summaryrefslogtreecommitdiffstats
path: root/tests/test_optimizer.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_optimizer.py')
-rw-r--r--tests/test_optimizer.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/tests/test_optimizer.py b/tests/test_optimizer.py
index a40f089..8775852 100644
--- a/tests/test_optimizer.py
+++ b/tests/test_optimizer.py
@@ -679,7 +679,7 @@ FROM READ_CSV('tests/fixtures/optimizer/tpc-h/nation.csv.gz', 'delimiter', '|')
def test_unknown_annotation(self):
schema = {"x": {"cola": "VARCHAR"}}
- sql = "SELECT x.cola || SOME_ANONYMOUS_FUNC(x.cola) AS col FROM x AS x"
+ sql = "SELECT x.cola + SOME_ANONYMOUS_FUNC(x.cola) AS col FROM x AS x"
concat_expr_alias = annotate_types(parse_one(sql), schema=schema).expressions[0]
self.assertEqual(concat_expr_alias.type.this, exp.DataType.Type.UNKNOWN)
@@ -702,7 +702,7 @@ FROM READ_CSV('tests/fixtures/optimizer/tpc-h/nation.csv.gz', 'delimiter', '|')
self.assertEqual(expression.right.type.this, exp.DataType.Type.INT)
# NULL <op> UNKNOWN should yield NULL
- sql = "SELECT NULL || SOME_ANONYMOUS_FUNC() AS result"
+ sql = "SELECT NULL + SOME_ANONYMOUS_FUNC() AS result"
concat_expr_alias = annotate_types(parse_one(sql)).expressions[0]
self.assertEqual(concat_expr_alias.type.this, exp.DataType.Type.NULL)
@@ -776,6 +776,17 @@ FROM READ_CSV('tests/fixtures/optimizer/tpc-h/nation.csv.gz', 'delimiter', '|')
self.assertEqual(exp.DataType.Type.ARRAY, expression.selects[0].type.this)
self.assertEqual(expression.selects[0].type.sql(), "ARRAY<INT>")
+ def test_type_annotation_cache(self):
+ sql = "SELECT 1 + 1"
+ expression = annotate_types(parse_one(sql))
+
+ self.assertEqual(exp.DataType.Type.INT, expression.selects[0].type.this)
+
+ expression.selects[0].this.replace(parse_one("1.2"))
+ expression = annotate_types(expression)
+
+ self.assertEqual(exp.DataType.Type.DOUBLE, expression.selects[0].type.this)
+
def test_user_defined_type_annotation(self):
schema = MappingSchema({"t": {"x": "int"}}, dialect="postgres")
expression = annotate_types(parse_one("SELECT CAST(x AS IPADDRESS) FROM t"), schema=schema)