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.py97
1 files changed, 97 insertions, 0 deletions
diff --git a/tests/dialects/test_clickhouse.py b/tests/dialects/test_clickhouse.py
index b6a7765..f5372d9 100644
--- a/tests/dialects/test_clickhouse.py
+++ b/tests/dialects/test_clickhouse.py
@@ -39,8 +39,17 @@ class TestClickhouse(Validator):
self.validate_identity(
"CREATE TABLE test (id UInt8) ENGINE=AggregatingMergeTree() ORDER BY tuple()"
)
+ self.validate_identity(
+ "CREATE TABLE test ON CLUSTER default (id UInt8) ENGINE=AggregatingMergeTree() ORDER BY tuple()"
+ )
+ self.validate_identity(
+ "CREATE MATERIALIZED VIEW test_view ON CLUSTER cl1 (id UInt8) ENGINE=AggregatingMergeTree() ORDER BY tuple() AS SELECT * FROM test_data"
+ )
self.validate_all(
+ r"'Enum8(\'Sunday\' = 0)'", write={"clickhouse": "'Enum8(''Sunday'' = 0)'"}
+ )
+ self.validate_all(
"SELECT uniq(x) FROM (SELECT any(y) AS x FROM (SELECT 1 AS y))",
read={
"bigquery": "SELECT APPROX_COUNT_DISTINCT(x) FROM (SELECT ANY_VALUE(y) x FROM (SELECT 1 y))",
@@ -395,3 +404,91 @@ SET
},
pretty=True,
)
+ self.validate_all(
+ """
+ CREATE DICTIONARY discounts_dict (
+ advertiser_id UInt64,
+ discount_start_date Date,
+ discount_end_date Date,
+ amount Float64
+ )
+ PRIMARY KEY id
+ SOURCE(CLICKHOUSE(TABLE 'discounts'))
+ LIFETIME(MIN 1 MAX 1000)
+ LAYOUT(RANGE_HASHED(range_lookup_strategy 'max'))
+ RANGE(MIN discount_start_date MAX discount_end_date)
+ """,
+ write={
+ "clickhouse": """CREATE DICTIONARY discounts_dict (
+ advertiser_id UInt64,
+ discount_start_date DATE,
+ discount_end_date DATE,
+ amount Float64
+)
+PRIMARY KEY (id)
+SOURCE(CLICKHOUSE(
+ TABLE 'discounts'
+))
+LIFETIME(MIN 1 MAX 1000)
+LAYOUT(RANGE_HASHED(
+ range_lookup_strategy 'max'
+))
+RANGE(MIN discount_start_date MAX discount_end_date)""",
+ },
+ pretty=True,
+ )
+ self.validate_all(
+ """
+ CREATE DICTIONARY my_ip_trie_dictionary (
+ prefix String,
+ asn UInt32,
+ cca2 String DEFAULT '??'
+ )
+ PRIMARY KEY prefix
+ SOURCE(CLICKHOUSE(TABLE 'my_ip_addresses'))
+ LAYOUT(IP_TRIE)
+ LIFETIME(3600);
+ """,
+ write={
+ "clickhouse": """CREATE DICTIONARY my_ip_trie_dictionary (
+ prefix TEXT,
+ asn UInt32,
+ cca2 TEXT DEFAULT '??'
+)
+PRIMARY KEY (prefix)
+SOURCE(CLICKHOUSE(
+ TABLE 'my_ip_addresses'
+))
+LAYOUT(IP_TRIE())
+LIFETIME(MIN 0 MAX 3600)""",
+ },
+ pretty=True,
+ )
+ self.validate_all(
+ """
+ CREATE DICTIONARY polygons_test_dictionary
+ (
+ key Array(Array(Array(Tuple(Float64, Float64)))),
+ name String
+ )
+ PRIMARY KEY key
+ SOURCE(CLICKHOUSE(TABLE 'polygons_test_table'))
+ LAYOUT(POLYGON(STORE_POLYGON_KEY_COLUMN 1))
+ LIFETIME(0);
+ """,
+ write={
+ "clickhouse": """CREATE DICTIONARY polygons_test_dictionary (
+ key Array(Array(Array(Tuple(Float64, Float64)))),
+ name TEXT
+)
+PRIMARY KEY (key)
+SOURCE(CLICKHOUSE(
+ TABLE 'polygons_test_table'
+))
+LAYOUT(POLYGON(
+ STORE_POLYGON_KEY_COLUMN 1
+))
+LIFETIME(MIN 0 MAX 0)""",
+ },
+ pretty=True,
+ )