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

feat(s3): add s3 source #4490

Merged
merged 6 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions metadata-ingestion/examples/recipes/s3_to_file.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
# see https://datahubproject.io/docs/metadata-ingestion/source_docs/s3_data_lake for complete documentation
source:
type: "s3"
config:
platform: s3
path_spec:
include: "s3://covid19-lake/covid_knowledge_graph/csv/nodes/*.*"
aws_config:
aws_access_key_id: accessKey
aws_secret_access_key: secretKey
aws_region: us-east-2

# see https://datahubproject.io/docs/metadata-ingestion/sink_docs/file for complete documentation
sink:
type: "file"
config:
filename: "./s3_data_lake_mces.json"

13 changes: 11 additions & 2 deletions metadata-ingestion/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,20 @@ def get_long_description():
"tableschema>=1.20.2",
"ujson>=4.3.0",
"types-ujson>=4.2.1",
"smart-open[s3]>=5.2.1",
"smart-open[s3]>=5.2.1"
}

data_lake_profiling = {
"pydeequ==1.0.1",
"pyspark==3.0.3",
}

s3_base = {
*data_lake_base,
"moto[s3]",
"wcmatch",
}

# Note: for all of these, framework_common will be added.
plugins: Dict[str, Set[str]] = {
# Sink plugins.
Expand All @@ -142,6 +148,7 @@ def get_long_description():
"datahub-lineage-file": set(),
"datahub-business-glossary": set(),
"data-lake": {*data_lake_base, *data_lake_profiling},
"s3": {*s3_base, *data_lake_profiling},
"dbt": {"requests"},
"druid": sql_common | {"pydruid>=0.6.2"},
# Starting with 7.14.0 python client is checking if it is connected to elasticsearch client. If its not it throws
Expand Down Expand Up @@ -224,7 +231,7 @@ def get_long_description():
*base_requirements,
*framework_common,
*mypy_stubs,
*data_lake_base,
*s3_base,
"black>=21.12b0",
"coverage>=5.1",
"flake8>=3.8.3",
Expand Down Expand Up @@ -267,6 +274,7 @@ def get_long_description():
"redshift",
"redshift-usage",
"data-lake",
"s3",
"tableau",
"trino",
"hive",
Expand Down Expand Up @@ -335,6 +343,7 @@ def get_long_description():
"clickhouse = datahub.ingestion.source.sql.clickhouse:ClickHouseSource",
"clickhouse-usage = datahub.ingestion.source.usage.clickhouse_usage:ClickHouseUsageSource",
"data-lake = datahub.ingestion.source.data_lake:DataLakeSource",
"s3 = datahub.ingestion.source.s3:S3Source",
"dbt = datahub.ingestion.source.dbt:DBTSource",
"druid = datahub.ingestion.source.sql.druid:DruidSource",
"elasticsearch = datahub.ingestion.source.elastic_search:ElasticsearchSource",
Expand Down
180 changes: 180 additions & 0 deletions metadata-ingestion/source_docs/s3_data_lake.md

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion metadata-ingestion/src/datahub/emitter/mcp_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ class BigQueryDatasetKey(ProjectIdKey):
dataset_id: str


class FolderKey(PlatformKey):
folder_abs_path: str


class S3BucketKey(PlatformKey):
bucket_name: str


class DatahubKeyJSONEncoder(json.JSONEncoder):

# overload method default
Expand Down Expand Up @@ -158,7 +166,7 @@ def gen_containers(
# entityKeyAspect=ContainerKeyClass(guid=schema_container_key.guid()),
aspectName="dataPlatformInstance",
aspect=DataPlatformInstance(
platform=f"{make_data_platform_urn(container_key.platform)}"
platform=f"{make_data_platform_urn(container_key.platform)}",
),
)
wu = MetadataWorkUnit(
Expand Down
12 changes: 12 additions & 0 deletions metadata-ingestion/src/datahub/ingestion/source/aws/s3_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def strip_s3_prefix(s3_uri: str) -> str:
)


def get_bucket_relative_path(s3_uri: str) -> str:
return "/".join(strip_s3_prefix(s3_uri).split("/")[1:])


def make_s3_urn(s3_uri: str, env: str) -> str:

s3_name = strip_s3_prefix(s3_uri)
Expand All @@ -33,3 +37,11 @@ def make_s3_urn(s3_uri: str, env: str) -> str:
return f"urn:li:dataset:(urn:li:dataPlatform:s3,{name}_{extension},{env})"

return f"urn:li:dataset:(urn:li:dataPlatform:s3,{s3_name},{env})"


def get_bucket_name(s3_uri: str) -> str:
if not is_s3_uri(s3_uri):
raise ValueError(
f"Not an S3 URI. Must start with one of the following prefixes: {str(S3_PREFIXES)}"
)
return strip_s3_prefix(s3_uri).split("/")[0]
Loading