summaryrefslogtreecommitdiffstats
path: root/sqlglot/dialects/clickhouse.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-10-26 17:21:54 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-10-26 17:21:54 +0000
commitc03ba18c491e52cc85d8aae1825dd9e0b4f75e32 (patch)
treef76d58b50900be4bfd2dc15f0ec38d1a70d8417b /sqlglot/dialects/clickhouse.py
parentReleasing debian version 18.13.0-1. (diff)
downloadsqlglot-c03ba18c491e52cc85d8aae1825dd9e0b4f75e32.tar.xz
sqlglot-c03ba18c491e52cc85d8aae1825dd9e0b4f75e32.zip
Merging upstream version 18.17.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/dialects/clickhouse.py')
-rw-r--r--sqlglot/dialects/clickhouse.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/sqlglot/dialects/clickhouse.py b/sqlglot/dialects/clickhouse.py
index e9d9326..30f728c 100644
--- a/sqlglot/dialects/clickhouse.py
+++ b/sqlglot/dialects/clickhouse.py
@@ -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.