summaryrefslogtreecommitdiffstats
path: root/tests/dialects/test_clickhouse.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/dialects/test_clickhouse.py')
-rw-r--r--tests/dialects/test_clickhouse.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/dialects/test_clickhouse.py b/tests/dialects/test_clickhouse.py
index df3caaf..af552d1 100644
--- a/tests/dialects/test_clickhouse.py
+++ b/tests/dialects/test_clickhouse.py
@@ -93,6 +93,9 @@ class TestClickhouse(Validator):
self.validate_identity("""SELECT JSONExtractString('{"x": {"y": 1}}', 'x', 'y')""")
self.validate_identity("SELECT * FROM table LIMIT 1 BY a, b")
self.validate_identity("SELECT * FROM table LIMIT 2 OFFSET 1 BY a, b")
+ self.validate_identity(
+ "SELECT id, quantileGK(100, 0.95)(reading) OVER (PARTITION BY id ORDER BY id RANGE BETWEEN 30000 PRECEDING AND CURRENT ROW) AS window FROM table"
+ )
self.validate_identity(
"SELECT $1$foo$1$",
@@ -409,6 +412,19 @@ class TestClickhouse(Validator):
self.validate_identity("SELECT FORMAT")
self.validate_identity("1 AS FORMAT").assert_is(exp.Alias)
+ self.validate_identity("SELECT DATE_FORMAT(NOW(), '%Y-%m-%d', '%T')")
+ self.validate_all(
+ "SELECT DATE_FORMAT(NOW(), '%Y-%m-%d')",
+ read={
+ "clickhouse": "SELECT formatDateTime(NOW(), '%Y-%m-%d')",
+ "mysql": "SELECT DATE_FORMAT(NOW(), '%Y-%m-%d')",
+ },
+ write={
+ "clickhouse": "SELECT DATE_FORMAT(NOW(), '%Y-%m-%d')",
+ "mysql": "SELECT DATE_FORMAT(NOW(), '%Y-%m-%d')",
+ },
+ )
+
def test_cte(self):
self.validate_identity("WITH 'x' AS foo SELECT foo")
self.validate_identity("WITH ['c'] AS field_names SELECT field_names")
@@ -813,3 +829,30 @@ LIFETIME(MIN 0 MAX 0)""",
self.validate_identity(
"CREATE TABLE t1 (a String EPHEMERAL, b String EPHEMERAL func(), c String MATERIALIZED func(), d String ALIAS func()) ENGINE=TinyLog()"
)
+
+ def test_agg_functions(self):
+ def extract_agg_func(query):
+ return parse_one(query, read="clickhouse").selects[0].this
+
+ self.assertIsInstance(
+ extract_agg_func("select quantileGK(100, 0.95) OVER (PARTITION BY id) FROM table"),
+ exp.AnonymousAggFunc,
+ )
+ self.assertIsInstance(
+ extract_agg_func(
+ "select quantileGK(100, 0.95)(reading) OVER (PARTITION BY id) FROM table"
+ ),
+ exp.ParameterizedAgg,
+ )
+ self.assertIsInstance(
+ extract_agg_func("select quantileGKIf(100, 0.95) OVER (PARTITION BY id) FROM table"),
+ exp.CombinedAggFunc,
+ )
+ self.assertIsInstance(
+ extract_agg_func(
+ "select quantileGKIf(100, 0.95)(reading) OVER (PARTITION BY id) FROM table"
+ ),
+ exp.CombinedParameterizedAgg,
+ )
+
+ parse_one("foobar(x)").assert_is(exp.Anonymous)