diff options
Diffstat (limited to 'tests/test_executor.py')
-rw-r--r-- | tests/test_executor.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/test_executor.py b/tests/test_executor.py index 6bf7d6a..a121dea 100644 --- a/tests/test_executor.py +++ b/tests/test_executor.py @@ -58,6 +58,7 @@ class TestExecutor(unittest.TestCase): def test_py_dialect(self): self.assertEqual(Python().generate(parse_one("'x '''")), r"'x \''") + self.assertEqual(Python().generate(parse_one("MAP([1], [2])")), "MAP([1], [2])") def test_optimized_tpch(self): for i, (sql, optimized) in enumerate(self.sqls[:20], start=1): @@ -566,6 +567,7 @@ class TestExecutor(unittest.TestCase): ("IF(false, 1, 0)", 0), ("CASE WHEN 0 = 1 THEN 'foo' ELSE 'bar' END", "bar"), ("CAST('2022-01-01' AS DATE) + INTERVAL '1' DAY", date(2022, 1, 2)), + ("INTERVAL '1' week", datetime.timedelta(weeks=1)), ("1 IN (1, 2, 3)", True), ("1 IN (2, 3)", False), ("NULL IS NULL", True), @@ -592,6 +594,14 @@ class TestExecutor(unittest.TestCase): ), ("YEAR(CURRENT_DATE()) = (YEAR(CURRENT_DATE()))", True), ("YEAR(CURRENT_DATE()) <> (YEAR(CURRENT_DATE()))", False), + ("1::bool", True), + ("0::bool", False), + ("MAP(['a'], [1]).a", 1), + ("MAP()", {}), + ("STRFTIME('%j', '2023-03-23 15:00:00')", "082"), + ("STRFTIME('%j', NULL)", None), + ("DATESTRTODATE('2022-01-01')", date(2022, 1, 1)), + ("TIMESTRTOTIME('2022-01-01')", datetime.datetime(2022, 1, 1)), ]: with self.subTest(sql): result = execute(f"SELECT {sql}") @@ -599,5 +609,27 @@ class TestExecutor(unittest.TestCase): def test_case_sensitivity(self): result = execute("SELECT A AS A FROM X", tables={"x": [{"a": 1}]}) + self.assertEqual(result.columns, ("a",)) + self.assertEqual(result.rows, [(1,)]) + + result = execute('SELECT A AS "A" FROM X', tables={"x": [{"a": 1}]}) self.assertEqual(result.columns, ("A",)) self.assertEqual(result.rows, [(1,)]) + + def test_nested_table_reference(self): + tables = { + "some_catalog": { + "some_schema": { + "some_table": [ + {"id": 1, "price": 1.0}, + {"id": 2, "price": 2.0}, + {"id": 3, "price": 3.0}, + ] + } + } + } + + result = execute("SELECT * FROM some_catalog.some_schema.some_table s", tables=tables) + + self.assertEqual(result.columns, ("id", "price")) + self.assertEqual(result.rows, [(1, 1.0), (2, 2.0), (3, 3.0)]) |