summaryrefslogtreecommitdiffstats
path: root/tests/test_executor.py
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2023-12-10 10:45:55 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2023-12-10 10:45:55 +0000
commit02df6cdb000c8dbf739abda2af321a4f90d1b059 (patch)
tree2fc1daf848082ff67a11e60025cac260e3c318b2 /tests/test_executor.py
parentAdding upstream version 19.0.1. (diff)
downloadsqlglot-02df6cdb000c8dbf739abda2af321a4f90d1b059.tar.xz
sqlglot-02df6cdb000c8dbf739abda2af321a4f90d1b059.zip
Adding upstream version 20.1.0.upstream/20.1.0
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'tests/test_executor.py')
-rw-r--r--tests/test_executor.py51
1 files changed, 48 insertions, 3 deletions
diff --git a/tests/test_executor.py b/tests/test_executor.py
index 721550e..ffe00a7 100644
--- a/tests/test_executor.py
+++ b/tests/test_executor.py
@@ -289,11 +289,47 @@ class TestExecutor(unittest.TestCase):
["a"],
[(1,), (2,), (3,)],
),
+ (
+ "SELECT 1 AS a UNION SELECT 2 AS a UNION SELECT 3 AS a",
+ ["a"],
+ [(1,), (2,), (3,)],
+ ),
+ (
+ "SELECT 1 / 2 AS a",
+ ["a"],
+ [
+ (0.5,),
+ ],
+ ),
+ ("SELECT 1 / 0 AS a", ["a"], ZeroDivisionError),
+ (
+ exp.select(
+ exp.alias_(exp.Literal.number(1).div(exp.Literal.number(2), typed=True), "a")
+ ),
+ ["a"],
+ [
+ (0,),
+ ],
+ ),
+ (
+ exp.select(
+ exp.alias_(exp.Literal.number(1).div(exp.Literal.number(0), safe=True), "a")
+ ),
+ ["a"],
+ [
+ (None,),
+ ],
+ ),
]:
with self.subTest(sql):
- result = execute(sql, schema=schema, tables=tables)
- self.assertEqual(result.columns, tuple(cols))
- self.assertEqual(set(result.rows), set(rows))
+ if isinstance(rows, list):
+ result = execute(sql, schema=schema, tables=tables)
+ self.assertEqual(result.columns, tuple(cols))
+ self.assertEqual(set(result.rows), set(rows))
+ else:
+ with self.assertRaises(ExecuteError) as ctx:
+ execute(sql, schema=schema, tables=tables)
+ self.assertIsInstance(ctx.exception.__cause__, rows)
def test_execute_catalog_db_table(self):
tables = {
@@ -632,6 +668,10 @@ class TestExecutor(unittest.TestCase):
("DATEDIFF('2022-01-03'::date, '2022-01-01'::TIMESTAMP::DATE)", 2),
("TRIM(' foo ')", "foo"),
("TRIM('afoob', 'ab')", "foo"),
+ ("ARRAY_JOIN(['foo', 'bar'], ':')", "foo:bar"),
+ ("ARRAY_JOIN(['hello', null ,'world'], ' ', ',')", "hello , world"),
+ ("ARRAY_JOIN(['', null ,'world'], ' ', ',')", " , world"),
+ ("STRUCT('foo', 'bar', null, null)", {"foo": "bar"}),
]:
with self.subTest(sql):
result = execute(f"SELECT {sql}")
@@ -726,6 +766,11 @@ class TestExecutor(unittest.TestCase):
[(1, 50), (2, 45), (3, 28)],
("a", "_col_1"),
),
+ (
+ "SELECT a, ARRAY_UNIQUE_AGG(b) FROM x GROUP BY a",
+ [(1, [40, 10]), (2, [25, 20]), (3, [28])],
+ ("a", "_col_1"),
+ ),
):
with self.subTest(sql):
result = execute(sql, tables=tables)