Merging upstream version 18.17.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
fdf9ca761f
commit
04c9be45a8
90 changed files with 46581 additions and 43319 deletions
|
@ -5,6 +5,7 @@ import typing as t
|
|||
from sqlglot import exp, generator, parser, tokens, transforms
|
||||
from sqlglot.dialects.dialect import (
|
||||
Dialect,
|
||||
arg_max_or_min_no_count,
|
||||
inline_array_sql,
|
||||
no_pivot_sql,
|
||||
rename_func,
|
||||
|
@ -373,8 +374,11 @@ class ClickHouse(Dialect):
|
|||
exp.Select: transforms.preprocess([transforms.eliminate_qualify]),
|
||||
exp.AnyValue: rename_func("any"),
|
||||
exp.ApproxDistinct: rename_func("uniq"),
|
||||
exp.ArgMax: arg_max_or_min_no_count("argMax"),
|
||||
exp.ArgMin: arg_max_or_min_no_count("argMin"),
|
||||
exp.Array: inline_array_sql,
|
||||
exp.CastToStrType: rename_func("CAST"),
|
||||
exp.CurrentDate: lambda self, e: self.func("CURRENT_DATE"),
|
||||
exp.DateAdd: lambda self, e: self.func(
|
||||
"DATE_ADD", exp.Literal.string(e.text("unit") or "day"), e.expression, e.this
|
||||
),
|
||||
|
@ -418,6 +422,33 @@ class ClickHouse(Dialect):
|
|||
"NAMED COLLECTION",
|
||||
}
|
||||
|
||||
def _any_to_has(
|
||||
self,
|
||||
expression: exp.EQ | exp.NEQ,
|
||||
default: t.Callable[[t.Any], str],
|
||||
prefix: str = "",
|
||||
) -> str:
|
||||
if isinstance(expression.left, exp.Any):
|
||||
arr = expression.left
|
||||
this = expression.right
|
||||
elif isinstance(expression.right, exp.Any):
|
||||
arr = expression.right
|
||||
this = expression.left
|
||||
else:
|
||||
return default(expression)
|
||||
return prefix + self.func("has", arr.this.unnest(), this)
|
||||
|
||||
def eq_sql(self, expression: exp.EQ) -> str:
|
||||
return self._any_to_has(expression, super().eq_sql)
|
||||
|
||||
def neq_sql(self, expression: exp.NEQ) -> str:
|
||||
return self._any_to_has(expression, super().neq_sql, "NOT ")
|
||||
|
||||
def regexpilike_sql(self, expression: exp.RegexpILike) -> str:
|
||||
# Manually add a flag to make the search case-insensitive
|
||||
regex = self.func("CONCAT", "'(?i)'", expression.expression)
|
||||
return f"match({self.format_args(expression.this, regex)})"
|
||||
|
||||
def datatype_sql(self, expression: exp.DataType) -> str:
|
||||
# String is the standard ClickHouse type, every other variant is just an alias.
|
||||
# Additionally, any supplied length parameter will be ignored.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue