summaryrefslogtreecommitdiffstats
path: root/tests/test_optimizer.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-10-26 17:21:54 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-10-26 17:21:54 +0000
commitc03ba18c491e52cc85d8aae1825dd9e0b4f75e32 (patch)
treef76d58b50900be4bfd2dc15f0ec38d1a70d8417b /tests/test_optimizer.py
parentReleasing debian version 18.13.0-1. (diff)
downloadsqlglot-c03ba18c491e52cc85d8aae1825dd9e0b4f75e32.tar.xz
sqlglot-c03ba18c491e52cc85d8aae1825dd9e0b4f75e32.zip
Merging upstream version 18.17.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_optimizer.py')
-rw-r--r--tests/test_optimizer.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/test_optimizer.py b/tests/test_optimizer.py
index c43a84e..8f5dd08 100644
--- a/tests/test_optimizer.py
+++ b/tests/test_optimizer.py
@@ -550,6 +550,47 @@ FROM READ_CSV('tests/fixtures/optimizer/tpc-h/nation.csv.gz', 'delimiter', '|')
self.assertEqual(expression.right.this.left.type.this, exp.DataType.Type.INT)
self.assertEqual(expression.right.this.right.type.this, exp.DataType.Type.INT)
+ def test_bracket_annotation(self):
+ expression = annotate_types(parse_one("SELECT A[:]")).expressions[0]
+
+ self.assertEqual(expression.type.this, exp.DataType.Type.UNKNOWN)
+ self.assertEqual(expression.expressions[0].type.this, exp.DataType.Type.UNKNOWN)
+
+ expression = annotate_types(parse_one("SELECT ARRAY[1, 2, 3][1]")).expressions[0]
+ self.assertEqual(expression.this.type.sql(), "ARRAY<INT>")
+ self.assertEqual(expression.type.this, exp.DataType.Type.INT)
+
+ expression = annotate_types(parse_one("SELECT ARRAY[1, 2, 3][1 : 2]")).expressions[0]
+ self.assertEqual(expression.this.type.sql(), "ARRAY<INT>")
+ self.assertEqual(expression.type.sql(), "ARRAY<INT>")
+
+ expression = annotate_types(
+ parse_one("SELECT ARRAY[ARRAY[1], ARRAY[2], ARRAY[3]][1][2]")
+ ).expressions[0]
+ self.assertEqual(expression.this.this.type.sql(), "ARRAY<ARRAY<INT>>")
+ self.assertEqual(expression.this.type.sql(), "ARRAY<INT>")
+ self.assertEqual(expression.type.this, exp.DataType.Type.INT)
+
+ expression = annotate_types(
+ parse_one("SELECT ARRAY[ARRAY[1], ARRAY[2], ARRAY[3]][1:2]")
+ ).expressions[0]
+ self.assertEqual(expression.type.sql(), "ARRAY<ARRAY<INT>>")
+
+ expression = annotate_types(parse_one("MAP(1.0, 2, '2', 3.0)['2']", read="spark"))
+ self.assertEqual(expression.type.this, exp.DataType.Type.DOUBLE)
+
+ expression = annotate_types(parse_one("MAP(1.0, 2, x, 3.0)[2]", read="spark"))
+ self.assertEqual(expression.type.this, exp.DataType.Type.UNKNOWN)
+
+ expression = annotate_types(parse_one("MAP(ARRAY(1.0, x), ARRAY(2, 3.0))[x]"))
+ self.assertEqual(expression.type.this, exp.DataType.Type.DOUBLE)
+
+ expression = annotate_types(
+ parse_one("SELECT MAP(1.0, 2, 2, t.y)[2] FROM t", read="spark"),
+ schema={"t": {"y": "int"}},
+ ).expressions[0]
+ self.assertEqual(expression.type.this, exp.DataType.Type.INT)
+
def test_interval_math_annotation(self):
schema = {
"x": {