Repository navigation
Commit f868d60
authored
fix: Emit LIKE the way the Substrait extension defines it (#25442)
## Which issue does this PR close?
- Closes #25368.
## Rationale for this change
`functions_string.yaml` defines one function for this, with two
arguments and an option:
```yaml
name: like
impls:
- args:
- value: "varchar<L1>"
name: "input"
- value: "varchar<L2>"
name: "match"
options:
case_sensitivity:
values: [ CASE_SENSITIVE, CASE_INSENSITIVE, CASE_INSENSITIVE_ASCII ]
return: "boolean"
```
The producer emitted three arguments, registered `ilike` for the case
insensitive form, and never set the option. Neither `ilike` nor an
escape argument appears in any extension file, in the pinned crate or
upstream.
## What changes are included in this PR?
- `make_substrait_like_expr` registers `like`, emits the two arguments
the definition takes, and sets `case_sensitivity` to `CASE_INSENSITIVE`
for `ILIKE`. A plain `LIKE` sets no option, which leaves the default.
- `LIKE ... ESCAPE` is now `not_impl_err`. There is no escape in the
definition, so the third argument only produced a call a consumer cannot
bind.
- The consumer reads `case_sensitivity`, taking the first value it
supports and refusing the ones it does not, as Substrait requires. It
still accepts the `ilike` name and the three argument form, so plans
written by an older DataFusion still load.
## What is the testing strategy for this PR?
- New producer tests: `LIKE` emits `like` with two arguments and no
option, `ILIKE` emits the `case_sensitivity` option, and an escape
character is rejected.
- `roundtrip_like` and `roundtrip_ilike` still pass, which is what
covers the consumer: with the option reading removed, `roundtrip_ilike`
fails because `ILIKE` comes back as `LIKE`. Removing the producer half
likewise fails the new producer test.
- `cargo test -p datafusion-substrait` passes and
`./ci/scripts/rust_clippy.sh` is clean.
Measured against substrait-java 0.103.0 and Spark 3.5.4, over `t(s)`
holding `abc` and `ABC`, with the #11545 URN patched and `output_type`
filled (#25049):
| plan | before | after |
| --- | --- | --- |
| `s LIKE 'a%'` | `AnalysisException: WRONG_NUM_ARGS ... requires 2
parameters but the actual number is 3` | runs, returns `abc` |
| `s ILIKE 'a%'` | `IllegalArgumentException: Unexpected scalar function
with key ilike:str_str` | runs, returns `abc` |
**The second row is a trade-off worth stating.** `ILIKE` used to fail
loudly there, and now it is accepted but answered case sensitively,
because substrait-spark does not read the option: `case_sensitivity`
appears nowhere in its sources. Substrait says a consumer that does not
recognise an option must reject the call, so that looks like a gap on
that side, and I am happy to report it there. If you would rather not
emit something a known consumer mishandles, the alternative is to reject
`ILIKE` as well until a consumer honours the option, and I will change
it.
## Are there any user-facing changes?
`LIKE` and `ILIKE` are emitted in the form the extension defines, so
consumers that bind arguments by the declaration can now read them.
`LIKE ... ESCAPE` is rejected instead of being emitted in a shape no
consumer can bind; DataFusion round trips it today only because its own
consumer reads the same private convention.
This touches `make_substrait_like_expr`, which #25367 folds into
`from_like`, so whichever lands second needs a small rebase.
---------
Co-authored-by: namanjain24-sudo <180642416+namanjain24-sudo@users.noreply.github.com>1 parent 048fc19 commit f868d60
2 files changed
Lines changed: 222 additions & 22 deletions
File tree
- datafusion/substrait/src/logical_plan
- consumer/expr
- producer/expr
Lines changed: 110 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
190 | 216 | | |
191 | 217 | | |
192 | 218 | | |
| |||
213 | 239 | | |
214 | 240 | | |
215 | 241 | | |
216 | | - | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
217 | 246 | | |
218 | 247 | | |
219 | 248 | | |
| |||
374 | 403 | | |
375 | 404 | | |
376 | 405 | | |
377 | | - | |
| 406 | + | |
378 | 407 | | |
379 | 408 | | |
380 | 409 | | |
| |||
583 | 612 | | |
584 | 613 | | |
585 | 614 | | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
586 | 694 | | |
Lines changed: 112 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
| 19 | + | |
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
25 | | - | |
| 24 | + | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
237 | 242 | | |
238 | 243 | | |
239 | 244 | | |
| |||
246 | 251 | | |
247 | 252 | | |
248 | 253 | | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
254 | 262 | | |
255 | 263 | | |
256 | 264 | | |
257 | 265 | | |
258 | 266 | | |
259 | 267 | | |
260 | 268 | | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
267 | 273 | | |
268 | 274 | | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
| 275 | + | |
273 | 276 | | |
274 | 277 | | |
275 | | - | |
| 278 | + | |
276 | 279 | | |
277 | 280 | | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
278 | 290 | | |
279 | 291 | | |
280 | 292 | | |
| |||
283 | 295 | | |
284 | 296 | | |
285 | 297 | | |
286 | | - | |
| 298 | + | |
287 | 299 | | |
288 | 300 | | |
289 | 301 | | |
| |||
438 | 450 | | |
439 | 451 | | |
440 | 452 | | |
| 453 | + | |
441 | 454 | | |
442 | 455 | | |
443 | 456 | | |
| |||
447 | 460 | | |
448 | 461 | | |
449 | 462 | | |
| 463 | + | |
450 | 464 | | |
451 | 465 | | |
452 | 466 | | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
453 | 545 | | |
454 | 546 | | |
455 | 547 | | |
| |||
0 commit comments