Skip to content

Commit

Permalink
chore(deps): bump clickhouse-server version (ibis-project#9738)
Browse files Browse the repository at this point in the history
Managed to get backwards compatible code working with the latest
clickhouse-server version bump

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
  • Loading branch information
cpcloud and renovate[bot] authored Jul 31, 2024
1 parent 3bc9799 commit e27f2c9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 26 deletions.
2 changes: 1 addition & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
clickhouse:
image: clickhouse/clickhouse-server:24.6.3.70-alpine
image: clickhouse/clickhouse-server:24.7.1.2915-alpine
ports:
- 8123:8123 # http port
- 9000:9000 # native protocol port
Expand Down
40 changes: 33 additions & 7 deletions ibis/backends/sql/compilers/clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ class ClickHouseCompiler(SQLGlotCompiler):
ops.ArrayIntersect: "arrayIntersect",
ops.ArrayPosition: "indexOf",
ops.BitwiseAnd: "bitAnd",
ops.BitwiseLeftShift: "bitShiftLeft",
ops.BitwiseNot: "bitNot",
ops.BitwiseOr: "bitOr",
ops.BitwiseRightShift: "bitShiftRight",
ops.BitwiseXor: "bitXor",
ops.Capitalize: "initcap",
ops.CountDistinct: "uniq",
Expand Down Expand Up @@ -97,7 +95,6 @@ class ClickHouseCompiler(SQLGlotCompiler):
ops.Last: "anyLast",
ops.Ln: "log",
ops.Log10: "log10",
ops.MapContains: "mapContains",
ops.MapKeys: "mapKeys",
ops.MapLength: "length",
ops.MapMerge: "mapUpdate",
Expand Down Expand Up @@ -443,10 +440,8 @@ def visit_GroupConcat(self, op, *, arg, sep, where):
def visit_Cot(self, op, *, arg):
return 1.0 / self.f.tan(arg)

def visit_StructColumn(self, op, *, values, names):
# ClickHouse struct types cannot be nullable
# (non-nested fields can be nullable)
return self.cast(self.f.tuple(*values), op.dtype.copy(nullable=False))
def visit_StructColumn(self, op, *, values, **_):
return self.f.tuple(*values)

def visit_Clip(self, op, *, arg, lower, upper):
if upper is not None:
Expand Down Expand Up @@ -759,3 +754,34 @@ def visit_ArraySum(self, op, *, arg):

def visit_ArrayMean(self, op, *, arg):
return self.f.arrayReduce("avg", self._array_reduction(arg))

def _promote_bitshift_inputs(self, *, op, left, right):
# clickhouse is incredibly pedantic about types allowed in bit shifting
#
# e.g., a UInt8 cannot be bitshift by more than 8 bits, UInt16 by more
# than 16, and so on.
#
# This is why something like Ibis is necessary so that people have just
# _consistent_ things, let alone *nice* things.
left_dtype = op.left.dtype
right_dtype = op.right.dtype

if left_dtype != right_dtype:
promoted = dt.higher_precedence(left_dtype, right_dtype)
return self.cast(left, promoted), self.cast(right, promoted)
return left, right

def visit_BitwiseLeftShift(self, op, *, left, right):
return self.f.bitShiftLeft(
*self._promote_bitshift_inputs(op=op, left=left, right=right)
)

def visit_BitwiseRightShift(self, op, *, left, right):
return self.f.bitShiftRight(
*self._promote_bitshift_inputs(op=op, left=left, right=right)
)

def visit_MapContains(self, op, *, arg, key):
return self.if_(
sg.or_(arg.is_(NULL), key.is_(NULL)), NULL, self.f.mapContains(arg, key)
)
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@ WITH "t5" AS (
"t0"."field_of_study" AS "field_of_study",
arrayJoin(
[
CAST(tuple('1970-71', "t0"."1970-71") AS Tuple("years" Nullable(String), "degrees" Nullable(Int64))),
CAST(tuple('1975-76', "t0"."1975-76") AS Tuple("years" Nullable(String), "degrees" Nullable(Int64))),
CAST(tuple('1980-81', "t0"."1980-81") AS Tuple("years" Nullable(String), "degrees" Nullable(Int64))),
CAST(tuple('1985-86', "t0"."1985-86") AS Tuple("years" Nullable(String), "degrees" Nullable(Int64))),
CAST(tuple('1990-91', "t0"."1990-91") AS Tuple("years" Nullable(String), "degrees" Nullable(Int64))),
CAST(tuple('1995-96', "t0"."1995-96") AS Tuple("years" Nullable(String), "degrees" Nullable(Int64))),
CAST(tuple('2000-01', "t0"."2000-01") AS Tuple("years" Nullable(String), "degrees" Nullable(Int64))),
CAST(tuple('2005-06', "t0"."2005-06") AS Tuple("years" Nullable(String), "degrees" Nullable(Int64))),
CAST(tuple('2010-11', "t0"."2010-11") AS Tuple("years" Nullable(String), "degrees" Nullable(Int64))),
CAST(tuple('2011-12', "t0"."2011-12") AS Tuple("years" Nullable(String), "degrees" Nullable(Int64))),
CAST(tuple('2012-13', "t0"."2012-13") AS Tuple("years" Nullable(String), "degrees" Nullable(Int64))),
CAST(tuple('2013-14', "t0"."2013-14") AS Tuple("years" Nullable(String), "degrees" Nullable(Int64))),
CAST(tuple('2014-15', "t0"."2014-15") AS Tuple("years" Nullable(String), "degrees" Nullable(Int64))),
CAST(tuple('2015-16', "t0"."2015-16") AS Tuple("years" Nullable(String), "degrees" Nullable(Int64))),
CAST(tuple('2016-17', "t0"."2016-17") AS Tuple("years" Nullable(String), "degrees" Nullable(Int64))),
CAST(tuple('2017-18', "t0"."2017-18") AS Tuple("years" Nullable(String), "degrees" Nullable(Int64))),
CAST(tuple('2018-19', "t0"."2018-19") AS Tuple("years" Nullable(String), "degrees" Nullable(Int64))),
CAST(tuple('2019-20', "t0"."2019-20") AS Tuple("years" Nullable(String), "degrees" Nullable(Int64)))
tuple('1970-71', "t0"."1970-71"),
tuple('1975-76', "t0"."1975-76"),
tuple('1980-81', "t0"."1980-81"),
tuple('1985-86', "t0"."1985-86"),
tuple('1990-91', "t0"."1990-91"),
tuple('1995-96', "t0"."1995-96"),
tuple('2000-01', "t0"."2000-01"),
tuple('2005-06', "t0"."2005-06"),
tuple('2010-11', "t0"."2010-11"),
tuple('2011-12', "t0"."2011-12"),
tuple('2012-13', "t0"."2012-13"),
tuple('2013-14', "t0"."2013-14"),
tuple('2014-15', "t0"."2014-15"),
tuple('2015-16', "t0"."2015-16"),
tuple('2016-17', "t0"."2016-17"),
tuple('2017-18', "t0"."2017-18"),
tuple('2018-19', "t0"."2018-19"),
tuple('2019-20', "t0"."2019-20")
]
) AS "__pivoted__"
FROM "humanities" AS "t0"
Expand Down

0 comments on commit e27f2c9

Please sign in to comment.