From 77a8eb9baa2a9061d3b91c10a176648610e53b29 Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Tue, 15 Mar 2022 11:54:58 -0400 Subject: [PATCH] feat(mysql): move string join impl up to alchemy for mysql --- ibis/backends/base/sql/alchemy/registry.py | 6 ++++++ ibis/backends/postgres/registry.py | 6 ------ ibis/backends/tests/test_string.py | 19 ++++++++++++++++++- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/ibis/backends/base/sql/alchemy/registry.py b/ibis/backends/base/sql/alchemy/registry.py index 27419d144eb7..71377c42580d 100644 --- a/ibis/backends/base/sql/alchemy/registry.py +++ b/ibis/backends/base/sql/alchemy/registry.py @@ -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), @@ -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"), diff --git a/ibis/backends/postgres/registry.py b/ibis/backends/postgres/registry.py index 3576f8abb56f..08a6cedb7cee 100644 --- a/ibis/backends/postgres/registry.py +++ b/ibis/backends/postgres/registry.py @@ -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() @@ -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, diff --git a/ibis/backends/tests/test_string.py b/ibis/backends/tests/test_string.py index 35d6eeb2d96c..de1d0dc66827 100644 --- a/ibis/backends/tests/test_string.py +++ b/ibis/backends/tests/test_string.py @@ -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"]), ), ], )