Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for more slicing cases with SUBSTR #260

Open
knassre-bodo opened this issue Feb 12, 2025 · 0 comments
Open

Add support for more slicing cases with SUBSTR #260

knassre-bodo opened this issue Feb 12, 2025 · 0 comments
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

Comments

@knassre-bodo
Copy link
Contributor

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 in convert_slice to handle the following additional cases:

  1. s[-n:] -> SUBSTR(s, -n)
  2. s[-n:-m] -> SUBSTR(s, -n, n-m))
  3. 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:

  • The expression being sliced (s) must be a PyDough term (rather than a string literal)
  • The step (e.g. c in s[a:b:c] must be 1 or must be absent
  • The start/stop/step must all be litearls
@knassre-bodo knassre-bodo added 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 labels Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

1 participant