summaryrefslogtreecommitdiffstats
path: root/tests/test_optimizer.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-06-29 13:02:26 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-06-29 13:02:26 +0000
commita299be925028c6243d34b020920dfd0135bb9574 (patch)
tree39a7a231466fd9d139047a67672f09040dd23394 /tests/test_optimizer.py
parentAdding upstream version 16.4.2. (diff)
downloadsqlglot-a299be925028c6243d34b020920dfd0135bb9574.tar.xz
sqlglot-a299be925028c6243d34b020920dfd0135bb9574.zip
Adding upstream version 16.7.3.upstream/16.7.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_optimizer.py')
-rw-r--r--tests/test_optimizer.py32
1 files changed, 30 insertions, 2 deletions
diff --git a/tests/test_optimizer.py b/tests/test_optimizer.py
index 94bd0ba..b7425af 100644
--- a/tests/test_optimizer.py
+++ b/tests/test_optimizer.py
@@ -216,6 +216,17 @@ class TestOptimizer(unittest.TestCase):
"SELECT y AS y FROM x",
)
+ self.assertEqual(
+ optimizer.qualify.qualify(
+ parse_one(
+ "WITH X AS (SELECT Y.A FROM DB.Y CROSS JOIN a.b.INFORMATION_SCHEMA.COLUMNS) SELECT `A` FROM X",
+ read="bigquery",
+ ),
+ 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"',
+ )
+
self.check_file("qualify_columns", qualify_columns, execute=True, schema=self.schema)
def test_qualify_columns__with_invisible(self):
@@ -262,7 +273,7 @@ class TestOptimizer(unittest.TestCase):
# check order of lateral expansion with no schema
self.assertEqual(
optimizer.optimize("SELECT a + 1 AS d, d + 1 AS e FROM x WHERE e > 1 GROUP BY e").sql(),
- 'SELECT "x"."a" + 1 AS "d", "x"."a" + 2 AS "e" FROM "x" AS "x" WHERE "x"."a" + 2 > 1 GROUP BY "x"."a" + 2',
+ 'SELECT "x"."a" + 1 AS "d", "x"."a" + 1 + 1 AS "e" FROM "x" AS "x" WHERE "x"."a" + 2 > 1 GROUP BY "x"."a" + 1 + 1',
)
self.assertEqual(
@@ -724,6 +735,23 @@ FROM READ_CSV('tests/fixtures/optimizer/tpc-h/nation.csv.gz', 'delimiter', '|')
).sql(pretty=True, dialect="snowflake")
for func in (optimizer.qualify.qualify, optimizer.optimize):
- source_query = parse_one('SELECT * FROM example."source"', read="snowflake")
+ source_query = parse_one('SELECT * FROM example."source" AS "source"', read="snowflake")
transformed = func(source_query, dialect="snowflake", schema=schema)
self.assertEqual(transformed.sql(pretty=True, dialect="snowflake"), expected)
+
+ def test_no_pseudocolumn_expansion(self):
+ schema = {
+ "a": {
+ "a": "text",
+ "b": "text",
+ "_PARTITIONDATE": "date",
+ "_PARTITIONTIME": "timestamp",
+ }
+ }
+
+ self.assertEqual(
+ optimizer.optimize(
+ parse_one("SELECT * FROM a"), schema=MappingSchema(schema, dialect="bigquery")
+ ),
+ parse_one('SELECT "a"."a" AS "a", "a"."b" AS "b" FROM "a" AS "a"'),
+ )