summaryrefslogtreecommitdiffstats
path: root/tests/test_optimizer.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-11-09 08:14:01 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-11-09 08:14:01 +0000
commit705d595e4873c2b13dd98d4614ca729f4d4ed81c (patch)
treed42152d0d58a859ebf2eff8e5688f988f376703d /tests/test_optimizer.py
parentReleasing debian version 25.26.0-1. (diff)
downloadsqlglot-705d595e4873c2b13dd98d4614ca729f4d4ed81c.tar.xz
sqlglot-705d595e4873c2b13dd98d4614ca729f4d4ed81c.zip
Merging upstream version 25.29.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--tests/test_optimizer.py43
1 files changed, 42 insertions, 1 deletions
diff --git a/tests/test_optimizer.py b/tests/test_optimizer.py
index 9313285..0fa4ff6 100644
--- a/tests/test_optimizer.py
+++ b/tests/test_optimizer.py
@@ -315,7 +315,7 @@ class TestOptimizer(unittest.TestCase):
),
dialect="bigquery",
).sql(),
- 'WITH "x" AS (SELECT "y"."a" AS "a" FROM "DB"."y" AS "y" CROSS JOIN "a"."b"."INFORMATION_SCHEMA"."COLUMNS" AS "COLUMNS") SELECT "x"."a" AS "a" FROM "x" AS "x"',
+ 'WITH "x" AS (SELECT "y"."a" AS "a" FROM "DB"."y" AS "y" CROSS JOIN "a"."b"."INFORMATION_SCHEMA.COLUMNS" AS "columns") SELECT "x"."a" AS "a" FROM "x" AS "x"',
)
self.assertEqual(
@@ -1337,6 +1337,47 @@ FROM READ_CSV('tests/fixtures/optimizer/tpc-h/nation.csv.gz', 'delimiter', '|')
self.assertEqual(union_by_name.selects[0].type.this, exp.DataType.Type.BIGINT)
self.assertEqual(union_by_name.selects[1].type.this, exp.DataType.Type.DOUBLE)
+ # Test chained UNIONs
+ sql = """
+ WITH t AS
+ (
+ SELECT NULL AS col
+ UNION
+ SELECT NULL AS col
+ UNION
+ SELECT 'a' AS col
+ UNION
+ SELECT NULL AS col
+ UNION
+ SELECT NULL AS col
+ )
+ SELECT col FROM t;
+ """
+ self.assertEqual(optimizer.optimize(sql).selects[0].type.this, exp.DataType.Type.VARCHAR)
+
+ # Test UNIONs with nested subqueries
+ sql = """
+ WITH t AS
+ (
+ SELECT NULL AS col
+ UNION
+ (SELECT NULL AS col UNION ALL SELECT 'a' AS col)
+ )
+ SELECT col FROM t;
+ """
+ self.assertEqual(optimizer.optimize(sql).selects[0].type.this, exp.DataType.Type.VARCHAR)
+
+ sql = """
+ WITH t AS
+ (
+ (SELECT NULL AS col UNION ALL SELECT 'a' AS col)
+ UNION
+ SELECT NULL AS col
+ )
+ SELECT col FROM t;
+ """
+ self.assertEqual(optimizer.optimize(sql).selects[0].type.this, exp.DataType.Type.VARCHAR)
+
def test_recursive_cte(self):
query = parse_one(
"""