-
Notifications
You must be signed in to change notification settings - Fork 3k
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/snowflake): apply table name normalization for queries_v2 #12566
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import logging | ||
import re | ||
from collections import defaultdict | ||
from dataclasses import dataclass | ||
from typing import Dict, List, Optional, Set | ||
|
@@ -300,6 +301,18 @@ | |
"to ignore the temporary staging tables created by known ETL tools.", | ||
) | ||
|
||
table_name_normalization_rules: Dict[re.Pattern, str] = pydantic.Field( | ||
default={}, | ||
description="[Advanced] Regex patterns for table names to normalize in lineage ingestion. " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does it make sense for us to have the ruff linter uses a similar pattern which works pretty well https://docs.astral.sh/ruff/settings/#lint_extend-select There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's an excellent idea. Have not injected defaults yet. That's exactly the problem I was looking to solve - how to let users extend defaults without re-declaring them, and at the same time, allow users to change defaults if they do not suit them. |
||
"Specify key as regex to match the table name as it appears in query. " | ||
"The value is the normalized table name. " | ||
"Defaults are to set in such a way to normalize the staging tables created by known ETL tools." | ||
"The tables identified by these rules should typically be temporary or transient tables " | ||
"and should not be used directly in other tools. DataHub will not be able to detect cross" | ||
"-platform lineage for such tables.", | ||
# "Only applicable if `use_queries_v2` is enabled.", | ||
) | ||
|
||
rename_upstreams_deny_pattern_to_temporary_table_pattern = pydantic_renamed_field( | ||
"upstreams_deny_pattern", "temporary_tables_pattern" | ||
) | ||
|
@@ -325,6 +338,15 @@ | |
"Only applicable if `use_queries_v2` is enabled.", | ||
) | ||
|
||
@validator("table_name_normalization_rules") | ||
def validate_pattern(cls, pattern): | ||
if isinstance(pattern, re.Pattern): # Already compiled, good | ||
return pattern | ||
try: | ||
return re.compile(pattern) # Attempt compilation | ||
except re.error as e: | ||
raise ValueError(f"Invalid regular expression: {e}") | ||
|
||
@validator("convert_urns_to_lowercase") | ||
def validate_convert_urns_to_lowercase(cls, v): | ||
if not v: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
from datahub.sql_parsing.sql_parsing_common import QueryType | ||
from datahub.sql_parsing.sqlglot_lineage import _UPDATE_ARGS_NOT_SUPPORTED_BY_SELECT | ||
from datahub.sql_parsing.sqlglot_utils import ( | ||
_TABLE_NAME_NORMALIZATION_RULES, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should remove the |
||
generalize_query, | ||
generalize_query_fast, | ||
get_dialect, | ||
|
@@ -173,7 +174,11 @@ def test_query_generalization( | |
assert generalize_query(query, dialect=dialect) == expected | ||
if mode in {QueryGeneralizationTestMode.FAST, QueryGeneralizationTestMode.BOTH}: | ||
assert ( | ||
generalize_query_fast(query, dialect=dialect, change_table_names=True) | ||
generalize_query_fast( | ||
query, | ||
dialect=dialect, | ||
table_name_normalization_rules=_TABLE_NAME_NORMALIZATION_RULES, | ||
) | ||
== expected | ||
) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where are the defaults injected in?