Repository navigation
Commit 7b7429d
authored
fix: replace with empty search string should be a no-op (apache#22497)
## 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 <[email protected]>1 parent f033199 commit 7b7429d
4 files changed
Lines changed: 39 additions & 42 deletions
File tree
- datafusion
- functions
- benches
- src/string
- sqllogictest/test_files/string
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | 165 | | |
196 | 166 | | |
197 | 167 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
268 | 268 | | |
269 | 269 | | |
270 | 270 | | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
| 271 | + | |
| 272 | + | |
279 | 273 | | |
280 | 274 | | |
281 | 275 | | |
| |||
346 | 340 | | |
347 | 341 | | |
348 | 342 | | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
349 | 356 | | |
350 | 357 | | |
351 | 358 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
430 | 430 | | |
431 | 431 | | |
432 | 432 | | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
433 | 453 | | |
434 | 454 | | |
435 | 455 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
884 | 884 | | |
885 | 885 | | |
886 | 886 | | |
887 | | - | |
888 | | - | |
889 | | - | |
890 | | - | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
891 | 891 | | |
892 | 892 | | |
893 | 893 | | |
| |||
0 commit comments