Skip to content

Commit

Permalink
feat(mysql): move string join impl up to alchemy for mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Mar 18, 2022
1 parent 6f5f353 commit 77a8eb9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
6 changes: 6 additions & 0 deletions ibis/backends/base/sql/alchemy/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,11 @@ def _sort_key(t, expr):
return sort_direction(t.translate(by))


def _string_join(t, expr):
sep, elements = expr.op().args
return sa.func.concat_ws(t.translate(sep), *map(t.translate, elements))


sqlalchemy_operation_registry: Dict[Any, Any] = {
ops.And: fixed_arity(sql.and_, 2),
ops.Or: fixed_arity(sql.or_, 2),
Expand Down Expand Up @@ -482,6 +487,7 @@ def _sort_key(t, expr):
ops.Uppercase: unary(sa.func.upper),
ops.StringAscii: unary(sa.func.ascii),
ops.StringLength: unary(sa.func.length),
ops.StringJoin: _string_join,
ops.StringReplace: fixed_arity(sa.func.replace, 3),
ops.StringSQLLike: functools.partial(_string_like, "like"),
ops.StringSQLILike: functools.partial(_string_like, "ilike"),
Expand Down
6 changes: 0 additions & 6 deletions ibis/backends/postgres/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,11 +596,6 @@ def _array_slice(t, expr):
return sa_arg[sa_start + 1 : sa_stop]


def _string_join(t, expr):
sep, elements = expr.op().args
return sa.func.concat_ws(t.translate(sep), *map(t.translate, elements))


def _literal(t, expr):
dtype = expr.type()
op = expr.op()
Expand Down Expand Up @@ -669,7 +664,6 @@ def _day_of_week_name(t, expr):
),
2,
),
ops.StringJoin: _string_join,
ops.FindInSet: _find_in_set,
# math
ops.Log: _log,
Expand Down
19 changes: 18 additions & 1 deletion ibis/backends/tests/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,24 @@ 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", "mysql", "sqlite"]),
),
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"]),
),
param(
lambda t: t.string_col + 'a',
lambda t: t.string_col + 'a',
id='concat_column_scalar',
marks=pytest.mark.notimpl(["datafusion", "clickhouse"]),
),
param(
lambda t: 'a' + t.string_col,
lambda t: 'a' + t.string_col,
id='concat_scalar_column',
marks=pytest.mark.notimpl(["datafusion", "clickhouse"]),
),
],
)
Expand Down

0 comments on commit 77a8eb9

Please sign in to comment.