Skip to content

Commit

Permalink
feat(trino): implement ops.StrRight
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztof-kwitt authored and cpcloud committed Dec 24, 2022
1 parent dff14fc commit 691b39c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ibis/backends/tests/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def test_string_col_is_unicode(alltypes, df):
lambda t: t.date_string_col.right(2),
lambda t: t.date_string_col.str[-2:],
id="right",
marks=pytest.mark.notimpl(["datafusion", "trino"]),
marks=pytest.mark.notimpl(["datafusion"]),
),
param(
lambda t: t.date_string_col[1:3],
Expand Down
8 changes: 8 additions & 0 deletions ibis/backends/trino/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ def _capitalize(t, op):
)


def _string_right(t, op):
sa_arg = t.translate(op.arg)
sa_length = t.translate(op.nchars)

return sa.func.substr(sa_arg, -sa_length)


operation_registry.update(
{
# conditional expressions
Expand Down Expand Up @@ -93,6 +100,7 @@ def _capitalize(t, op):
ops.JSONGetItem: _json_get_item,
ops.Translate: fixed_arity(sa.func.translate, 3),
ops.Capitalize: _capitalize,
ops.StrRight: _string_right,
ops.Repeat: fixed_arity(
lambda value, count: sa.func.array_join(sa.func.repeat(value, count), ''), 2
),
Expand Down

0 comments on commit 691b39c

Please sign in to comment.