Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ingest/s3): incorrectly parsing path in s3_uri #12135

Conversation

eagle-25
Copy link
Contributor

@eagle-25 eagle-25 commented Dec 15, 2024

Background

  • While ingesting S3 datasets with a pipeline, I encountered a warning: Unable to find any files in the folder s3://your-bucket/your-path/year=2024/. Skipping..., but the file was definitely present.

Changes

As-is

  • The path was misparsed due to using lstrip() with s3://<bucket-name>//.
dir = "s3://bucket/test9/abc.txt"
path_to_process = dir.rstrip("\\").lstrip("s3://bucket//")

print(path_to_process) # result: '9/abc.txt', expected: test9/abc.txt

To-be

  • Use urlparse to parse the path in s3_uri.
from urllib.parse import urlparse

dir = "s3://bucket/test/abc.txt"
path_to_process = urlparse(dir).path.lstrip("/")

print(path_to_process) # result: 'test9/abc.txt'

How to reproduce

  • You can reproduce this bug with the following code.
from datahub.ingestion.run.pipeline import Pipeline

DATAHUB_SERVER = "http://localhost:8080"
DEFAULT_SINK = {"type": "datahub-rest", "config": {"server": DATAHUB_SERVER}}

S3_PATH = "s3://your-bucket/your-path/path/{table}/{partition_key[0]}={partition[0]}/*.parquet"

s3_config = {
        "source": {
            "type": "s3",
            "config": {
                "path_spec": {
                    "include": S3_PATH,
                },
                "aws_config": {
                    "aws_region": "ap-northeast-2",
                },
            },
        },
        "sink": DEFAULT_SINK,
    }

pipeline = Pipeline.create(s3_config)
pipeline.run()

Checklist

  • The PR conforms to DataHub's Contributing Guideline (particularly Commit Message Format)
  • Links to related issues (if applicable)
  • Tests for the changes have been added/updated (if applicable)
  • Docs related to the changes have been added/updated (if applicable). If a new feature has been added a Usage Guide has been added for the same.
  • For any breaking change/potential downtime/deprecation/big changes an entry has been made in Updating DataHub

@github-actions github-actions bot added ingestion PR or Issue related to the ingestion of metadata community-contribution PR or Issue raised by member(s) of DataHub Community labels Dec 15, 2024
@datahub-cyborg datahub-cyborg bot added the needs-review Label for PRs that need review from a maintainer. label Dec 15, 2024
@eagle-25 eagle-25 force-pushed the fix/ingestion/s3/incorrect-bucket-prefix-removal-logic branch from a133415 to 932f39a Compare December 15, 2024 13:34
@eagle-25 eagle-25 force-pushed the fix/ingestion/s3/incorrect-bucket-prefix-removal-logic branch from 932f39a to 080a992 Compare December 16, 2024 01:48
Copy link
Contributor

@treff7es treff7es left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good, thanks for the fix

@treff7es treff7es merged commit 8f9659f into datahub-project:master Dec 17, 2024
72 of 73 checks passed
@eagle-25 eagle-25 deleted the fix/ingestion/s3/incorrect-bucket-prefix-removal-logic branch December 17, 2024 09:33
sleeperdeep pushed a commit to sleeperdeep/datahub that referenced this pull request Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community-contribution PR or Issue raised by member(s) of DataHub Community ingestion PR or Issue related to the ingestion of metadata needs-review Label for PRs that need review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants