Skip to content

Commit

Permalink
feat(clickhouse): implement string concat for clickhouse
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Mar 18, 2022
1 parent 77a8eb9 commit 1767205
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
7 changes: 7 additions & 0 deletions ibis/backends/clickhouse/registry.py
Expand Up @@ -551,6 +551,12 @@ def _string_join(translator, expr):
)


def _string_concat(translator, expr):
args = expr.op().arg
args_formatted = ", ".join(map(translator.translate, args))
return f"arrayStringConcat([{args_formatted}])"


def _string_like(translator, expr):
value, pattern = expr.op().args[:2]
return '{} LIKE {}'.format(
Expand Down Expand Up @@ -662,6 +668,7 @@ def _string_right(translator, expr):
ops.RStrip: _unary('trimRight'),
ops.Strip: _unary('trimBoth'),
ops.Repeat: _fixed_arity("repeat", 2),
ops.StringConcat: _string_concat,
ops.RegexSearch: _fixed_arity('match', 2),
# TODO: extractAll(haystack, pattern)[index + 1]
ops.RegexExtract: _regex_extract,
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/sqlite/registry.py
Expand Up @@ -289,7 +289,7 @@ def _string_join(t, expr):
sep, elements = expr.op().args
return functools.reduce(
operator.add,
map(t.translate, toolz.interpose(sep, elements)),
toolz.interpose(t.translate(sep), map(t.translate, elements)),
)


Expand Down
9 changes: 5 additions & 4 deletions ibis/backends/tests/test_string.py
Expand Up @@ -9,7 +9,7 @@ def is_text_type(x):
return isinstance(x, str)


def test_string_col_is_unicode(backend, alltypes, df):
def test_string_col_is_unicode(alltypes, df):
dtype = alltypes.string_col.type()
assert dtype == dt.String(nullable=dtype.nullable)
assert df.string_col.map(is_text_type).all()
Expand Down Expand Up @@ -262,24 +262,25 @@ def test_string_col_is_unicode(backend, alltypes, df):
lambda t: ibis.literal('-').join(['a', t.string_col, 'c']),
lambda t: 'a-' + t.string_col + '-c',
id='join',
marks=pytest.mark.notimpl(["datafusion"]),
),
param(
lambda t: t.string_col + t.date_string_col,
lambda t: t.string_col + t.date_string_col,
id='concat_columns',
marks=pytest.mark.notimpl(["datafusion", "clickhouse"]),
marks=pytest.mark.notimpl(["datafusion", "impala"]),
),
param(
lambda t: t.string_col + 'a',
lambda t: t.string_col + 'a',
id='concat_column_scalar',
marks=pytest.mark.notimpl(["datafusion", "clickhouse"]),
marks=pytest.mark.notimpl(["datafusion", "impala"]),
),
param(
lambda t: 'a' + t.string_col,
lambda t: 'a' + t.string_col,
id='concat_scalar_column',
marks=pytest.mark.notimpl(["datafusion", "clickhouse"]),
marks=pytest.mark.notimpl(["datafusion", "impala"]),
),
],
)
Expand Down
1 change: 0 additions & 1 deletion ibis/backends/tests/test_temporal.py
Expand Up @@ -269,7 +269,6 @@ def convert_to_offset(offset, displacement_type=displacement_type):
# TODO - DateOffset - #2553
@pytest.mark.notimpl(
[
"clickhouse",
"dask",
"datafusion",
"impala",
Expand Down

0 comments on commit 1767205

Please sign in to comment.