Add support for more slicing cases with SUBSTR #260
Labels
documentation
Improvements or additions to documentation
effort - low
quick & simple issue
enhancement
New feature or request
extensibility
Increasing situations in which PyDough works
user feature
Adding a new user-facing feature/functionality
Currently, PyDough only allows string slicing in cases where the step is absent (or 1), and the start/stop are both non-negative (or absent), by translating to
SUBSTR
. However,SUBSTR
has support for negatives, which we should also support. This means we can expand the conversion logic inconvert_slice
to handle the following additional cases:s[-n:]
->SUBSTR(s, -n)
s[-n:-m]
->SUBSTR(s, -n, n-m))
s[:-n]
->SUBSTR(s, 1, LENGTH(s) -n)
If the dialect does not allow negative indices (like default ANSI), can change it so
LENGTH(s) - n
is always used for the second argument in the first 2 cases. This is viable because currently we require the slicing indices to be integer literals.These expansions should all be tested, and should be noted in the function list documentation (which currently specifies the restricted semantics). The only restriction on slicing with
s[...]
syntax should now be that:s
) must be a PyDough term (rather than a string literal)c
ins[a:b:c]
must be 1 or must be absentThe text was updated successfully, but these errors were encountered: