Skip to content

fix: handle empty delimiter in split_part (closes #20503) - #20542

Merged
alamb merged 2 commits into
apache:mainfrom
gferrate:fix/20503-split-part-empty-delimiter
Feb 26, 2026
Merged

alamb merged 2 commits into
apache:mainfrom
gferrate:fix/20503-split-part-empty-delimiter

Conversation

@gferrate

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

split_part did not handle empty delimiters in a PostgreSQL-compatible way (split("") in Rust creates leading/trailing empty fields).
This could return unexpected results for positions like 1 / -1 and out-of-range values.
This PR aligns behavior with Postgres semantics for empty delimiters.

What changes are included in this PR?

Small change in how we treat the 1, -1

Are these changes tested?

Indeed!

Are there any user-facing changes?

Yes, behavior is now more consistent with PostgreSQL for split_part(str, '', n).
No API changes.

@github-actions github-actions Bot added the functions Changes to functions implementation label Feb 25, 2026

@LiaCastaneda LiaCastaneda left a comment

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.

This lgtm 👍 thanks!

Utf8,
StringArray
);
// Edge cases with delimiters

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.

wdyt about adding a couple of test cases for these edge cases in the sqllogic tests too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added!

@github-actions github-actions Bot added the sqllogictest SQL Logic Tests (.slt) label Feb 25, 2026

@gabotechs gabotechs left a comment

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.

Thanks @gferrate!

@alamb
alamb added this pull request to the merge queue Feb 26, 2026
@alamb

alamb commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Thank you @gferrate and @gabotechs

Merged via the queue into apache:main with commit 3ab1301 Feb 26, 2026
28 checks passed
LiaCastaneda pushed a commit to DataDog/datafusion that referenced this pull request Mar 3, 2026
…he#20542)

- Closes apache#20503

`split_part` did not handle empty delimiters in a PostgreSQL-compatible
way (`split("")` in Rust creates leading/trailing empty fields).
This could return unexpected results for positions like `1` / `-1` and
out-of-range values.
This PR aligns behavior with Postgres semantics for empty delimiters.

Small change in how we treat the 1, -1

Indeed!

Yes, behavior is now more consistent with PostgreSQL for
`split_part(str, '', n)`.
No API changes.

(cherry picked from commit 3ab1301)
LiaCastaneda pushed a commit to DataDog/datafusion that referenced this pull request Mar 3, 2026
…he#20542)

- Closes apache#20503

`split_part` did not handle empty delimiters in a PostgreSQL-compatible
way (`split("")` in Rust creates leading/trailing empty fields).
This could return unexpected results for positions like `1` / `-1` and
out-of-range values.
This PR aligns behavior with Postgres semantics for empty delimiters.

Small change in how we treat the 1, -1

Indeed!

Yes, behavior is now more consistent with PostgreSQL for
`split_part(str, '', n)`.
No API changes.

(cherry picked from commit 3ab1301)
LiaCastaneda added a commit to DataDog/datafusion that referenced this pull request Mar 3, 2026
…he#20542) (#88)

- Closes apache#20503

`split_part` did not handle empty delimiters in a PostgreSQL-compatible
way (`split("")` in Rust creates leading/trailing empty fields).
This could return unexpected results for positions like `1` / `-1` and
out-of-range values.
This PR aligns behavior with Postgres semantics for empty delimiters.

Small change in how we treat the 1, -1

Indeed!

Yes, behavior is now more consistent with PostgreSQL for
`split_part(str, '', n)`.
No API changes.

(cherry picked from commit 3ab1301)

Co-authored-by: Gabriel Ferraté <gabriel.ferrate@datadoghq.com>
de-bgunter pushed a commit to de-bgunter/datafusion that referenced this pull request Mar 24, 2026
…he#20542)

## Which issue does this PR close?

- Closes apache#20503 

## Rationale for this change

`split_part` did not handle empty delimiters in a PostgreSQL-compatible
way (`split("")` in Rust creates leading/trailing empty fields).
This could return unexpected results for positions like `1` / `-1` and
out-of-range values.
This PR aligns behavior with Postgres semantics for empty delimiters.

## What changes are included in this PR?

Small change in how we treat the 1, -1

## Are these changes tested?

Indeed!

## Are there any user-facing changes?

Yes, behavior is now more consistent with PostgreSQL for
`split_part(str, '', n)`.
No API changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

split_part function returning wrong results

4 participants