forked from datahub-project/datahub
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ingest): support CLL for redshift materialized views with auto r…
…efresh (datahub-project#9508)
- Loading branch information
Showing
5 changed files
with
207 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...ngestion/tests/unit/sql_parsing/goldens/test_redshift_materialized_view_auto_refresh.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"query_type": "CREATE", | ||
"in_tables": [ | ||
"urn:li:dataset:(urn:li:dataPlatform:redshift,customer,PROD)", | ||
"urn:li:dataset:(urn:li:dataPlatform:redshift,orders,PROD)" | ||
], | ||
"out_tables": [ | ||
"urn:li:dataset:(urn:li:dataPlatform:redshift,mv_total_orders,PROD)" | ||
], | ||
"column_lineage": [ | ||
{ | ||
"downstream": { | ||
"table": "urn:li:dataset:(urn:li:dataPlatform:redshift,mv_total_orders,PROD)", | ||
"column": "cust_id", | ||
"column_type": null, | ||
"native_column_type": null | ||
}, | ||
"upstreams": [ | ||
{ | ||
"table": "urn:li:dataset:(urn:li:dataPlatform:redshift,customer,PROD)", | ||
"column": "cust_id" | ||
} | ||
] | ||
}, | ||
{ | ||
"downstream": { | ||
"table": "urn:li:dataset:(urn:li:dataPlatform:redshift,mv_total_orders,PROD)", | ||
"column": "first_name", | ||
"column_type": null, | ||
"native_column_type": null | ||
}, | ||
"upstreams": [ | ||
{ | ||
"table": "urn:li:dataset:(urn:li:dataPlatform:redshift,customer,PROD)", | ||
"column": "first_name" | ||
} | ||
] | ||
}, | ||
{ | ||
"downstream": { | ||
"table": "urn:li:dataset:(urn:li:dataPlatform:redshift,mv_total_orders,PROD)", | ||
"column": "total_amount", | ||
"column_type": null, | ||
"native_column_type": null | ||
}, | ||
"upstreams": [ | ||
{ | ||
"table": "urn:li:dataset:(urn:li:dataPlatform:redshift,orders,PROD)", | ||
"column": "amount" | ||
} | ||
] | ||
} | ||
] | ||
} |
46 changes: 46 additions & 0 deletions
46
metadata-ingestion/tests/unit/sql_parsing/test_sql_detach.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from datahub.utilities.sqlglot_lineage import detach_ctes | ||
|
||
|
||
def test_detach_ctes_simple(): | ||
original = "WITH __cte_0 AS (SELECT * FROM table1) SELECT * FROM table2 JOIN __cte_0 ON table2.id = __cte_0.id" | ||
detached_expr = detach_ctes( | ||
original, | ||
platform="snowflake", | ||
cte_mapping={"__cte_0": "_my_cte_table"}, | ||
) | ||
detached = detached_expr.sql(dialect="snowflake") | ||
|
||
assert ( | ||
detached | ||
== "WITH __cte_0 AS (SELECT * FROM table1) SELECT * FROM table2 JOIN _my_cte_table ON table2.id = _my_cte_table.id" | ||
) | ||
|
||
|
||
def test_detach_ctes_with_alias(): | ||
original = "WITH __cte_0 AS (SELECT * FROM table1) SELECT * FROM table2 JOIN __cte_0 AS tablealias ON table2.id = tablealias.id" | ||
detached_expr = detach_ctes( | ||
original, | ||
platform="snowflake", | ||
cte_mapping={"__cte_0": "_my_cte_table"}, | ||
) | ||
detached = detached_expr.sql(dialect="snowflake") | ||
|
||
assert ( | ||
detached | ||
== "WITH __cte_0 AS (SELECT * FROM table1) SELECT * FROM table2 JOIN _my_cte_table AS tablealias ON table2.id = tablealias.id" | ||
) | ||
|
||
|
||
def test_detach_ctes_with_multipart_replacement(): | ||
original = "WITH __cte_0 AS (SELECT * FROM table1) SELECT * FROM table2 JOIN __cte_0 ON table2.id = __cte_0.id" | ||
detached_expr = detach_ctes( | ||
original, | ||
platform="snowflake", | ||
cte_mapping={"__cte_0": "my_db.my_schema.my_table"}, | ||
) | ||
detached = detached_expr.sql(dialect="snowflake") | ||
|
||
assert ( | ||
detached | ||
== "WITH __cte_0 AS (SELECT * FROM table1) SELECT * FROM table2 JOIN my_db.my_schema.my_table ON table2.id = my_db.my_schema.my_table.id" | ||
) |
Oops, something went wrong.