Adding upstream version 26.8.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
4b797b16f0
commit
4c394df415
61 changed files with 43883 additions and 41898 deletions
|
@ -29,6 +29,10 @@ class TestClickhouse(Validator):
|
|||
self.assertEqual(expr.sql(dialect="clickhouse"), "COUNT(x)")
|
||||
self.assertIsNone(expr._meta)
|
||||
|
||||
self.validate_identity("SELECT 1 OR (1 = 2)")
|
||||
self.validate_identity("SELECT 1 AND (1 = 2)")
|
||||
self.validate_identity("SELECT json.a.:Int64")
|
||||
self.validate_identity("SELECT json.a.:JSON.b.:Int64")
|
||||
self.validate_identity("WITH arrayJoin([(1, [2, 3])]) AS arr SELECT arr")
|
||||
self.validate_identity("CAST(1 AS Bool)")
|
||||
self.validate_identity("SELECT toString(CHAR(104.1, 101, 108.9, 108.9, 111, 32))")
|
||||
|
@ -85,6 +89,7 @@ class TestClickhouse(Validator):
|
|||
self.validate_identity("SELECT exponentialTimeDecayedAvg(60)(a, b)")
|
||||
self.validate_identity("levenshteinDistance(col1, col2)", "editDistance(col1, col2)")
|
||||
self.validate_identity("SELECT * FROM foo WHERE x GLOBAL IN (SELECT * FROM bar)")
|
||||
self.validate_identity("SELECT * FROM foo WHERE x GLOBAL NOT IN (SELECT * FROM bar)")
|
||||
self.validate_identity("POSITION(haystack, needle)")
|
||||
self.validate_identity("POSITION(haystack, needle, position)")
|
||||
self.validate_identity("CAST(x AS DATETIME)", "CAST(x AS DateTime)")
|
||||
|
@ -158,6 +163,21 @@ class TestClickhouse(Validator):
|
|||
self.validate_identity(
|
||||
"CREATE TABLE t (foo String CODEC(LZ4HC(9), ZSTD, DELTA), size String ALIAS formatReadableSize(size_bytes), INDEX idx1 a TYPE bloom_filter(0.001) GRANULARITY 1, INDEX idx2 a TYPE set(100) GRANULARITY 2, INDEX idx3 a TYPE minmax GRANULARITY 3)"
|
||||
)
|
||||
self.validate_identity(
|
||||
"SELECT generate_series FROM generate_series(0, 10) AS g(x)",
|
||||
)
|
||||
self.validate_identity(
|
||||
"SELECT and(1, 2)",
|
||||
"SELECT 1 AND 2",
|
||||
)
|
||||
self.validate_identity(
|
||||
"SELECT or(1, 2)",
|
||||
"SELECT 1 OR 2",
|
||||
)
|
||||
self.validate_identity(
|
||||
"SELECT generate_series FROM generate_series(0, 10) AS g",
|
||||
"SELECT generate_series FROM generate_series(0, 10) AS g(generate_series)",
|
||||
)
|
||||
self.validate_identity(
|
||||
"INSERT INTO tab VALUES ({'key1': 1, 'key2': 10}), ({'key1': 2, 'key2': 20}), ({'key1': 3, 'key2': 30})",
|
||||
"INSERT INTO tab VALUES (map('key1', 1, 'key2', 10)), (map('key1', 2, 'key2', 20)), (map('key1', 3, 'key2', 30))",
|
||||
|
@ -179,6 +199,13 @@ class TestClickhouse(Validator):
|
|||
"SELECT SUM(1) AS impressions FROM (SELECT ['Istanbul', 'Berlin', 'Bobruisk'] AS cities) WHERE arrayJoin(cities) IN ('Istanbul', 'Berlin')",
|
||||
)
|
||||
|
||||
self.validate_all(
|
||||
"SELECT CAST(STR_TO_DATE(SUBSTRING(a.eta, 1, 10), '%Y-%m-%d') AS Nullable(DATE))",
|
||||
read={
|
||||
"clickhouse": "SELECT CAST(STR_TO_DATE(SUBSTRING(a.eta, 1, 10), '%Y-%m-%d') AS Nullable(DATE))",
|
||||
"oracle": "SELECT to_date(substr(a.eta, 1,10), 'YYYY-MM-DD')",
|
||||
},
|
||||
)
|
||||
self.validate_all(
|
||||
"CHAR(67) || CHAR(65) || CHAR(84)",
|
||||
read={
|
||||
|
@ -201,13 +228,13 @@ class TestClickhouse(Validator):
|
|||
},
|
||||
)
|
||||
self.validate_all(
|
||||
"SELECT CAST(STR_TO_DATE('05 12 2000', '%d %m %Y') AS DATE)",
|
||||
"SELECT CAST(STR_TO_DATE('05 12 2000', '%d %m %Y') AS Nullable(DATE))",
|
||||
read={
|
||||
"clickhouse": "SELECT CAST(STR_TO_DATE('05 12 2000', '%d %m %Y') AS DATE)",
|
||||
"clickhouse": "SELECT CAST(STR_TO_DATE('05 12 2000', '%d %m %Y') AS Nullable(DATE))",
|
||||
"postgres": "SELECT TO_DATE('05 12 2000', 'DD MM YYYY')",
|
||||
},
|
||||
write={
|
||||
"clickhouse": "SELECT CAST(STR_TO_DATE('05 12 2000', '%d %m %Y') AS DATE)",
|
||||
"clickhouse": "SELECT CAST(STR_TO_DATE('05 12 2000', '%d %m %Y') AS Nullable(DATE))",
|
||||
"postgres": "SELECT CAST(CAST(TO_DATE('05 12 2000', 'DD MM YYYY') AS TIMESTAMP) AS DATE)",
|
||||
},
|
||||
)
|
||||
|
@ -226,9 +253,9 @@ class TestClickhouse(Validator):
|
|||
},
|
||||
)
|
||||
self.validate_all(
|
||||
"SELECT a, b FROM (SELECT * FROM x) AS t",
|
||||
"SELECT a, b FROM (SELECT * FROM x) AS t(a, b)",
|
||||
read={
|
||||
"clickhouse": "SELECT a, b FROM (SELECT * FROM x) AS t",
|
||||
"clickhouse": "SELECT a, b FROM (SELECT * FROM x) AS t(a, b)",
|
||||
"duckdb": "SELECT a, b FROM (SELECT * FROM x) AS t(a, b)",
|
||||
},
|
||||
)
|
||||
|
@ -557,6 +584,7 @@ class TestClickhouse(Validator):
|
|||
self.validate_identity(
|
||||
"SELECT COUNT(1) FROM table SETTINGS additional_table_filters = {'a': 'b', 'c': 'd'}"
|
||||
)
|
||||
self.validate_identity("SELECT arrayConcat([1, 2], [3, 4])")
|
||||
|
||||
def test_clickhouse_values(self):
|
||||
values = exp.select("*").from_(
|
||||
|
@ -682,6 +710,33 @@ class TestClickhouse(Validator):
|
|||
with self.subTest(f"Casting to ClickHouse {data_type}"):
|
||||
self.validate_identity(f"SELECT CAST(val AS {data_type})")
|
||||
|
||||
def test_aggregate_function_column_with_any_keyword(self):
|
||||
# Regression test for https://github.com/tobymao/sqlglot/issues/4723
|
||||
self.validate_all(
|
||||
"""
|
||||
CREATE TABLE my_db.my_table
|
||||
(
|
||||
someId UUID,
|
||||
aggregatedColumn AggregateFunction(any, String),
|
||||
aggregatedColumnWithParams AggregateFunction(any(somecolumn), String),
|
||||
)
|
||||
ENGINE = AggregatingMergeTree()
|
||||
ORDER BY (someId)
|
||||
""",
|
||||
write={
|
||||
"clickhouse": """CREATE TABLE my_db.my_table (
|
||||
someId UUID,
|
||||
aggregatedColumn AggregateFunction(any, String),
|
||||
aggregatedColumnWithParams AggregateFunction(any(somecolumn), String)
|
||||
)
|
||||
ENGINE=AggregatingMergeTree()
|
||||
ORDER BY (
|
||||
someId
|
||||
)""",
|
||||
},
|
||||
pretty=True,
|
||||
)
|
||||
|
||||
def test_ddl(self):
|
||||
db_table_expr = exp.Table(this=None, db=exp.to_identifier("foo"), catalog=None)
|
||||
create_with_cluster = exp.Create(
|
||||
|
@ -1061,13 +1116,15 @@ LIFETIME(MIN 0 MAX 0)""",
|
|||
CREATE TABLE t (
|
||||
a AggregateFunction(quantiles(0.5, 0.9), UInt64),
|
||||
b AggregateFunction(quantiles, UInt64),
|
||||
c SimpleAggregateFunction(sum, Float64)
|
||||
c SimpleAggregateFunction(sum, Float64),
|
||||
d AggregateFunction(count)
|
||||
)""",
|
||||
write={
|
||||
"clickhouse": """CREATE TABLE t (
|
||||
a AggregateFunction(quantiles(0.5, 0.9), UInt64),
|
||||
b AggregateFunction(quantiles, UInt64),
|
||||
c SimpleAggregateFunction(sum, Float64)
|
||||
c SimpleAggregateFunction(sum, Float64),
|
||||
d AggregateFunction(count)
|
||||
)"""
|
||||
},
|
||||
pretty=True,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue