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): avoid shell entities during view lineage generation #12044

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,8 @@ def _run_sql_parser(
)
else:
self.report.num_view_definitions_parsed += 1
if raw_lineage.out_tables != [view_urn]:
self.report.num_view_definitions_view_urn_mismatch += 1
return view_definition_lineage_helper(raw_lineage, view_urn)

def get_db_schema(self, dataset_identifier: str) -> Tuple[Optional[str], str]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class SQLSourceReport(
query_combiner: Optional[SQLAlchemyQueryCombinerReport] = None

num_view_definitions_parsed: int = 0
num_view_definitions_view_urn_mismatch: int = 0
num_view_definitions_failed_parsing: int = 0
num_view_definitions_failed_column_parsing: int = 0
view_definitions_parsing_failures: LossyList[str] = field(default_factory=LossyList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,8 @@ def _run_sql_parser(
)
else:
self.report.num_view_definitions_parsed += 1
if raw_lineage.out_tables != [view_urn]:
self.report.num_view_definitions_view_urn_mismatch += 1
return view_definition_lineage_helper(raw_lineage, view_urn)

def get_view_lineage(self) -> Iterable[MetadataWorkUnit]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1243,13 +1243,19 @@ def infer_output_schema(result: SqlParsingResult) -> Optional[List[SchemaFieldCl
def view_definition_lineage_helper(
result: SqlParsingResult, view_urn: str
) -> SqlParsingResult:
if result.query_type is QueryType.SELECT:
if result.query_type is QueryType.SELECT or (
result.out_tables and result.out_tables != [view_urn]
):
Copy link
Collaborator

Choose a reason for hiding this comment

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

it'd be good to add some error reporting around this

# Some platforms (e.g. postgres) store only <select statement> from view definition
# `create view V as <select statement>` . For such view definitions, `result.out_tables` and
# `result.column_lineage[].downstream` are empty in `sqlglot_lineage` response, whereas upstream
# details and downstream column details are extracted correctly.
# Here, we inject view V's urn in `result.out_tables` and `result.column_lineage[].downstream`
# to get complete lineage result.

# Some platforms(e.g. mssql) may have slightly different view name in view definition than
# actual view name used elsewhere. Therefore we overwrite downstream table for such cases as well.

result.out_tables = [view_urn]
if result.column_lineage:
for col_result in result.column_lineage:
Expand Down
Loading
Loading