From da8fc943704a221b86f0f6938f4131f0dd679f82 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 04:50:21 +0200 Subject: Adding upstream version 23.12.1. Signed-off-by: Daniel Baumann --- tests/dialects/test_clickhouse.py | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'tests/dialects/test_clickhouse.py') 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) -- cgit v1.2.3