Skip to content

Commit

Permalink
bug: substr fails to compile (ibis-project#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
seibs committed Nov 22, 2021
1 parent 86594aa commit 05012d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ibis_bigquery/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def _string_substring(translator, expr):
raise ValueError("Length parameter should not be a negative value.")

base_substring = operation_registry[ops.Substring]
base_substring(translator, expr)
return base_substring(translator, expr)


def _array_literal_format(expr):
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,16 @@ def test_binary():


def test_substring():
t = ibis.table([("value", "string")], name="t")
expr = t["value"].substr(3, 1)
expected = """\
SELECT substr(`value`, 3 + 1, 1) AS `tmp`
FROM t"""
result = ibis_bigquery.compile(expr)

assert result == expected

def test_substring_neg_length():
t = ibis.table([("value", "string")], name="t")
expr = t["value"].substr(3, -1)
with pytest.raises(Exception) as exception_info:
Expand Down

0 comments on commit 05012d5

Please sign in to comment.