Skip to content

Commit

Permalink
feat(clickhouse): implement ArrayColumn
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored and kszucs committed May 23, 2022
1 parent 7b0a506 commit 1301f18
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 6 additions & 0 deletions ibis/backends/clickhouse/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,11 @@ def compile(translator, expr):
return compile


def _array_column(t, expr):
args = ", ".join(map(t.translate, expr.op().cols))
return f"[{args}]"


# TODO: clickhouse uses different string functions
# for ascii and utf-8 encodings,

Expand Down Expand Up @@ -762,6 +767,7 @@ def compile(translator, expr):
ops.Degrees: _unary("degrees"),
ops.Radians: _unary("radians"),
ops.Strftime: _fixed_arity("formatDateTime", 2),
ops.ArrayColumn: _array_column,
}


Expand Down
6 changes: 2 additions & 4 deletions ibis/backends/tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@
pytestmark = pytest.mark.never(["sqlite", "mysql"], reason="No array support")


@pytest.mark.notimpl(["impala", "clickhouse", "datafusion"])
@pytest.mark.notimpl(["impala", "datafusion"])
def test_array_column(backend, alltypes, df):
expr = ibis.array([alltypes['double_col'], alltypes['double_col']])
assert isinstance(expr, ir.ArrayColumn)

result = expr.execute()
expected = df.apply(
lambda row: np.array(
[row['double_col'], row['double_col']], dtype=object
),
lambda row: [row['double_col'], row['double_col']],
axis=1,
)
backend.assert_series_equal(result, expected, check_names=False)
Expand Down

0 comments on commit 1301f18

Please sign in to comment.