Skip to content

Commit 6607434

Browse files
authored
test(ingest): test case statements with sql parser (#8437)
1 parent ef3b948 commit 6607434

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"query_type": "SELECT",
3+
"in_tables": [
4+
"urn:li:dataset:(urn:li:dataPlatform:snowflake,snowflake_sample_data.tpch_sf1.orders,PROD)"
5+
],
6+
"out_tables": [],
7+
"column_lineage": [
8+
{
9+
"downstream": {
10+
"table": null,
11+
"column": "TOTAL_PRICE_CATEGORY"
12+
},
13+
"upstreams": [
14+
{
15+
"table": "urn:li:dataset:(urn:li:dataPlatform:snowflake,snowflake_sample_data.tpch_sf1.orders,PROD)",
16+
"column": "totalprice"
17+
}
18+
]
19+
},
20+
{
21+
"downstream": {
22+
"table": null,
23+
"column": "TOTAL_PRICE_SUCCESS"
24+
},
25+
"upstreams": [
26+
{
27+
"table": "urn:li:dataset:(urn:li:dataPlatform:snowflake,snowflake_sample_data.tpch_sf1.orders,PROD)",
28+
"column": "is_payment_successful"
29+
},
30+
{
31+
"table": "urn:li:dataset:(urn:li:dataPlatform:snowflake,snowflake_sample_data.tpch_sf1.orders,PROD)",
32+
"column": "totalprice"
33+
}
34+
]
35+
}
36+
]
37+
}

metadata-ingestion/tests/unit/sql_parsing/test_sqlglot_lineage.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,34 @@ def test_snowflake_column_normalization():
287287
)
288288

289289

290+
def test_snowflake_case_statement():
291+
assert_sql_result(
292+
"""
293+
SELECT
294+
CASE
295+
WHEN o."totalprice" > 1000 THEN 'high'
296+
WHEN o."totalprice" > 100 THEN 'medium'
297+
ELSE 'low'
298+
END as total_price_category,
299+
-- Also add a case where the column is in the THEN clause.
300+
CASE
301+
WHEN o."is_payment_successful" THEN o."totalprice"
302+
ELSE 0
303+
END as total_price_success
304+
FROM snowflake_sample_data.tpch_sf1.orders o
305+
""",
306+
dialect="snowflake",
307+
schemas={
308+
"urn:li:dataset:(urn:li:dataPlatform:snowflake,snowflake_sample_data.tpch_sf1.orders,PROD)": {
309+
"orderkey": "NUMBER",
310+
"totalprice": "FLOAT",
311+
"is_payment_successful": "BOOLEAN",
312+
},
313+
},
314+
expected_file=RESOURCE_DIR / "test_snowflake_case_statement.json",
315+
)
316+
317+
290318
@pytest.mark.skip(reason="We don't handle the unnest lineage correctly")
291319
def test_bigquery_unnest_columns():
292320
assert_sql_result(

0 commit comments

Comments
 (0)