summaryrefslogtreecommitdiffstats
path: root/tests/test_optimizer.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-07-06 07:28:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-07-06 07:28:09 +0000
commit52f4a5e2260f3e5b919b4e270339afd670bf0b8a (patch)
tree5ca419af0e2e409018492b82f5b9847f0112b5fb /tests/test_optimizer.py
parentAdding upstream version 16.7.7. (diff)
downloadsqlglot-52f4a5e2260f3e5b919b4e270339afd670bf0b8a.tar.xz
sqlglot-52f4a5e2260f3e5b919b4e270339afd670bf0b8a.zip
Adding upstream version 17.2.0.upstream/17.2.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_optimizer.py')
-rw-r--r--tests/test_optimizer.py27
1 files changed, 23 insertions, 4 deletions
diff --git a/tests/test_optimizer.py b/tests/test_optimizer.py
index 40eef9f..0608903 100644
--- a/tests/test_optimizer.py
+++ b/tests/test_optimizer.py
@@ -146,7 +146,8 @@ class TestOptimizer(unittest.TestCase):
df2 = self.conn.execute(optimized.sql(pretty=pretty, dialect="duckdb")).df()
assert_frame_equal(df1, df2)
- def test_optimize(self):
+ @patch("sqlglot.generator.logger")
+ def test_optimize(self, logger):
self.assertEqual(optimizer.optimize("x = 1 + 1", identify=None).sql(), "x = 2")
schema = {
@@ -199,7 +200,8 @@ class TestOptimizer(unittest.TestCase):
self.check_file("normalize", normalize)
- def test_qualify_columns(self):
+ @patch("sqlglot.generator.logger")
+ def test_qualify_columns(self, logger):
self.assertEqual(
optimizer.qualify_columns.qualify_columns(
parse_one("WITH x AS (SELECT a FROM db.y) SELECT z FROM db.x"),
@@ -229,6 +231,17 @@ class TestOptimizer(unittest.TestCase):
'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.assertEqual(
+ optimizer.qualify.qualify(
+ parse_one(
+ "CREATE FUNCTION udfs.`myTest`(`x` FLOAT64) AS (1)",
+ read="bigquery",
+ ),
+ dialect="bigquery",
+ ).sql(dialect="bigquery"),
+ "CREATE FUNCTION `udfs`.`myTest`(`x` FLOAT64) AS (1)",
+ )
+
self.check_file("qualify_columns", qualify_columns, execute=True, schema=self.schema)
def test_qualify_columns__with_invisible(self):
@@ -307,7 +320,8 @@ class TestOptimizer(unittest.TestCase):
pretty=True,
)
- def test_merge_subqueries(self):
+ @patch("sqlglot.generator.logger")
+ def test_merge_subqueries(self, logger):
optimize = partial(
optimizer.optimize,
rules=[
@@ -575,7 +589,9 @@ FROM READ_CSV('tests/fixtures/optimizer/tpc-h/nation.csv.gz', 'delimiter', '|')
def test_function_annotation(self):
schema = {"x": {"cola": "VARCHAR", "colb": "CHAR"}}
- sql = "SELECT x.cola || TRIM(x.colb) AS col, DATE(x.colb) FROM x AS x"
+ sql = (
+ "SELECT x.cola || TRIM(x.colb) AS col, DATE(x.colb), DATEFROMPARTS(y, m, d) FROM x AS x"
+ )
expression = annotate_types(parse_one(sql), schema=schema)
concat_expr_alias = expression.expressions[0]
@@ -590,6 +606,9 @@ FROM READ_CSV('tests/fixtures/optimizer/tpc-h/nation.csv.gz', 'delimiter', '|')
date_expr = expression.expressions[1]
self.assertEqual(date_expr.type.this, exp.DataType.Type.DATE)
+ date_expr = expression.expressions[2]
+ self.assertEqual(date_expr.type.this, exp.DataType.Type.DATE)
+
sql = "SELECT CASE WHEN 1=1 THEN x.cola ELSE x.colb END AS col FROM x AS x"
case_expr_alias = annotate_types(parse_one(sql), schema=schema).expressions[0]