summaryrefslogtreecommitdiffstats
path: root/tests/dialects/test_clickhouse.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-01-23 05:06:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-01-23 05:06:10 +0000
commit258c7df9cab21a4978c100568907ac1cb7fd6ee0 (patch)
treea98c4c9fc7433833be72543de5d99d15b9927442 /tests/dialects/test_clickhouse.py
parentAdding upstream version 20.4.0. (diff)
downloadsqlglot-258c7df9cab21a4978c100568907ac1cb7fd6ee0.tar.xz
sqlglot-258c7df9cab21a4978c100568907ac1cb7fd6ee0.zip
Adding upstream version 20.9.0.upstream/20.9.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/dialects/test_clickhouse.py')
-rw-r--r--tests/dialects/test_clickhouse.py36
1 files changed, 21 insertions, 15 deletions
diff --git a/tests/dialects/test_clickhouse.py b/tests/dialects/test_clickhouse.py
index bb993b5..84903aa 100644
--- a/tests/dialects/test_clickhouse.py
+++ b/tests/dialects/test_clickhouse.py
@@ -26,6 +26,7 @@ class TestClickhouse(Validator):
self.assertEqual(expr.sql(dialect="clickhouse"), "COUNT(x)")
self.assertIsNone(expr._meta)
+ self.validate_identity("countIf(x, y)")
self.validate_identity("x = y")
self.validate_identity("x <> y")
self.validate_identity("SELECT * FROM (SELECT a FROM b SAMPLE 0.01)")
@@ -44,10 +45,10 @@ class TestClickhouse(Validator):
self.validate_identity("ATTACH DATABASE DEFAULT ENGINE = ORDINARY")
self.validate_identity("CAST(['hello'], 'Array(Enum8(''hello'' = 1))')")
self.validate_identity("SELECT x, COUNT() FROM y GROUP BY x WITH TOTALS")
- self.validate_identity("SELECT INTERVAL t.days day")
+ self.validate_identity("SELECT INTERVAL t.days DAY")
self.validate_identity("SELECT match('abc', '([a-z]+)')")
self.validate_identity("dictGet(x, 'y')")
- self.validate_identity("SELECT * FROM final")
+ self.validate_identity("WITH final AS (SELECT 1) SELECT * FROM final")
self.validate_identity("SELECT * FROM x FINAL")
self.validate_identity("SELECT * FROM x AS y FINAL")
self.validate_identity("'a' IN mapKeys(map('a', 1, 'b', 2))")
@@ -60,6 +61,9 @@ class TestClickhouse(Validator):
self.validate_identity("SELECT * FROM foo GLOBAL LEFT ANY JOIN bla")
self.validate_identity("SELECT quantile(0.5)(a)")
self.validate_identity("SELECT quantiles(0.5)(a) AS x FROM t")
+ self.validate_identity("SELECT quantilesIf(0.5)(a, a > 1) AS x FROM t")
+ self.validate_identity("SELECT quantileState(0.5)(a) AS x FROM t")
+ self.validate_identity("SELECT deltaSumMerge(a) AS x FROM t")
self.validate_identity("SELECT quantiles(0.1, 0.2, 0.3)(a)")
self.validate_identity("SELECT quantileTiming(0.5)(RANGE(100))")
self.validate_identity("SELECT histogram(5)(a)")
@@ -132,7 +136,7 @@ class TestClickhouse(Validator):
},
)
self.validate_all(
- "SELECT CAST('2020-01-01' AS TIMESTAMP) + INTERVAL '500' microsecond",
+ "SELECT CAST('2020-01-01' AS TIMESTAMP) + INTERVAL '500' MICROSECOND",
read={
"duckdb": "SELECT TIMESTAMP '2020-01-01' + INTERVAL '500 us'",
"postgres": "SELECT TIMESTAMP '2020-01-01' + INTERVAL '500 us'",
@@ -175,27 +179,27 @@ class TestClickhouse(Validator):
},
)
self.validate_all(
- "DATE_ADD('day', 1, x)",
+ "DATE_ADD(DAY, 1, x)",
read={
- "clickhouse": "dateAdd(day, 1, x)",
- "presto": "DATE_ADD('day', 1, x)",
+ "clickhouse": "dateAdd(DAY, 1, x)",
+ "presto": "DATE_ADD('DAY', 1, x)",
},
write={
- "clickhouse": "DATE_ADD('day', 1, x)",
- "presto": "DATE_ADD('day', 1, x)",
- "": "DATE_ADD(x, 1, 'day')",
+ "clickhouse": "DATE_ADD(DAY, 1, x)",
+ "presto": "DATE_ADD('DAY', 1, x)",
+ "": "DATE_ADD(x, 1, 'DAY')",
},
)
self.validate_all(
- "DATE_DIFF('day', a, b)",
+ "DATE_DIFF(DAY, a, b)",
read={
- "clickhouse": "dateDiff('day', a, b)",
- "presto": "DATE_DIFF('day', a, b)",
+ "clickhouse": "dateDiff(DAY, a, b)",
+ "presto": "DATE_DIFF('DAY', a, b)",
},
write={
- "clickhouse": "DATE_DIFF('day', a, b)",
- "presto": "DATE_DIFF('day', a, b)",
- "": "DATEDIFF(b, a, day)",
+ "clickhouse": "DATE_DIFF(DAY, a, b)",
+ "presto": "DATE_DIFF('DAY', a, b)",
+ "": "DATEDIFF(b, a, DAY)",
},
)
self.validate_all(
@@ -722,3 +726,5 @@ LIFETIME(MIN 0 MAX 0)""",
},
pretty=True,
)
+ self.validate_identity("""CREATE TABLE ip_data (ip4 IPv4, ip6 IPv6) ENGINE=TinyLog()""")
+ self.validate_identity("""CREATE TABLE dates (dt1 Date32) ENGINE=TinyLog()""")