diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-08 08:11:53 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-08 08:12:02 +0000 |
commit | 8d36f5966675e23bee7026ba37ae0647fbf47300 (patch) | |
tree | df4227bbb3b07cb70df87237bcff03c8efd7822d /tests/test_transpile.py | |
parent | Releasing debian version 22.2.0-1. (diff) | |
download | sqlglot-8d36f5966675e23bee7026ba37ae0647fbf47300.tar.xz sqlglot-8d36f5966675e23bee7026ba37ae0647fbf47300.zip |
Merging upstream version 23.7.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_transpile.py')
-rw-r--r-- | tests/test_transpile.py | 68 |
1 files changed, 62 insertions, 6 deletions
diff --git a/tests/test_transpile.py b/tests/test_transpile.py index 49deda9..0c65da4 100644 --- a/tests/test_transpile.py +++ b/tests/test_transpile.py @@ -62,11 +62,29 @@ class TestTranspile(unittest.TestCase): def test_some(self): self.validate( "SELECT * FROM x WHERE a = SOME (SELECT 1)", - "SELECT * FROM x WHERE a = ANY (SELECT 1)", + "SELECT * FROM x WHERE a = ANY(SELECT 1)", ) def test_leading_comma(self): self.validate( + "SELECT a, b, c FROM (SELECT a, b, c FROM t)", + "SELECT\n" + " a\n" + " , b\n" + " , c\n" + "FROM (\n" + " SELECT\n" + " a\n" + " , b\n" + " , c\n" + " FROM t\n" + ")", + leading_comma=True, + pretty=True, + pad=4, + indent=4, + ) + self.validate( "SELECT FOO, BAR, BAZ", "SELECT\n FOO\n , BAR\n , BAZ", leading_comma=True, @@ -275,7 +293,7 @@ FROM bar /* comment 5 */, tbl /* comment 6 */""", FROM b /* where */ WHERE - foo /* comment 1 */ AND bar AND bla /* comment 2 */""", + foo AND /* comment 1 */ bar AND /* comment 2 */ bla""", pretty=True, ) self.validate( @@ -428,7 +446,8 @@ FROM dw_1_dw_1_1.exactonline_2.transactionlines""", """SELECT 'hotel1' AS hotel, * -FROM dw_1_dw_1_1.exactonline_1.transactionlines /* +FROM dw_1_dw_1_1.exactonline_1.transactionlines +/* UNION ALL SELECT 'Thon Partner Hotel Jølster' AS hotel, @@ -479,6 +498,32 @@ SELECT FROM base""", pretty=True, ) + self.validate( + """-- comment +SOME_FUNC(arg IGNORE NULLS) + OVER (PARTITION BY foo ORDER BY bla) AS col""", + "SOME_FUNC(arg IGNORE NULLS) OVER (PARTITION BY foo ORDER BY bla) AS col /* comment */", + pretty=True, + ) + self.validate( + """ + SELECT * + FROM x + INNER JOIN y + -- inner join z + LEFT JOIN z using (id) + using (id) + """, + """SELECT + * +FROM x +INNER JOIN y + /* inner join z */ + LEFT JOIN z + USING (id) + USING (id)""", + pretty=True, + ) def test_types(self): self.validate("INT 1", "CAST(1 AS INT)") @@ -676,7 +721,11 @@ FROM base""", ) self.validate("STR_TO_TIME('x', 'y')", "DATE_PARSE('x', 'y')", write="presto") - self.validate("STR_TO_UNIX('x', 'y')", "TO_UNIXTIME(DATE_PARSE('x', 'y'))", write="presto") + self.validate( + "STR_TO_UNIX('x', 'y')", + "TO_UNIXTIME(COALESCE(TRY(DATE_PARSE(CAST('x' AS VARCHAR), 'y')), PARSE_DATETIME(CAST('x' AS VARCHAR), 'y')))", + write="presto", + ) self.validate("TIME_TO_STR(x, 'y')", "DATE_FORMAT(x, 'y')", write="presto") self.validate("TIME_TO_UNIX(x)", "TO_UNIXTIME(x)", write="presto") self.validate( @@ -714,7 +763,10 @@ FROM base""", self.validate("x[x - 1]", "x[x - 1]", write="presto", identity=False) self.validate( - "x[array_size(y) - 1]", "x[CARDINALITY(y) - 1 + 1]", write="presto", identity=False + "x[array_size(y) - 1]", + "x[(CARDINALITY(y) - 1) + 1]", + write="presto", + identity=False, ) self.validate("x[3 - 1]", "x[3]", write="presto", identity=False) self.validate("MAP(a, b)[0]", "MAP(a, b)[0]", write="presto", identity=False) @@ -758,7 +810,6 @@ FROM base""", "CALL catalog.system.iceberg_procedure_name(named_arg_1 => 'arg_1', named_arg_2 => 'arg_2')", "COMMENT ON ACCESS METHOD gin IS 'GIN index access method'", "CREATE OR REPLACE STAGE", - "CREATE SET GLOBAL TEMPORARY TABLE a, NO BEFORE JOURNAL, NO AFTER JOURNAL, MINIMUM DATABLOCKSIZE, BLOCKCOMPRESSION=NEVER (a INT)", "EXECUTE statement", "EXPLAIN SELECT * FROM x", "GRANT INSERT ON foo TO bla", @@ -904,3 +955,8 @@ FROM base""", with self.assertRaises(UnsupportedError) as ctx: unsupported(ErrorLevel.IMMEDIATE) self.assertEqual(str(ctx.exception).count(error), 1) + + def test_recursion(self): + sql = "1 AND 2 OR 3 AND " * 1000 + sql += "4" + self.assertEqual(len(parse_one(sql).sql()), 17001) |