Skip to content

Commit 12fcbb4

Browse files
committed
chore: add nested cte to sushi for testing
1 parent a6992e0 commit 12fcbb4

3 files changed

Lines changed: 36 additions & 6 deletions

File tree

examples/sushi/models/customers.sql

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ CREATE VIEW raw.demographics AS (
1717
SELECT 1 AS customer_id, '00000' AS zip
1818
);
1919

20-
WITH current_marketing AS (
20+
WITH current_marketing_outer AS (
2121
SELECT
2222
customer_id,
2323
status
@@ -29,7 +29,15 @@ SELECT DISTINCT
2929
m.status,
3030
d.zip
3131
FROM sushi.orders AS o
32-
LEFT JOIN current_marketing AS m
32+
LEFT JOIN (
33+
WITH current_marketing AS (
34+
SELECT
35+
customer_id,
36+
status
37+
FROM current_marketing_outer
38+
)
39+
SELECT * FROM current_marketing
40+
) AS m
3341
ON o.customer_id = m.customer_id
3442
LEFT JOIN raw.demographics AS d
3543
ON o.customer_id = d.customer_id

tests/test_forking.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_parallel_load(assert_exp_eq, mocker):
1919
assert_exp_eq(
2020
context.render("sushi.customers"),
2121
"""
22-
WITH "current_marketing" AS (
22+
WITH "current_marketing_outer" AS (
2323
SELECT
2424
"marketing"."customer_id" AS "customer_id",
2525
"marketing"."status" AS "status"
@@ -32,7 +32,18 @@ def test_parallel_load(assert_exp_eq, mocker):
3232
"m"."status" AS "status",
3333
"d"."zip" AS "zip"
3434
FROM "memory"."sushi"."orders" AS "o"
35-
LEFT JOIN "current_marketing" AS "m"
35+
LEFT JOIN (
36+
WITH "current_marketing" AS (
37+
SELECT
38+
"current_marketing_outer"."customer_id" AS "customer_id",
39+
"current_marketing_outer"."status" AS "status"
40+
FROM "current_marketing_outer" AS "current_marketing_outer"
41+
)
42+
SELECT
43+
"current_marketing"."customer_id" AS "customer_id",
44+
"current_marketing"."status" AS "status"
45+
FROM "current_marketing" AS "current_marketing"
46+
) AS "m"
3647
ON "m"."customer_id" = "o"."customer_id"
3748
LEFT JOIN "memory"."raw"."demographics" AS "d"
3849
ON "d"."customer_id" = "o"."customer_id"

tests/web/test_lineage.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_get_lineage(client: TestClient, web_sushi_context: Context) -> None:
4747
"customer_id": {
4848
"expression": 'CAST("o"."customer_id" AS INT) AS "customer_id" /* this comment should not be registered */',
4949
"models": {'"memory"."sushi"."orders"': ["customer_id"]},
50-
"source": '''WITH "current_marketing" AS (
50+
"source": '''WITH "current_marketing_outer" AS (
5151
SELECT
5252
"marketing"."customer_id" AS "customer_id",
5353
"marketing"."status" AS "status"
@@ -58,7 +58,18 @@ def test_get_lineage(client: TestClient, web_sushi_context: Context) -> None:
5858
SELECT DISTINCT
5959
CAST("o"."customer_id" AS INT) AS "customer_id" /* this comment should not be registered */
6060
FROM "memory"."sushi"."orders" AS "o"
61-
LEFT JOIN "current_marketing" AS "m"
61+
LEFT JOIN (
62+
WITH "current_marketing" AS (
63+
SELECT
64+
"current_marketing_outer"."customer_id" AS "customer_id",
65+
"current_marketing_outer"."status" AS "status"
66+
FROM "current_marketing_outer" AS "current_marketing_outer"
67+
)
68+
SELECT
69+
"current_marketing"."customer_id" AS "customer_id",
70+
"current_marketing"."status" AS "status"
71+
FROM "current_marketing" AS "current_marketing"
72+
) AS "m"
6273
ON "m"."customer_id" = "o"."customer_id"
6374
LEFT JOIN "memory"."raw"."demographics" AS "d"
6475
ON "d"."customer_id" = "o"."customer_id"''',

0 commit comments

Comments
 (0)