From 8fe30fd23dc37ec3516e530a86d1c4b604e71241 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 10 Dec 2023 11:46:01 +0100 Subject: Merging upstream version 20.1.0. Signed-off-by: Daniel Baumann --- tests/test_executor.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) (limited to 'tests/test_executor.py') 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) -- cgit v1.2.3