Skip to content

Support negatives in split part#10780

Merged
alamb merged 4 commits intoapache:mainfrom
tshauck:support-negatives-in-split-part
Jun 3, 2024
Merged

Support negatives in split part#10780
alamb merged 4 commits intoapache:mainfrom
tshauck:support-negatives-in-split-part

Conversation

@tshauck
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@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