summaryrefslogtreecommitdiffstats
path: root/tests/test_optimizer.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-01-31 05:44:37 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-01-31 05:44:37 +0000
commit5f8be2e0852f3c925fb873a48946caee3050899f (patch)
tree1f31666277e226f47180321c08be7ebbedc2780e /tests/test_optimizer.py
parentAdding upstream version 20.9.0. (diff)
downloadsqlglot-5f8be2e0852f3c925fb873a48946caee3050899f.tar.xz
sqlglot-5f8be2e0852f3c925fb873a48946caee3050899f.zip
Adding upstream version 20.11.0.upstream/20.11.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_optimizer.py')
-rw-r--r--tests/test_optimizer.py28
1 files changed, 18 insertions, 10 deletions
diff --git a/tests/test_optimizer.py b/tests/test_optimizer.py
index 3f96a0e..d0ef8aa 100644
--- a/tests/test_optimizer.py
+++ b/tests/test_optimizer.py
@@ -262,7 +262,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"',
+ '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(
@@ -550,18 +550,26 @@ FROM READ_CSV('tests/fixtures/optimizer/tpc-h/nation.csv.gz', 'delimiter', '|')
def test_struct_type_annotation(self):
tests = {
- "SELECT STRUCT(1 AS col)": "STRUCT<col INT>",
- "SELECT STRUCT(1 AS col, 2.5 AS row)": "STRUCT<col INT, row DOUBLE>",
- "SELECT STRUCT(1)": "STRUCT<INT>",
- "SELECT STRUCT(1 AS col, 2.5 AS row, struct(3.5 AS inner_col, 4 AS inner_row) AS nested_struct)": "STRUCT<col INT, row DOUBLE, nested_struct STRUCT<inner_col DOUBLE, inner_row INT>>",
- "SELECT STRUCT(1 AS col, 2.5, ARRAY[1, 2, 3] AS nested_array, 'foo')": "STRUCT<col INT, DOUBLE, nested_array ARRAY<INT>, VARCHAR>",
- "SELECT STRUCT(1, 2.5, 'bar')": "STRUCT<INT, DOUBLE, VARCHAR>",
- 'SELECT STRUCT(1 AS "CaseSensitive")': 'STRUCT<"CaseSensitive" INT>',
+ ("SELECT STRUCT(1 AS col)", "spark"): "STRUCT<col INT>",
+ ("SELECT STRUCT(1 AS col, 2.5 AS row)", "spark"): "STRUCT<col INT, row DOUBLE>",
+ ("SELECT STRUCT(1)", "bigquery"): "STRUCT<INT>",
+ (
+ "SELECT STRUCT(1 AS col, 2.5 AS row, struct(3.5 AS inner_col, 4 AS inner_row) AS nested_struct)",
+ "spark",
+ ): "STRUCT<col INT, row DOUBLE, nested_struct STRUCT<inner_col DOUBLE, inner_row INT>>",
+ (
+ "SELECT STRUCT(1 AS col, 2.5, ARRAY[1, 2, 3] AS nested_array, 'foo')",
+ "bigquery",
+ ): "STRUCT<col INT, DOUBLE, nested_array ARRAY<INT>, VARCHAR>",
+ ("SELECT STRUCT(1, 2.5, 'bar')", "spark"): "STRUCT<INT, DOUBLE, VARCHAR>",
+ ('SELECT STRUCT(1 AS "CaseSensitive")', "spark"): 'STRUCT<"CaseSensitive" INT>',
+ ("SELECT STRUCT_PACK(a := 1, b := 2.5)", "duckdb"): "STRUCT<a INT, b DOUBLE>",
+ ("SELECT ROW(1, 2.5, 'foo')", "presto"): "STRUCT<INT, DOUBLE, VARCHAR>",
}
- for sql, target_type in tests.items():
+ for (sql, dialect), target_type in tests.items():
with self.subTest(sql):
- expression = annotate_types(parse_one(sql))
+ expression = annotate_types(parse_one(sql, read=dialect))
assert expression.expressions[0].is_type(target_type)
def test_literal_type_annotation(self):