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/lookml): support views with derived_table.explore_source #7704

Merged
merged 10 commits into from
Apr 3, 2023

Conversation

hsheth2
Copy link
Collaborator

@hsheth2 hsheth2 commented Mar 28, 2023

Also includes some minor refactoring.

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 the ingestion PR or Issue related to the ingestion of metadata label Mar 28, 2023
@codecov-commenter

This comment was marked as outdated.

Copy link
Collaborator

@mayurinehate mayurinehate left a comment

Choose a reason for hiding this comment

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

Overall looks good, except schema field urn generated for fine grained lineage.

@@ -771,6 +772,11 @@ def _get_fields(
matched_field.replace('"', "").replace("`", "").lower()
)
upstream_fields.append(matched_field)
else:
Copy link
Collaborator

Choose a reason for hiding this comment

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

are there any known facts that contradict this assumption ? Like - is it possible that maybe sql is missing due to missing permissions.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or that, the field is named differently than the upstream column name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

there's an alias option in lookml, but we don't support that one yet https://cloud.google.com/looker/docs/reference/param-field-alias

Copy link
Collaborator

Choose a reason for hiding this comment

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

This function is getting pretty long, was a bit hard to follow. But def doesn't have to be cleaned up here

fields,
use_external_process=process_isolation_for_sql_parsing,
)
# Derived tables can either be a SQL query or a LookML explore.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think, adding link to this looker doc would be helpful here - https://cloud.google.com/looker/docs/derived-tables

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added

# We want this to render the full lkml block
# e.g. explore_source: source_name { ... }
# As such, we use the full derived_table instead of the explore_source.
view_logic = str(lkml.dump(derived_table))[:max_file_snippet_length]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Limiting length by max_file_snippet_length is new change and is okay. I wonder if we also required it when setting view_logic for SQL derived table's sql.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

not a new change - we already do it above in the code

Copy link
Collaborator

Choose a reason for hiding this comment

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

If I am not wrong, earlier view_logic for derived table was simply this:

view_logic = str(derived_table["explore_source"])
https://github.com/datahub-project/datahub/blob/master/metadata-ingestion/src/datahub/ingestion/source/looker/lookml_source.py#L871

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yep and that logic still remains, we only special case it for derived_table

Copy link
Collaborator

Choose a reason for hiding this comment

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

got it. We do not special case it for SQL derived tables, that was the comment, but definitely not directly related to this PR :)

upstream_dataset_urn = LookerExplore(
name=upstream_explore, model_name=looker_view.id.model_name
).get_explore_urn(self.source_config)
upstream_dataset_urns.append(upstream_dataset_urn)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice !
So we will now get table level and column level lineage for native derived tables, i.e. below edge ?
looker explore(upstream) -> looker view (derived)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yep

{
"upstreamType": "FIELD_SET",
"upstreams": [
"urn:li:schemaField:(urn:li:dataset:(urn:li:dataPlatform:looker,data.explore.my_view_explore,PROD),my_view_explore.country)"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think, the correct schema field urns would be

"urn:li:schemaField:(urn:li:dataset:(urn:li:dataPlatform:looker,data.explore.my_view_explore,PROD),country)"

Probably need to strip the starting explore name from column name ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

actually this is correct - explore fields have the explore name as part of the schema

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yup, although this is only applicable for looker explores

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, okay. Curious, if we have tested this on UI, that column lineage edge shows up correctly, or is if any change required there. Otherwise looks good.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes I tested it locally

Copy link
Collaborator

@asikowitz asikowitz left a comment

Choose a reason for hiding this comment

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

Didn't really follow the changes but trusting this is safe enough

@@ -771,6 +772,11 @@ def _get_fields(
matched_field.replace('"', "").replace("`", "").lower()
)
upstream_fields.append(matched_field)
else:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function is getting pretty long, was a bit hard to follow. But def doesn't have to be cleaned up here

@hsheth2 hsheth2 merged commit f780da4 into datahub-project:master Apr 3, 2023
@hsheth2 hsheth2 deleted the lookml-explore-source branch April 3, 2023 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ingestion PR or Issue related to the ingestion of metadata
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants