summaryrefslogtreecommitdiffstats
path: root/tests/test_transpile.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_transpile.py')
-rw-r--r--tests/test_transpile.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/tests/test_transpile.py b/tests/test_transpile.py
index 7bf53e5..9253ded 100644
--- a/tests/test_transpile.py
+++ b/tests/test_transpile.py
@@ -28,7 +28,7 @@ class TestTranspile(unittest.TestCase):
self.assertEqual(transpile("SELECT 1 current_datetime")[0], "SELECT 1 AS current_datetime")
self.assertEqual(transpile("SELECT 1 row")[0], "SELECT 1 AS row")
- for key in ("union", "filter", "over", "from", "join"):
+ for key in ("union", "over", "from", "join"):
with self.subTest(f"alias {key}"):
self.validate(f"SELECT x AS {key}", f"SELECT x AS {key}")
self.validate(f'SELECT x "{key}"', f'SELECT x AS "{key}"')
@@ -263,6 +263,25 @@ FROM bar /* comment 5 */, tbl /* comment 6 */""",
"WITH a AS (SELECT 1), WITH b AS (SELECT 2) SELECT *",
"WITH a AS (SELECT 1), b AS (SELECT 2) SELECT *",
)
+ self.validate(
+ "WITH A(filter) AS (VALUES 1, 2, 3) SELECT * FROM A WHERE filter >= 2",
+ "WITH A(filter) AS (VALUES (1), (2), (3)) SELECT * FROM A WHERE filter >= 2",
+ )
+
+ def test_alter(self):
+ self.validate(
+ "ALTER TABLE integers ADD k INTEGER",
+ "ALTER TABLE integers ADD COLUMN k INT",
+ )
+ self.validate("ALTER TABLE integers DROP k", "ALTER TABLE integers DROP COLUMN k")
+ self.validate(
+ "ALTER TABLE integers ALTER i SET DATA TYPE VARCHAR",
+ "ALTER TABLE integers ALTER COLUMN i TYPE VARCHAR",
+ )
+ self.validate(
+ "ALTER TABLE integers ALTER i TYPE VARCHAR COLLATE foo USING bar",
+ "ALTER TABLE integers ALTER COLUMN i TYPE VARCHAR COLLATE foo USING bar",
+ )
def test_time(self):
self.validate("TIMESTAMP '2020-01-01'", "CAST('2020-01-01' AS TIMESTAMP)")
@@ -403,6 +422,14 @@ FROM bar /* comment 5 */, tbl /* comment 6 */""",
with self.subTest(sql):
self.assertEqual(transpile(sql)[0], sql.strip())
+ def test_normalize_name(self):
+ self.assertEqual(
+ transpile("cardinality(x)", read="presto", write="presto", normalize_functions="lower")[
+ 0
+ ],
+ "cardinality(x)",
+ )
+
def test_partial(self):
for sql in load_sql_fixtures("partial.sql"):
with self.subTest(sql):