summaryrefslogtreecommitdiffstats
path: root/tests/dialects/test_clickhouse.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 02:50:21 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 02:50:21 +0000
commitda8fc943704a221b86f0f6938f4131f0dd679f82 (patch)
treebef7144499ea444319403ba8dbf68480ae3a4e39 /tests/dialects/test_clickhouse.py
parentAdding upstream version 23.10.0. (diff)
downloadsqlglot-da8fc943704a221b86f0f6938f4131f0dd679f82.tar.xz
sqlglot-da8fc943704a221b86f0f6938f4131f0dd679f82.zip
Adding upstream version 23.12.1.upstream/23.12.1
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.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)