Skip to content

Commit

Permalink
fix(clickhouse): make sure that array1.union(array2) null handling …
Browse files Browse the repository at this point in the history
…matches across backends
  • Loading branch information
cpcloud committed Aug 5, 2023
1 parent 849dea4 commit 8d42794
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ibis/backends/clickhouse/compiler/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,6 @@ def formatter(op, **kw):
ops.BitwiseLeftShift: "bitShiftLeft",
ops.BitwiseRightShift: "bitShiftRight",
ops.BitwiseNot: "bitNot",
ops.ArrayDistinct: "arrayDistinct",
ops.ArraySort: "arraySort",
ops.ArrayContains: "has",
ops.FirstValue: "first_value",
Expand All @@ -1116,6 +1115,13 @@ def _fmt(op, _name: str = _name, **kw):
del _fmt, _name, _op


@translate_val.register(ops.ArrayDistinct)
def _array_distinct(op, **kw):
arg = translate_val(op.arg, **kw)
null_element = f"if(countEqual({arg}, NULL) > 0, [NULL], [])"
return f"arrayConcat(arrayDistinct({arg}), {null_element})"


@translate_val.register(ops.ExtractMicrosecond)
def _extract_microsecond(op, **kw):
arg = translate_val(op.arg, **kw)
Expand Down
5 changes: 5 additions & 0 deletions ibis/backends/tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,11 @@ def test_array_remove(backend, con):
raises=com.IbisTypeError,
reason="argument passes none of the following rules:....",
)
@pytest.mark.notyet(
["clickhouse"],
raises=TypeError,
reason="clickhouse doesn't support nullable array types",
)
def test_array_unique(backend, con):
t = ibis.memtable({"a": [[1, 3, 3], [], [42, 42], [], [None], None]})
expr = t.a.unique()
Expand Down

0 comments on commit 8d42794

Please sign in to comment.