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(redshift) Properly handling database alias in redshift usage and redshift lineage generation #4473

Merged
merged 2 commits into from
Mar 23, 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
14 changes: 8 additions & 6 deletions metadata-ingestion/src/datahub/ingestion/source/sql/redshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,8 +677,6 @@ def _populate_lineage_map(

def _populate_lineage(self) -> None:

db_name = self.get_db_name()

stl_scan_based_lineage_query: str = """
select
distinct cluster,
Expand Down Expand Up @@ -736,7 +734,8 @@ def _populate_lineage(self) -> None:
scan_type in (1, 2, 3)
order by cluster, target_schema, target_table, starttime asc
""".format(
db_name=db_name,
# We need the original database name for filtering
db_name=self.config.database,
start_time=self.config.start_time.strftime(redshift_datetime_format),
end_time=self.config.end_time.strftime(redshift_datetime_format),
)
Expand Down Expand Up @@ -835,7 +834,8 @@ def _populate_lineage(self) -> None:
) as target_tables
order by cluster, target_schema, target_table, starttime asc
""".format(
db_name=db_name,
# We need the original database name for filtering
db_name=self.config.database,
start_time=self.config.start_time.strftime(redshift_datetime_format),
end_time=self.config.end_time.strftime(redshift_datetime_format),
)
Expand All @@ -858,7 +858,8 @@ def _populate_lineage(self) -> None:
and si.starttime < '{end_time}'
order by target_schema, target_table, starttime asc
""".format(
db_name=db_name,
# We need the original database name for filtering
db_name=self.config.database,
start_time=self.config.start_time.strftime(redshift_datetime_format),
end_time=self.config.end_time.strftime(redshift_datetime_format),
)
Expand Down Expand Up @@ -915,7 +916,8 @@ def get_lineage_mcp(
if dataset_key is None:
return None, None

if not self._lineage_map:
if self._lineage_map is None:
logger.debug("Populating lineage")
Copy link
Contributor

Choose a reason for hiding this comment

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

🙌

self._populate_lineage()
assert self._lineage_map is not None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
JOIN svl_user_info sui ON sq.userid = sui.usesysid
WHERE ss.starttime >= '{start_time}'
AND ss.starttime < '{end_time}'
AND sti.database = '{database}'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this to make sure we only get usage for the database set in the config

AND sq.aborted = 0
ORDER BY ss.endtime DESC;
""".strip()
Expand Down Expand Up @@ -175,6 +176,7 @@ def _make_usage_query(self, query: str) -> str:
return query.format(
start_time=self.config.start_time.strftime(redshift_datetime_format),
end_time=self.config.end_time.strftime(redshift_datetime_format),
database=self.config.database,
)

def _make_redshift_operation_aspect_query(self, table_name: str) -> str:
Expand Down Expand Up @@ -265,6 +267,9 @@ def _get_joined_access_event(self, events):
logging.info("An access event parameter(s) is missing. Skipping ....")
continue

if self.config.database_alias:
event_dict["database"] = self.config.database_alias

if not event_dict.get("usename") or event_dict["usename"] == "":
logging.info("The username parameter is missing. Skipping ....")
continue
Expand Down