From 88a278577224659412b1d27d897de639c9debc4f Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Tue, 25 Jun 2024 13:37:18 -0400 Subject: [PATCH] refactor(api): remove unnecessary `select` from set operations (#9438) --- .../test_set_operation/difference/out.sql | 14 +++----- .../test_set_operation/intersect/out.sql | 14 +++----- .../test_set_operation/union_all/out.sql | 14 +++----- .../test_set_operation/union_distinct/out.sql | 14 +++----- .../test_compiler/test_union/False/out.sql | 14 +++----- .../test_compiler/test_union/True/out.sql | 14 +++----- .../test_union_cte/False-False/out.sql | 22 ++++-------- .../test_union_cte/False-True/out.sql | 24 +++++-------- .../test_union_cte/True-False/out.sql | 24 +++++-------- .../test_union_cte/True-True/out.sql | 22 ++++-------- .../test_union_cte/False/out.sql | 22 ++++-------- .../test_union_cte/True/out.sql | 22 ++++-------- .../test_union_cte/False/out.sql | 22 ++++-------- .../test_union_cte/True/out.sql | 22 ++++-------- .../test_union_aliasing/bigquery/out.sql | 36 +++++++++---------- .../test_union_aliasing/clickhouse/out.sql | 36 +++++++++---------- .../test_union_aliasing/duckdb/out.sql | 36 +++++++++---------- .../test_union_aliasing/postgres/out.sql | 36 +++++++++---------- .../test_union_aliasing/pyspark/out.sql | 36 +++++++++---------- .../test_union_aliasing/trino/out.sql | 36 +++++++++---------- .../test_table_difference/out.sql | 36 +++++++++---------- .../test_table_intersect/out.sql | 36 +++++++++---------- .../test_compiler/test_union/out.sql | 36 +++++++++---------- .../test_compiler/test_union_order_by/out.sql | 14 +++----- .../test_complex_union/result.sql | 28 +++++++-------- .../test_subquery_in_union/out.sql | 14 +++----- .../test_table_count_expr/union_repr.txt | 6 +--- ibis/expr/types/relations.py | 4 +-- ibis/tests/benchmarks/test_benchmarks.py | 9 ++--- ibis/tests/expr/test_set_operations.py | 4 +-- ibis/tests/expr/test_table.py | 10 +++--- 31 files changed, 269 insertions(+), 408 deletions(-) diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_set_operation/difference/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_set_operation/difference/out.sql index 5391ef866138..6d2cc9852e77 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_set_operation/difference/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_set_operation/difference/out.sql @@ -1,11 +1,7 @@ SELECT * -FROM ( - SELECT - * - FROM `t0` AS `t0` - EXCEPT DISTINCT - SELECT - * - FROM `t1` AS `t1` -) AS `t2` \ No newline at end of file +FROM `t0` AS `t0` +EXCEPT DISTINCT +SELECT + * +FROM `t1` AS `t1` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_set_operation/intersect/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_set_operation/intersect/out.sql index 68c2ec7c13d2..d8e00ce6a183 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_set_operation/intersect/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_set_operation/intersect/out.sql @@ -1,11 +1,7 @@ SELECT * -FROM ( - SELECT - * - FROM `t0` AS `t0` - INTERSECT DISTINCT - SELECT - * - FROM `t1` AS `t1` -) AS `t2` \ No newline at end of file +FROM `t0` AS `t0` +INTERSECT DISTINCT +SELECT + * +FROM `t1` AS `t1` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_set_operation/union_all/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_set_operation/union_all/out.sql index 287d262f9d2c..4e3ad8ebe177 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_set_operation/union_all/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_set_operation/union_all/out.sql @@ -1,11 +1,7 @@ SELECT * -FROM ( - SELECT - * - FROM `t0` AS `t0` - UNION ALL - SELECT - * - FROM `t1` AS `t1` -) AS `t2` \ No newline at end of file +FROM `t0` AS `t0` +UNION ALL +SELECT + * +FROM `t1` AS `t1` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_set_operation/union_distinct/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_set_operation/union_distinct/out.sql index 747e1717abf5..628e41173d8a 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_set_operation/union_distinct/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_set_operation/union_distinct/out.sql @@ -1,11 +1,7 @@ SELECT * -FROM ( - SELECT - * - FROM `t0` AS `t0` - UNION DISTINCT - SELECT - * - FROM `t1` AS `t1` -) AS `t2` \ No newline at end of file +FROM `t0` AS `t0` +UNION DISTINCT +SELECT + * +FROM `t1` AS `t1` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_union/False/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_union/False/out.sql index 900f7a580e50..867114c5a8d5 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_union/False/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_union/False/out.sql @@ -1,11 +1,7 @@ SELECT * -FROM ( - SELECT - * - FROM `functional_alltypes` AS `t0` - UNION ALL - SELECT - * - FROM `functional_alltypes` AS `t0` -) AS `t1` \ No newline at end of file +FROM `functional_alltypes` AS `t0` +UNION ALL +SELECT + * +FROM `functional_alltypes` AS `t0` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_union/True/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_union/True/out.sql index 53c098c9941b..2aafd02252b4 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_union/True/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_union/True/out.sql @@ -1,11 +1,7 @@ SELECT * -FROM ( - SELECT - * - FROM `functional_alltypes` AS `t0` - UNION DISTINCT - SELECT - * - FROM `functional_alltypes` AS `t0` -) AS `t1` \ No newline at end of file +FROM `functional_alltypes` AS `t0` +UNION DISTINCT +SELECT + * +FROM `functional_alltypes` AS `t0` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_union_cte/False-False/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_union_cte/False-False/out.sql index acb003ec089f..e8bcdb210ba7 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_union_cte/False-False/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_union_cte/False-False/out.sql @@ -11,21 +11,13 @@ SELECT FROM ( SELECT * - FROM ( - SELECT - * - FROM ( - SELECT - * - FROM `t1` AS `t2` - UNION ALL - SELECT - * - FROM `t1` AS `t4` - ) AS `t5` - ) AS `t6` + FROM `t1` AS `t2` UNION ALL SELECT * - FROM `t1` AS `t3` -) AS `t7` \ No newline at end of file + FROM `t1` AS `t4` +) AS `t5` +UNION ALL +SELECT + * +FROM `t1` AS `t3` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_union_cte/False-True/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_union_cte/False-True/out.sql index 530ada1a9ed2..23a109821588 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_union_cte/False-True/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_union_cte/False-True/out.sql @@ -11,21 +11,13 @@ SELECT FROM ( SELECT * - FROM ( - SELECT - * - FROM ( - SELECT - * - FROM `t1` AS `t2` - UNION DISTINCT - SELECT - * - FROM `t1` AS `t4` - ) AS `t5` - ) AS `t6` - UNION ALL + FROM `t1` AS `t2` + UNION DISTINCT SELECT * - FROM `t1` AS `t3` -) AS `t7` \ No newline at end of file + FROM `t1` AS `t4` +) AS `t5` +UNION ALL +SELECT + * +FROM `t1` AS `t3` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_union_cte/True-False/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_union_cte/True-False/out.sql index 96dfd5ec5081..d07b7e3e7cd2 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_union_cte/True-False/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_union_cte/True-False/out.sql @@ -11,21 +11,13 @@ SELECT FROM ( SELECT * - FROM ( - SELECT - * - FROM ( - SELECT - * - FROM `t1` AS `t2` - UNION ALL - SELECT - * - FROM `t1` AS `t4` - ) AS `t5` - ) AS `t6` - UNION DISTINCT + FROM `t1` AS `t2` + UNION ALL SELECT * - FROM `t1` AS `t3` -) AS `t7` \ No newline at end of file + FROM `t1` AS `t4` +) AS `t5` +UNION DISTINCT +SELECT + * +FROM `t1` AS `t3` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_union_cte/True-True/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_union_cte/True-True/out.sql index e17db7e4eee2..6cea925621dd 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_union_cte/True-True/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_union_cte/True-True/out.sql @@ -11,21 +11,13 @@ SELECT FROM ( SELECT * - FROM ( - SELECT - * - FROM ( - SELECT - * - FROM `t1` AS `t2` - UNION DISTINCT - SELECT - * - FROM `t1` AS `t4` - ) AS `t5` - ) AS `t6` + FROM `t1` AS `t2` UNION DISTINCT SELECT * - FROM `t1` AS `t3` -) AS `t7` \ No newline at end of file + FROM `t1` AS `t4` +) AS `t5` +UNION DISTINCT +SELECT + * +FROM `t1` AS `t3` \ No newline at end of file diff --git a/ibis/backends/postgres/tests/snapshots/test_functions/test_union_cte/False/out.sql b/ibis/backends/postgres/tests/snapshots/test_functions/test_union_cte/False/out.sql index 5de93bab93c9..ac3d4a39cb4e 100644 --- a/ibis/backends/postgres/tests/snapshots/test_functions/test_union_cte/False/out.sql +++ b/ibis/backends/postgres/tests/snapshots/test_functions/test_union_cte/False/out.sql @@ -11,21 +11,13 @@ SELECT FROM ( SELECT * - FROM ( - SELECT - * - FROM ( - SELECT - * - FROM "t1" AS "t2" - UNION ALL - SELECT - * - FROM "t1" AS "t4" - ) AS "t5" - ) AS "t6" + FROM "t1" AS "t2" UNION ALL SELECT * - FROM "t1" AS "t3" -) AS "t7" \ No newline at end of file + FROM "t1" AS "t4" +) AS "t5" +UNION ALL +SELECT + * +FROM "t1" AS "t3" \ No newline at end of file diff --git a/ibis/backends/postgres/tests/snapshots/test_functions/test_union_cte/True/out.sql b/ibis/backends/postgres/tests/snapshots/test_functions/test_union_cte/True/out.sql index baeade441368..83351713767d 100644 --- a/ibis/backends/postgres/tests/snapshots/test_functions/test_union_cte/True/out.sql +++ b/ibis/backends/postgres/tests/snapshots/test_functions/test_union_cte/True/out.sql @@ -11,21 +11,13 @@ SELECT FROM ( SELECT * - FROM ( - SELECT - * - FROM ( - SELECT - * - FROM "t1" AS "t2" - UNION - SELECT - * - FROM "t1" AS "t4" - ) AS "t5" - ) AS "t6" + FROM "t1" AS "t2" UNION SELECT * - FROM "t1" AS "t3" -) AS "t7" \ No newline at end of file + FROM "t1" AS "t4" +) AS "t5" +UNION +SELECT + * +FROM "t1" AS "t3" \ No newline at end of file diff --git a/ibis/backends/risingwave/tests/snapshots/test_functions/test_union_cte/False/out.sql b/ibis/backends/risingwave/tests/snapshots/test_functions/test_union_cte/False/out.sql index 5de93bab93c9..ac3d4a39cb4e 100644 --- a/ibis/backends/risingwave/tests/snapshots/test_functions/test_union_cte/False/out.sql +++ b/ibis/backends/risingwave/tests/snapshots/test_functions/test_union_cte/False/out.sql @@ -11,21 +11,13 @@ SELECT FROM ( SELECT * - FROM ( - SELECT - * - FROM ( - SELECT - * - FROM "t1" AS "t2" - UNION ALL - SELECT - * - FROM "t1" AS "t4" - ) AS "t5" - ) AS "t6" + FROM "t1" AS "t2" UNION ALL SELECT * - FROM "t1" AS "t3" -) AS "t7" \ No newline at end of file + FROM "t1" AS "t4" +) AS "t5" +UNION ALL +SELECT + * +FROM "t1" AS "t3" \ No newline at end of file diff --git a/ibis/backends/risingwave/tests/snapshots/test_functions/test_union_cte/True/out.sql b/ibis/backends/risingwave/tests/snapshots/test_functions/test_union_cte/True/out.sql index baeade441368..83351713767d 100644 --- a/ibis/backends/risingwave/tests/snapshots/test_functions/test_union_cte/True/out.sql +++ b/ibis/backends/risingwave/tests/snapshots/test_functions/test_union_cte/True/out.sql @@ -11,21 +11,13 @@ SELECT FROM ( SELECT * - FROM ( - SELECT - * - FROM ( - SELECT - * - FROM "t1" AS "t2" - UNION - SELECT - * - FROM "t1" AS "t4" - ) AS "t5" - ) AS "t6" + FROM "t1" AS "t2" UNION SELECT * - FROM "t1" AS "t3" -) AS "t7" \ No newline at end of file + FROM "t1" AS "t4" +) AS "t5" +UNION +SELECT + * +FROM "t1" AS "t3" \ No newline at end of file diff --git a/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/bigquery/out.sql b/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/bigquery/out.sql index 7e0c9c347e00..e19b9a0bafb4 100644 --- a/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/bigquery/out.sql +++ b/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/bigquery/out.sql @@ -138,25 +138,21 @@ SELECT FROM ( SELECT * - FROM ( - SELECT - * - FROM `t5` AS `t6` - ORDER BY - `t6`.`diff` DESC - LIMIT 10 - ) AS `t9` - UNION ALL + FROM `t5` AS `t6` + ORDER BY + `t6`.`diff` DESC + LIMIT 10 +) AS `t9` +UNION ALL +SELECT + * +FROM ( SELECT * - FROM ( - SELECT - * - FROM `t5` AS `t6` - WHERE - `t6`.`diff` < 0 - ORDER BY - `t6`.`diff` ASC NULLS LAST - LIMIT 10 - ) AS `t10` -) AS `t11` \ No newline at end of file + FROM `t5` AS `t6` + WHERE + `t6`.`diff` < 0 + ORDER BY + `t6`.`diff` ASC NULLS LAST + LIMIT 10 +) AS `t10` \ No newline at end of file diff --git a/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/clickhouse/out.sql b/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/clickhouse/out.sql index e68d6cd280d0..13f05009a8c0 100644 --- a/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/clickhouse/out.sql +++ b/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/clickhouse/out.sql @@ -60,25 +60,21 @@ SELECT FROM ( SELECT * - FROM ( - SELECT - * - FROM "t5" AS "t6" - ORDER BY - "t6"."diff" DESC - LIMIT 10 - ) AS "t9" - UNION ALL + FROM "t5" AS "t6" + ORDER BY + "t6"."diff" DESC + LIMIT 10 +) AS "t9" +UNION ALL +SELECT + * +FROM ( SELECT * - FROM ( - SELECT - * - FROM "t5" AS "t6" - WHERE - "t6"."diff" < 0 - ORDER BY - "t6"."diff" ASC - LIMIT 10 - ) AS "t10" -) AS "t11" \ No newline at end of file + FROM "t5" AS "t6" + WHERE + "t6"."diff" < 0 + ORDER BY + "t6"."diff" ASC + LIMIT 10 +) AS "t10" \ No newline at end of file diff --git a/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/duckdb/out.sql b/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/duckdb/out.sql index 14f7bbe4d59a..90c27a09e25e 100644 --- a/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/duckdb/out.sql +++ b/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/duckdb/out.sql @@ -60,25 +60,21 @@ SELECT FROM ( SELECT * - FROM ( - SELECT - * - FROM "t5" AS "t6" - ORDER BY - "t6"."diff" DESC - LIMIT 10 - ) AS "t9" - UNION ALL + FROM "t5" AS "t6" + ORDER BY + "t6"."diff" DESC + LIMIT 10 +) AS "t9" +UNION ALL +SELECT + * +FROM ( SELECT * - FROM ( - SELECT - * - FROM "t5" AS "t6" - WHERE - "t6"."diff" < CAST(0 AS TINYINT) - ORDER BY - "t6"."diff" ASC - LIMIT 10 - ) AS "t10" -) AS "t11" \ No newline at end of file + FROM "t5" AS "t6" + WHERE + "t6"."diff" < CAST(0 AS TINYINT) + ORDER BY + "t6"."diff" ASC + LIMIT 10 +) AS "t10" \ No newline at end of file diff --git a/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/postgres/out.sql b/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/postgres/out.sql index 05ffd49ca3a6..005658728578 100644 --- a/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/postgres/out.sql +++ b/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/postgres/out.sql @@ -41,25 +41,21 @@ SELECT FROM ( SELECT * - FROM ( - SELECT - * - FROM "t5" AS "t6" - ORDER BY - "t6"."diff" DESC NULLS LAST - LIMIT 10 - ) AS "t9" - UNION ALL + FROM "t5" AS "t6" + ORDER BY + "t6"."diff" DESC NULLS LAST + LIMIT 10 +) AS "t9" +UNION ALL +SELECT + * +FROM ( SELECT * - FROM ( - SELECT - * - FROM "t5" AS "t6" - WHERE - "t6"."diff" < 0 - ORDER BY - "t6"."diff" ASC - LIMIT 10 - ) AS "t10" -) AS "t11" \ No newline at end of file + FROM "t5" AS "t6" + WHERE + "t6"."diff" < 0 + ORDER BY + "t6"."diff" ASC + LIMIT 10 +) AS "t10" \ No newline at end of file diff --git a/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/pyspark/out.sql b/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/pyspark/out.sql index a8f30b99c0c3..cc6373fb6cf7 100644 --- a/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/pyspark/out.sql +++ b/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/pyspark/out.sql @@ -60,25 +60,21 @@ SELECT FROM ( SELECT * - FROM ( - SELECT - * - FROM `t5` AS `t6` - ORDER BY - `t6`.`diff` DESC - LIMIT 10 - ) AS `t9` - UNION ALL + FROM `t5` AS `t6` + ORDER BY + `t6`.`diff` DESC + LIMIT 10 +) AS `t9` +UNION ALL +SELECT + * +FROM ( SELECT * - FROM ( - SELECT - * - FROM `t5` AS `t6` - WHERE - `t6`.`diff` < 0 - ORDER BY - `t6`.`diff` ASC NULLS LAST - LIMIT 10 - ) AS `t10` -) AS `t11` \ No newline at end of file + FROM `t5` AS `t6` + WHERE + `t6`.`diff` < 0 + ORDER BY + `t6`.`diff` ASC NULLS LAST + LIMIT 10 +) AS `t10` \ No newline at end of file diff --git a/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/trino/out.sql b/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/trino/out.sql index 1c5d8cb8af38..da950f94d1b1 100644 --- a/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/trino/out.sql +++ b/ibis/backends/tests/snapshots/test_sql/test_union_aliasing/trino/out.sql @@ -58,25 +58,21 @@ SELECT FROM ( SELECT * - FROM ( - SELECT - * - FROM "t5" AS "t6" - ORDER BY - "t6"."diff" DESC - LIMIT 10 - ) AS "t9" - UNION ALL + FROM "t5" AS "t6" + ORDER BY + "t6"."diff" DESC + LIMIT 10 +) AS "t9" +UNION ALL +SELECT + * +FROM ( SELECT * - FROM ( - SELECT - * - FROM "t5" AS "t6" - WHERE - "t6"."diff" < 0 - ORDER BY - "t6"."diff" ASC - LIMIT 10 - ) AS "t10" -) AS "t11" \ No newline at end of file + FROM "t5" AS "t6" + WHERE + "t6"."diff" < 0 + ORDER BY + "t6"."diff" ASC + LIMIT 10 +) AS "t10" \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_table_difference/out.sql b/ibis/backends/tests/sql/snapshots/test_compiler/test_table_difference/out.sql index 5ad07748bbe2..b5bc844f70a8 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_table_difference/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_table_difference/out.sql @@ -2,24 +2,20 @@ SELECT * FROM ( SELECT - * - FROM ( - SELECT - "t0"."string_col" AS "key", - CAST("t0"."float_col" AS DOUBLE) AS "value" - FROM "functional_alltypes" AS "t0" - WHERE - "t0"."int_col" > CAST(0 AS TINYINT) - ) AS "t1" - EXCEPT + "t0"."string_col" AS "key", + CAST("t0"."float_col" AS DOUBLE) AS "value" + FROM "functional_alltypes" AS "t0" + WHERE + "t0"."int_col" > CAST(0 AS TINYINT) +) AS "t1" +EXCEPT +SELECT + * +FROM ( SELECT - * - FROM ( - SELECT - "t0"."string_col" AS "key", - "t0"."double_col" AS "value" - FROM "functional_alltypes" AS "t0" - WHERE - "t0"."int_col" <= CAST(0 AS TINYINT) - ) AS "t2" -) AS "t3" \ No newline at end of file + "t0"."string_col" AS "key", + "t0"."double_col" AS "value" + FROM "functional_alltypes" AS "t0" + WHERE + "t0"."int_col" <= CAST(0 AS TINYINT) +) AS "t2" \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_table_intersect/out.sql b/ibis/backends/tests/sql/snapshots/test_compiler/test_table_intersect/out.sql index 4286fc106660..8ffb71b3b102 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_table_intersect/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_table_intersect/out.sql @@ -2,24 +2,20 @@ SELECT * FROM ( SELECT - * - FROM ( - SELECT - "t0"."string_col" AS "key", - CAST("t0"."float_col" AS DOUBLE) AS "value" - FROM "functional_alltypes" AS "t0" - WHERE - "t0"."int_col" > CAST(0 AS TINYINT) - ) AS "t1" - INTERSECT + "t0"."string_col" AS "key", + CAST("t0"."float_col" AS DOUBLE) AS "value" + FROM "functional_alltypes" AS "t0" + WHERE + "t0"."int_col" > CAST(0 AS TINYINT) +) AS "t1" +INTERSECT +SELECT + * +FROM ( SELECT - * - FROM ( - SELECT - "t0"."string_col" AS "key", - "t0"."double_col" AS "value" - FROM "functional_alltypes" AS "t0" - WHERE - "t0"."int_col" <= CAST(0 AS TINYINT) - ) AS "t2" -) AS "t3" \ No newline at end of file + "t0"."string_col" AS "key", + "t0"."double_col" AS "value" + FROM "functional_alltypes" AS "t0" + WHERE + "t0"."int_col" <= CAST(0 AS TINYINT) +) AS "t2" \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_union/out.sql b/ibis/backends/tests/sql/snapshots/test_compiler/test_union/out.sql index 6536cf67d7f4..fbda8f8cffb8 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_union/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_union/out.sql @@ -2,24 +2,20 @@ SELECT * FROM ( SELECT - * - FROM ( - SELECT - "t0"."string_col" AS "key", - CAST("t0"."float_col" AS DOUBLE) AS "value" - FROM "functional_alltypes" AS "t0" - WHERE - "t0"."int_col" > CAST(0 AS TINYINT) - ) AS "t1" - UNION + "t0"."string_col" AS "key", + CAST("t0"."float_col" AS DOUBLE) AS "value" + FROM "functional_alltypes" AS "t0" + WHERE + "t0"."int_col" > CAST(0 AS TINYINT) +) AS "t1" +UNION +SELECT + * +FROM ( SELECT - * - FROM ( - SELECT - "t0"."string_col" AS "key", - "t0"."double_col" AS "value" - FROM "functional_alltypes" AS "t0" - WHERE - "t0"."int_col" <= CAST(0 AS TINYINT) - ) AS "t2" -) AS "t3" \ No newline at end of file + "t0"."string_col" AS "key", + "t0"."double_col" AS "value" + FROM "functional_alltypes" AS "t0" + WHERE + "t0"."int_col" <= CAST(0 AS TINYINT) +) AS "t2" \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_compiler/test_union_order_by/out.sql b/ibis/backends/tests/sql/snapshots/test_compiler/test_union_order_by/out.sql index c175e4684c2d..06af95fbf21b 100644 --- a/ibis/backends/tests/sql/snapshots/test_compiler/test_union_order_by/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_compiler/test_union_order_by/out.sql @@ -7,12 +7,8 @@ WITH "t1" AS ( ) SELECT * -FROM ( - SELECT - * - FROM "t1" AS "t2" - UNION ALL - SELECT - * - FROM "t1" AS "t2" -) AS "t3" \ No newline at end of file +FROM "t1" AS "t2" +UNION ALL +SELECT + * +FROM "t1" AS "t2" \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_complex_union/result.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_complex_union/result.sql index d6a3481d98cd..ba179f3abdfa 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_complex_union/result.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_complex_union/result.sql @@ -2,20 +2,16 @@ SELECT * FROM ( SELECT - * - FROM ( - SELECT - CAST("t0"."diag" + CAST(1 AS TINYINT) AS INT) AS "diag", - "t0"."status" - FROM "aids2_one" AS "t0" - ) AS "t2" - UNION ALL + CAST("t0"."diag" + CAST(1 AS TINYINT) AS INT) AS "diag", + "t0"."status" + FROM "aids2_one" AS "t0" +) AS "t2" +UNION ALL +SELECT + * +FROM ( SELECT - * - FROM ( - SELECT - CAST("t1"."diag" + CAST(1 AS TINYINT) AS INT) AS "diag", - "t1"."status" - FROM "aids2_two" AS "t1" - ) AS "t3" -) AS "t4" \ No newline at end of file + CAST("t1"."diag" + CAST(1 AS TINYINT) AS INT) AS "diag", + "t1"."status" + FROM "aids2_two" AS "t1" +) AS "t3" \ No newline at end of file diff --git a/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_in_union/out.sql b/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_in_union/out.sql index b9a1d6cb0376..bdaeccfcf870 100644 --- a/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_in_union/out.sql +++ b/ibis/backends/tests/sql/snapshots/test_select_sql/test_subquery_in_union/out.sql @@ -18,12 +18,8 @@ WITH "t1" AS ( ) SELECT * -FROM ( - SELECT - * - FROM "t5" AS "t6" - UNION ALL - SELECT - * - FROM "t5" AS "t7" -) AS "t8" \ No newline at end of file +FROM "t5" AS "t6" +UNION ALL +SELECT + * +FROM "t5" AS "t7" \ No newline at end of file diff --git a/ibis/expr/tests/snapshots/test_format/test_table_count_expr/union_repr.txt b/ibis/expr/tests/snapshots/test_format/test_table_count_expr/union_repr.txt index 39d67ba6a7a6..6dc9d24f8065 100644 --- a/ibis/expr/tests/snapshots/test_format/test_table_count_expr/union_repr.txt +++ b/ibis/expr/tests/snapshots/test_format/test_table_count_expr/union_repr.txt @@ -8,8 +8,4 @@ r1 := UnboundTable: t2 r2 := Union[r0, r1, distinct=False] -r3 := Project[r2] - a: r2.a - b: r2.b - -CountStar(): CountStar(r3) \ No newline at end of file +CountStar(): CountStar(r2) \ No newline at end of file diff --git a/ibis/expr/types/relations.py b/ibis/expr/types/relations.py index fc5b3c29d4da..bd1e4b609982 100644 --- a/ibis/expr/types/relations.py +++ b/ibis/expr/types/relations.py @@ -1693,7 +1693,7 @@ def _assemble_set_op( queue.append(node) result = queue.popleft() assert not queue, "items left in queue" - return result.to_expr().select(*self.columns) + return result.to_expr() def union(self, table: Table, *rest: Table, distinct: bool = False) -> Table: """Compute the set union of multiple table expressions. @@ -1883,7 +1883,7 @@ def difference(self, table: Table, *rest: Table, distinct: bool = True) -> Table node = ops.Difference(self, table, distinct=distinct) for table in rest: node = ops.Difference(node, table, distinct=distinct) - return node.to_expr().select(self.columns) + return node.to_expr() @deprecated(as_of="9.0", instead="use table.as_scalar() instead") def to_array(self) -> ir.Column: diff --git a/ibis/tests/benchmarks/test_benchmarks.py b/ibis/tests/benchmarks/test_benchmarks.py index 415b1b9728b7..dce71e9ab91c 100644 --- a/ibis/tests/benchmarks/test_benchmarks.py +++ b/ibis/tests/benchmarks/test_benchmarks.py @@ -850,12 +850,12 @@ def test_column_access(benchmark, many_cols, getter): benchmark(getter, many_cols) -@pytest.fixture(scope="module") -def many_tables(): +@pytest.fixture(scope="module", params=[1000, 10000]) +def many_tables(request): num_cols = 10 - num_tables = 1000 return [ - ibis.table({f"c{i}": "int" for i in range(num_cols)}) for _ in range(num_tables) + ibis.table({f"c{i}": "int" for i in range(num_cols)}) + for _ in range(request.param) ] @@ -863,6 +863,7 @@ def test_large_union_construct(benchmark, many_tables): assert benchmark(lambda args: ibis.union(*args), many_tables) is not None +@pytest.mark.timeout(180) def test_large_union_compile(benchmark, many_tables): expr = ibis.union(*many_tables) assert benchmark(ibis.to_sql, expr) is not None diff --git a/ibis/tests/expr/test_set_operations.py b/ibis/tests/expr/test_set_operations.py index 3012c7a0ac10..3eb93f3c56be 100644 --- a/ibis/tests/expr/test_set_operations.py +++ b/ibis/tests/expr/test_set_operations.py @@ -51,13 +51,13 @@ def test_operation_supports_schemas_with_different_field_order(method): assert u1.schema() == a.schema() - u1 = u1.op().parent + u1 = u1.op() assert u1.left == a.op() assert u1.right == b.op() # a selection is added to ensure that the field order of the right table # matches the field order of the left table - u2 = u2.op().parent + u2 = u2.op() assert u2.schema == a.schema() assert u2.left == a.op() diff --git a/ibis/tests/expr/test_table.py b/ibis/tests/expr/test_table.py index 4dab6aee362a..666e58dc3495 100644 --- a/ibis/tests/expr/test_table.py +++ b/ibis/tests/expr/test_table.py @@ -1420,11 +1420,11 @@ def test_union( setops_relation_error_message, ): result = setops_table_foo.union(setops_table_bar) - assert isinstance(result.op().parent, ops.Union) - assert not result.op().parent.distinct + assert isinstance(result.op(), ops.Union) + assert not result.op().distinct result = setops_table_foo.union(setops_table_bar, distinct=True) - assert result.op().parent.distinct + assert result.op().distinct with pytest.raises(RelationError, match=setops_relation_error_message): setops_table_foo.union(setops_table_baz) @@ -1437,7 +1437,7 @@ def test_intersection( setops_relation_error_message, ): result = setops_table_foo.intersect(setops_table_bar) - assert isinstance(result.op().parent, ops.Intersection) + assert isinstance(result.op(), ops.Intersection) with pytest.raises(RelationError, match=setops_relation_error_message): setops_table_foo.intersect(setops_table_baz) @@ -1450,7 +1450,7 @@ def test_difference( setops_relation_error_message, ): result = setops_table_foo.difference(setops_table_bar) - assert isinstance(result.op().parent, ops.Difference) + assert isinstance(result.op(), ops.Difference) with pytest.raises(RelationError, match=setops_relation_error_message): setops_table_foo.difference(setops_table_baz)