-
Notifications
You must be signed in to change notification settings - Fork 609
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sql): replace CTEs within CTEs (#8572)
Co-authored-by: Phillip Cloud <417981+cpcloud@users.noreply.github.com>
- Loading branch information
Showing
18 changed files
with
391 additions
and
564 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
56 changes: 23 additions & 33 deletions
56
ibis/backends/tests/snapshots/test_generic/test_many_subqueries/bigquery/out.sql
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 |
---|---|---|
@@ -1,42 +1,32 @@ | ||
WITH `t6` AS ( | ||
WITH `t1` AS ( | ||
SELECT | ||
`t5`.`street`, | ||
ROW_NUMBER() OVER (ORDER BY `t5`.`street` ASC) - 1 AS `key` | ||
`t0`.`street`, | ||
ROW_NUMBER() OVER (ORDER BY `t0`.`street` ASC) - 1 AS `key` | ||
FROM `data` AS `t0` | ||
), `t7` AS ( | ||
SELECT | ||
`t6`.`street`, | ||
ROW_NUMBER() OVER (ORDER BY `t6`.`street` ASC) - 1 AS `key` | ||
FROM ( | ||
SELECT | ||
`t2`.`street`, | ||
`t2`.`key` | ||
FROM ( | ||
SELECT | ||
`t0`.`street`, | ||
ROW_NUMBER() OVER (ORDER BY `t0`.`street` ASC) - 1 AS `key` | ||
FROM `data` AS `t0` | ||
) AS `t2` | ||
`t3`.`street`, | ||
`t3`.`key` | ||
FROM `t1` AS `t3` | ||
INNER JOIN ( | ||
SELECT | ||
`t1`.`key` | ||
FROM ( | ||
SELECT | ||
`t0`.`street`, | ||
ROW_NUMBER() OVER (ORDER BY `t0`.`street` ASC) - 1 AS `key` | ||
FROM `data` AS `t0` | ||
) AS `t1` | ||
) AS `t4` | ||
ON `t2`.`key` = `t4`.`key` | ||
) AS `t5` | ||
), `t1` AS ( | ||
SELECT | ||
`t0`.`street`, | ||
ROW_NUMBER() OVER (ORDER BY `t0`.`street` ASC) - 1 AS `key` | ||
FROM `data` AS `t0` | ||
`t2`.`key` | ||
FROM `t1` AS `t2` | ||
) AS `t5` | ||
ON `t3`.`key` = `t5`.`key` | ||
) AS `t6` | ||
) | ||
SELECT | ||
`t8`.`street`, | ||
`t8`.`key` | ||
FROM `t6` AS `t8` | ||
`t9`.`street`, | ||
`t9`.`key` | ||
FROM `t7` AS `t9` | ||
INNER JOIN ( | ||
SELECT | ||
`t7`.`key` | ||
FROM `t6` AS `t7` | ||
) AS `t10` | ||
ON `t8`.`key` = `t10`.`key` | ||
`t8`.`key` | ||
FROM `t7` AS `t8` | ||
) AS `t11` | ||
ON `t9`.`key` = `t11`.`key` |
56 changes: 23 additions & 33 deletions
56
ibis/backends/tests/snapshots/test_generic/test_many_subqueries/clickhouse/out.sql
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 |
---|---|---|
@@ -1,42 +1,32 @@ | ||
WITH "t6" AS ( | ||
WITH "t1" AS ( | ||
SELECT | ||
"t5"."street", | ||
ROW_NUMBER() OVER (ORDER BY "t5"."street" ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) - 1 AS "key" | ||
"t0"."street", | ||
ROW_NUMBER() OVER (ORDER BY "t0"."street" ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) - 1 AS "key" | ||
FROM "data" AS "t0" | ||
), "t7" AS ( | ||
SELECT | ||
"t6"."street", | ||
ROW_NUMBER() OVER (ORDER BY "t6"."street" ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) - 1 AS "key" | ||
FROM ( | ||
SELECT | ||
"t2"."street", | ||
"t2"."key" | ||
FROM ( | ||
SELECT | ||
"t0"."street", | ||
ROW_NUMBER() OVER (ORDER BY "t0"."street" ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) - 1 AS "key" | ||
FROM "data" AS "t0" | ||
) AS "t2" | ||
"t3"."street", | ||
"t3"."key" | ||
FROM "t1" AS "t3" | ||
INNER JOIN ( | ||
SELECT | ||
"t1"."key" | ||
FROM ( | ||
SELECT | ||
"t0"."street", | ||
ROW_NUMBER() OVER (ORDER BY "t0"."street" ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) - 1 AS "key" | ||
FROM "data" AS "t0" | ||
) AS "t1" | ||
) AS "t4" | ||
ON "t2"."key" = "t4"."key" | ||
) AS "t5" | ||
), "t1" AS ( | ||
SELECT | ||
"t0"."street", | ||
ROW_NUMBER() OVER (ORDER BY "t0"."street" ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) - 1 AS "key" | ||
FROM "data" AS "t0" | ||
"t2"."key" | ||
FROM "t1" AS "t2" | ||
) AS "t5" | ||
ON "t3"."key" = "t5"."key" | ||
) AS "t6" | ||
) | ||
SELECT | ||
"t8"."street", | ||
"t8"."key" | ||
FROM "t6" AS "t8" | ||
"t9"."street", | ||
"t9"."key" | ||
FROM "t7" AS "t9" | ||
INNER JOIN ( | ||
SELECT | ||
"t7"."key" | ||
FROM "t6" AS "t7" | ||
) AS "t10" | ||
ON "t8"."key" = "t10"."key" | ||
"t8"."key" | ||
FROM "t7" AS "t8" | ||
) AS "t11" | ||
ON "t9"."key" = "t11"."key" |
56 changes: 23 additions & 33 deletions
56
ibis/backends/tests/snapshots/test_generic/test_many_subqueries/datafusion/out.sql
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 |
---|---|---|
@@ -1,42 +1,32 @@ | ||
WITH "t6" AS ( | ||
WITH "t1" AS ( | ||
SELECT | ||
"t5"."street", | ||
ROW_NUMBER() OVER (ORDER BY "t5"."street" ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) - 1 AS "key" | ||
"t0"."street", | ||
ROW_NUMBER() OVER (ORDER BY "t0"."street" ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) - 1 AS "key" | ||
FROM "data" AS "t0" | ||
), "t7" AS ( | ||
SELECT | ||
"t6"."street", | ||
ROW_NUMBER() OVER (ORDER BY "t6"."street" ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) - 1 AS "key" | ||
FROM ( | ||
SELECT | ||
"t2"."street", | ||
"t2"."key" | ||
FROM ( | ||
SELECT | ||
"t0"."street", | ||
ROW_NUMBER() OVER (ORDER BY "t0"."street" ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) - 1 AS "key" | ||
FROM "data" AS "t0" | ||
) AS "t2" | ||
"t3"."street", | ||
"t3"."key" | ||
FROM "t1" AS "t3" | ||
INNER JOIN ( | ||
SELECT | ||
"t1"."key" | ||
FROM ( | ||
SELECT | ||
"t0"."street", | ||
ROW_NUMBER() OVER (ORDER BY "t0"."street" ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) - 1 AS "key" | ||
FROM "data" AS "t0" | ||
) AS "t1" | ||
) AS "t4" | ||
ON "t2"."key" = "t4"."key" | ||
) AS "t5" | ||
), "t1" AS ( | ||
SELECT | ||
"t0"."street", | ||
ROW_NUMBER() OVER (ORDER BY "t0"."street" ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) - 1 AS "key" | ||
FROM "data" AS "t0" | ||
"t2"."key" | ||
FROM "t1" AS "t2" | ||
) AS "t5" | ||
ON "t3"."key" = "t5"."key" | ||
) AS "t6" | ||
) | ||
SELECT | ||
"t8"."street", | ||
"t8"."key" | ||
FROM "t6" AS "t8" | ||
"t9"."street", | ||
"t9"."key" | ||
FROM "t7" AS "t9" | ||
INNER JOIN ( | ||
SELECT | ||
"t7"."key" | ||
FROM "t6" AS "t7" | ||
) AS "t10" | ||
ON "t8"."key" = "t10"."key" | ||
"t8"."key" | ||
FROM "t7" AS "t8" | ||
) AS "t11" | ||
ON "t9"."key" = "t11"."key" |
56 changes: 23 additions & 33 deletions
56
ibis/backends/tests/snapshots/test_generic/test_many_subqueries/druid/out.sql
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 |
---|---|---|
@@ -1,42 +1,32 @@ | ||
WITH "t6" AS ( | ||
WITH "t1" AS ( | ||
SELECT | ||
"t5"."street", | ||
ROW_NUMBER() OVER (ORDER BY "t5"."street" ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) - 1 AS "key" | ||
"t0"."street", | ||
ROW_NUMBER() OVER (ORDER BY "t0"."street" ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) - 1 AS "key" | ||
FROM "data" AS "t0" | ||
), "t7" AS ( | ||
SELECT | ||
"t6"."street", | ||
ROW_NUMBER() OVER (ORDER BY "t6"."street" ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) - 1 AS "key" | ||
FROM ( | ||
SELECT | ||
"t2"."street", | ||
"t2"."key" | ||
FROM ( | ||
SELECT | ||
"t0"."street", | ||
ROW_NUMBER() OVER (ORDER BY "t0"."street" ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) - 1 AS "key" | ||
FROM "data" AS "t0" | ||
) AS "t2" | ||
"t3"."street", | ||
"t3"."key" | ||
FROM "t1" AS "t3" | ||
INNER JOIN ( | ||
SELECT | ||
"t1"."key" | ||
FROM ( | ||
SELECT | ||
"t0"."street", | ||
ROW_NUMBER() OVER (ORDER BY "t0"."street" ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) - 1 AS "key" | ||
FROM "data" AS "t0" | ||
) AS "t1" | ||
) AS "t4" | ||
ON "t2"."key" = "t4"."key" | ||
) AS "t5" | ||
), "t1" AS ( | ||
SELECT | ||
"t0"."street", | ||
ROW_NUMBER() OVER (ORDER BY "t0"."street" ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) - 1 AS "key" | ||
FROM "data" AS "t0" | ||
"t2"."key" | ||
FROM "t1" AS "t2" | ||
) AS "t5" | ||
ON "t3"."key" = "t5"."key" | ||
) AS "t6" | ||
) | ||
SELECT | ||
"t8"."street", | ||
"t8"."key" | ||
FROM "t6" AS "t8" | ||
"t9"."street", | ||
"t9"."key" | ||
FROM "t7" AS "t9" | ||
INNER JOIN ( | ||
SELECT | ||
"t7"."key" | ||
FROM "t6" AS "t7" | ||
) AS "t10" | ||
ON "t8"."key" = "t10"."key" | ||
"t8"."key" | ||
FROM "t7" AS "t8" | ||
) AS "t11" | ||
ON "t9"."key" = "t11"."key" |
56 changes: 23 additions & 33 deletions
56
ibis/backends/tests/snapshots/test_generic/test_many_subqueries/duckdb/out.sql
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 |
---|---|---|
@@ -1,42 +1,32 @@ | ||
WITH "t6" AS ( | ||
WITH "t1" AS ( | ||
SELECT | ||
"t5"."street", | ||
ROW_NUMBER() OVER (ORDER BY "t5"."street" ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) - CAST(1 AS TINYINT) AS "key" | ||
"t0"."street", | ||
ROW_NUMBER() OVER (ORDER BY "t0"."street" ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) - CAST(1 AS TINYINT) AS "key" | ||
FROM "data" AS "t0" | ||
), "t7" AS ( | ||
SELECT | ||
"t6"."street", | ||
ROW_NUMBER() OVER (ORDER BY "t6"."street" ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) - CAST(1 AS TINYINT) AS "key" | ||
FROM ( | ||
SELECT | ||
"t2"."street", | ||
"t2"."key" | ||
FROM ( | ||
SELECT | ||
"t0"."street", | ||
ROW_NUMBER() OVER (ORDER BY "t0"."street" ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) - CAST(1 AS TINYINT) AS "key" | ||
FROM "data" AS "t0" | ||
) AS "t2" | ||
"t3"."street", | ||
"t3"."key" | ||
FROM "t1" AS "t3" | ||
INNER JOIN ( | ||
SELECT | ||
"t1"."key" | ||
FROM ( | ||
SELECT | ||
"t0"."street", | ||
ROW_NUMBER() OVER (ORDER BY "t0"."street" ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) - CAST(1 AS TINYINT) AS "key" | ||
FROM "data" AS "t0" | ||
) AS "t1" | ||
) AS "t4" | ||
ON "t2"."key" = "t4"."key" | ||
) AS "t5" | ||
), "t1" AS ( | ||
SELECT | ||
"t0"."street", | ||
ROW_NUMBER() OVER (ORDER BY "t0"."street" ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) - CAST(1 AS TINYINT) AS "key" | ||
FROM "data" AS "t0" | ||
"t2"."key" | ||
FROM "t1" AS "t2" | ||
) AS "t5" | ||
ON "t3"."key" = "t5"."key" | ||
) AS "t6" | ||
) | ||
SELECT | ||
"t8"."street", | ||
"t8"."key" | ||
FROM "t6" AS "t8" | ||
"t9"."street", | ||
"t9"."key" | ||
FROM "t7" AS "t9" | ||
INNER JOIN ( | ||
SELECT | ||
"t7"."key" | ||
FROM "t6" AS "t7" | ||
) AS "t10" | ||
ON "t8"."key" = "t10"."key" | ||
"t8"."key" | ||
FROM "t7" AS "t8" | ||
) AS "t11" | ||
ON "t9"."key" = "t11"."key" |
Oops, something went wrong.