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(ingest): capture table descriptions #2157

Merged
merged 1 commit into from
Mar 2, 2021
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
21 changes: 19 additions & 2 deletions metadata-ingestion/src/datahub/ingestion/source/sql_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import time
from abc import abstractmethod
from dataclasses import dataclass, field
from typing import Any, List, Optional
from typing import Any, Iterable, List, Optional

from sqlalchemy import create_engine
from sqlalchemy.engine import reflection
Expand All @@ -26,6 +26,7 @@
SchemaMetadata,
StringTypeClass,
)
from datahub.metadata.schema_classes import DatasetPropertiesClass

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -144,7 +145,7 @@ def __init__(self, config, ctx, platform: str):
self.platform = platform
self.report = SQLSourceReport()

def get_workunits(self):
def get_workunits(self) -> Iterable[SqlWorkUnit]:
env: str = "PROD"
sql_config = self.config
platform = self.platform
Expand All @@ -163,10 +164,26 @@ def get_workunits(self):

if sql_config.table_pattern.allowed(dataset_name):
columns = inspector.get_columns(table, schema)
try:
description: Optional[str] = inspector.get_table_comment(
table, schema
)["text"]
except NotImplementedError:
description = None

# TODO: capture inspector.get_pk_constraint
Copy link
Contributor

Choose a reason for hiding this comment

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

nice!

# TODO: capture inspector.get_sorted_table_and_fkc_names

mce = MetadataChangeEvent()

dataset_snapshot = DatasetSnapshot()
dataset_snapshot.urn = f"urn:li:dataset:(urn:li:dataPlatform:{platform},{dataset_name},{env})"
if description is not None:
dataset_properties = DatasetPropertiesClass(
description=description,
# uri=dataset_name,
)
dataset_snapshot.aspects.append(dataset_properties)
schema_metadata = get_schema_metadata(
self.report, dataset_name, platform, columns
)
Expand Down
Loading