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

Support negatives in split part #10780

Merged
merged 4 commits into from
Jun 3, 2024

Conversation

tshauck
Copy link
Contributor

@tshauck tshauck commented Jun 3, 2024

Which issue does this PR close?

Closes #10761

Rationale for this change

Postgres at least supports negative index in split_part. It'd be nice to for datafusion to similarly, since split_part(..., ..., -1) is not unheard of.

What changes are included in this PR?

Updated code and tests.

Are these changes tested?

Yes, added new sqllogictests and updated exists unittests.

Are there any user-facing changes?

User queries which may've failed no longer will.

@github-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label Jun 3, 2024
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @tshauck -- looks good to me

let len = split_string.len();

let index = match n.cmp(&0) {
std::cmp::Ordering::Less => len as i64 + n,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so negative parts mean "index from end" rather than index from beginning? Makes sense to me.

@alamb alamb merged commit 180f3e8 into apache:main Jun 3, 2024
23 checks passed
@tshauck tshauck deleted the support-negatives-in-split-part branch June 3, 2024 18:51
findepi pushed a commit to findepi/datafusion that referenced this pull request Jul 16, 2024
* impv: support negative indexes for split_part

* tests: update unittests in func

* tests: add out of bounds negative test

* style: fix clippy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update split_part to support negative indexes vs failing
2 participants