Skip to content

Commit

Permalink
feat(sqlite): implement string join and concat
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Mar 18, 2022
1 parent 9c58e06 commit 6f5f353
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ibis/backends/sqlite/registry.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import functools
import operator

import sqlalchemy as sa
import toolz
from multipledispatch import Dispatcher
Expand Down Expand Up @@ -282,12 +285,31 @@ def _extract_week_of_year(t, expr):
) / 7 + 1


def _string_join(t, expr):
sep, elements = expr.op().args
return functools.reduce(
operator.add,
map(t.translate, toolz.interpose(sep, elements)),
)


def _string_concat(t, expr):
# yes, `arg`. for variadic functions `arg` is the list of arguments.
#
# `args` is always the list of values of the fields declared in the
# operation
args = expr.op().arg
return functools.reduce(operator.add, map(t.translate, args))


operation_registry.update(
{
ops.Cast: _cast,
ops.Substring: _substr,
ops.StrRight: _string_right,
ops.StringFind: _string_find,
ops.StringJoin: _string_join,
ops.StringConcat: _string_concat,
ops.Least: varargs(sa.func.min),
ops.Greatest: varargs(sa.func.max),
ops.IfNull: fixed_arity(sa.func.ifnull, 2),
Expand Down

0 comments on commit 6f5f353

Please sign in to comment.