diff options
Diffstat (limited to 'tests/test_optimizer.py')
-rw-r--r-- | tests/test_optimizer.py | 43 |
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( """ |