From d7f0758e21b5111b5327f3839c5c9f49a04d272b Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 4 Oct 2023 14:14:40 +0200 Subject: Adding upstream version 18.11.2. 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 40a270e..948c00e 100644 --- a/tests/dialects/test_clickhouse.py +++ b/tests/dialects/test_clickhouse.py @@ -24,6 +24,9 @@ class TestClickhouse(Validator): self.assertEqual(expr.sql(dialect="clickhouse"), "COUNT(x)") self.assertIsNone(expr._meta) + self.validate_identity("SELECT * FROM (SELECT a FROM b SAMPLE 0.01)") + self.validate_identity("SELECT * FROM (SELECT a FROM b SAMPLE 1 / 10 OFFSET 1 / 2)") + self.validate_identity("SELECT sum(foo * bar) FROM bla SAMPLE 10000000") self.validate_identity("CAST(x AS Nested(ID UInt32, Serial UInt32, EventTime DATETIME))") self.validate_identity("CAST(x AS Enum('hello' = 1, 'world' = 2))") self.validate_identity("CAST(x AS Enum('hello', 'world'))") @@ -82,6 +85,16 @@ class TestClickhouse(Validator): "CREATE MATERIALIZED VIEW test_view (id UInt8) TO db.table1 AS SELECT * FROM test_data" ) + self.validate_all( + "SELECT '\\0'", + read={ + "mysql": "SELECT '\0'", + }, + write={ + "clickhouse": "SELECT '\\0'", + "mysql": "SELECT '\0'", + }, + ) self.validate_all( "DATE_ADD('day', 1, x)", read={ @@ -224,6 +237,33 @@ class TestClickhouse(Validator): self.validate_identity( "SELECT s, arr_external FROM arrays_test ARRAY JOIN [1, 2, 3] AS arr_external" ) + self.validate_all( + "SELECT quantile(0.5)(a)", + read={"duckdb": "SELECT quantile(a, 0.5)"}, + write={"clickhouse": "SELECT quantile(0.5)(a)"}, + ) + self.validate_all( + "SELECT quantiles(0.5, 0.4)(a)", + read={"duckdb": "SELECT quantile(a, [0.5, 0.4])"}, + write={"clickhouse": "SELECT quantiles(0.5, 0.4)(a)"}, + ) + self.validate_all( + "SELECT quantiles(0.5)(a)", + read={"duckdb": "SELECT quantile(a, [0.5])"}, + write={"clickhouse": "SELECT quantiles(0.5)(a)"}, + ) + + self.validate_identity("SELECT isNaN(x)") + self.validate_all( + "SELECT IS_NAN(x), ISNAN(x)", + write={"clickhouse": "SELECT isNaN(x), isNaN(x)"}, + ) + + self.validate_identity("SELECT startsWith('a', 'b')") + self.validate_all( + "SELECT STARTS_WITH('a', 'b'), STARTSWITH('a', 'b')", + write={"clickhouse": "SELECT startsWith('a', 'b'), startsWith('a', 'b')"}, + ) def test_cte(self): self.validate_identity("WITH 'x' AS foo SELECT foo") @@ -304,6 +344,9 @@ class TestClickhouse(Validator): ) def test_ddl(self): + self.validate_identity( + 'CREATE TABLE data5 ("x" UInt32, "y" UInt32) ENGINE=MergeTree ORDER BY (round(y / 1000000000), cityHash64(x)) SAMPLE BY cityHash64(x)' + ) self.validate_identity( "CREATE TABLE foo (x UInt32) TTL time_column + INTERVAL '1' MONTH DELETE WHERE column = 'value'" ) -- cgit v1.2.3