fix: make replace empty search string a no-op#22357
Closed
garyconan1224 wants to merge 1 commit into
Closed
Conversation
Contributor
|
There's also #22275 for this issue, although I think this version is slightly better. |
kosiew
approved these changes
May 20, 2026
Contributor
kosiew
left a comment
There was a problem hiding this comment.
@garyconan1224
Thanks for working on this.
Looks 👍 to me
neilconway
reviewed
May 20, 2026
Contributor
neilconway
left a comment
There was a problem hiding this comment.
We should also update (or remove) the comment describing the behavior for "empty-from" in benches/replace.rs. You could argue we can now remove those benchmark cases anyway, since the empty-from behavior is now straightforward and unlikely to be a perf hotspot.
Contributor
|
@garyconan1224 could you fix the remaining CI failures? |
Contributor
|
fyi another PR was raised for this would be good to see if we can get this PR over the line, otherwise we can defer to the other PR instead |
Amogh-2404
added a commit
to Amogh-2404/datafusion
that referenced
this pull request
Jun 1, 2026
use builder.append_value(string) for the no-op instead of the append_with closure, per the suggestion from apache#22357. also drop the replace_string_empty_from benches since they were timing the old char-interleaving path this PR removes.
mkleen
pushed a commit
to mkleen/datafusion
that referenced
this pull request
Jun 4, 2026
## Which issue does this PR close? - Closes apache#22253 - Closes apache#22357 ## Rationale for this change PostgreSQL returns the input unchanged when `replace` is called with an empty `from`. DataFusion was instead inserting `to` before every character and at both ends, so `replace('abc', '', 'x')` returned `xaxbxcx`. This PR brings the behaviour in line with PostgreSQL. Part of the PG-compatibility cleanup tracked in apache#22247. ## What changes are included in this PR? - `datafusion/functions/src/string/replace.rs`: the empty-`from` branch in `apply_replace` now writes the input verbatim instead of inserting `to`. Added a `LargeUtf8` unit test for the new behaviour. - `datafusion/sqllogictest/test_files/string/string_literal.slt`: four new SLT asserts covering the `Utf8`, `Dictionary`, `Utf8View`, and `LargeUtf8` paths. - `datafusion/sqllogictest/test_files/string/string_query.slt.part`: updated four expected rows that were asserting the old buggy output. ## Are these changes tested? Yes. The unit test in `replace.rs` covers the `LargeUtf8` path, and the four new SLT asserts in `string_literal.slt` cover the remaining Arrow string encodings end-to-end. The full SLT suite passes locally. ## Are there any user-facing changes? Yes. `replace(str, '', x)` now returns `str` unchanged instead of inserting `x` between every character. This matches PostgreSQL. --------- Signed-off-by: Amogh Ramesh <ramogh2404@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Closes #22253.
Rationale for this change
PostgreSQL treats
replacewith an empty search string as a no-op. DataFusion currently inserts the replacement string around each character, soreplace('abc', '', 'x')returnsxaxbxcxinstead ofabc.What changes are included in this PR?
fromargument toreplaceis empty.Are these changes tested?
git diff --checkcargo/rustcinstalled; the added SQLLogicTest cases are intended for CI verification.