This repository was archived by the owner on Mar 29, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -274,6 +274,16 @@ def _string_right(translator, expr):
274274 )
275275
276276
277+ def _string_substring (translator , expr ):
278+ op = expr .op ()
279+ arg , start , length = op .args
280+ if length .op ().value < 0 :
281+ raise ValueError ('Length parameter should not be a negative value.' )
282+
283+ base_substring = operation_registry [ops .Substring ]
284+ base_substring (translator , expr )
285+
286+
277287def _array_literal_format (expr ):
278288 return str (list (expr .op ().value ))
279289
@@ -418,6 +428,7 @@ def _formatter(translator, expr):
418428 ops .StringJoin : _string_join ,
419429 ops .StringAscii : _string_ascii ,
420430 ops .StringFind : _string_find ,
431+ ops .Substring : _string_substring ,
421432 ops .StrRight : _string_right ,
422433 ops .Repeat : fixed_arity ('REPEAT' , 2 ),
423434 ops .RegexSearch : _regex_search ,
Original file line number Diff line number Diff line change @@ -258,6 +258,16 @@ def test_binary():
258258 assert result == expected
259259
260260
261+ def test_substring ():
262+ t = ibis .table ([('value' , 'string' )], name = 't' )
263+ expr = t ["value" ].substr (3 , - 1 )
264+ with pytest .raises (Exception ) as exception_info :
265+ ibis_bigquery .compile (expr )
266+
267+ expected = 'Length parameter should not be a negative value.'
268+ assert str (exception_info .value ) == expected
269+
270+
261271def test_bucket ():
262272 t = ibis .table ([('value' , 'double' )], name = 't' )
263273 buckets = [0 , 1 , 3 ]
You can’t perform that action at this time.
0 commit comments