Commit 8720ca7
committed
fix(opensearch): collapse 4-arg REGEXP_REPLACE_PG_4 'g' to 3-arg at script pushdown
The `feat(core)` commit on this branch lowered PPL `patterns` to a 4-arg
`REGEXP_REPLACE_PG_4(field, pattern, replacement, 'g')` so DataFusion (which
defaults to first-match-only) does global replacement on the analytics-engine
route. Calcite's enumerable runtime — which the V2 / Calcite-pushdown path uses
to compile the serialized RexCall into Janino bytecode — has no matching
`SqlFunctions.regexpReplace(String, String, String, String)` impl (only
`(String, String, String, int[, ...])` variants where the 4th arg is start
position, not a flags string). Janino codegen failed with
`No applicable constructor/method found` for the 4-arg-with-flags call shape,
breaking the patterns.md doctest (`source=apache | patterns message
method=simple_pattern mode=aggregation`).
Two complementary fixes:
1. `RexStandardizer.visitCall`: before serializing for pushdown, collapse
`REGEXP_REPLACE_PG_4(field, pattern, replacement, 'g')` to the 3-arg
`REGEXP_REPLACE_3` form. Safe because Calcite's 3-arg variant is already
replace-all (same semantics as PG_4 with `g`). Only fires when the flags
literal is exactly `"g"` so any future `i`/`m`/etc. use cases pass through
untouched.
2. `ExtendedRelJson.toOp`: pass operand count when looking up an operator on
the deserialization side so multi-arity SQL names (REGEXP_REPLACE_3 vs
REGEXP_REPLACE_PG_4 vs REGEXP_REPLACE_5 all share `name="REGEXP_REPLACE"`)
resolve to the right overload. Defensive — the standardizer fix above is
what actually unblocks the doctest, but the resolver was picking by name
alone and would have surfaced the same bug for any other overloaded
builtin.
Verified locally:
- doctest queries (`patterns ... method=simple_pattern mode=aggregation [...]`)
now return fully-tokenized output;
- `CalcitePPLDashboardPatternsIT` still 1/1 PASS;
- `CalcitePPLPatternsIT` still 10/15 with the same five known-pending failures
(LogicalCorrelate + `_ShowNumberedToken` BRAIN cases).
Signed-off-by: Kai Huang <ahkcs@amazon.com>1 parent 394cb5a commit 8720ca7
2 files changed
Lines changed: 51 additions & 2 deletions
File tree
- opensearch/src/main/java/org/opensearch/sql/opensearch/storage/serde
Lines changed: 29 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
460 | 460 | | |
461 | 461 | | |
462 | 462 | | |
463 | | - | |
| 463 | + | |
| 464 | + | |
464 | 465 | | |
465 | 466 | | |
466 | 467 | | |
| |||
553 | 554 | | |
554 | 555 | | |
555 | 556 | | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
556 | 573 | | |
557 | 574 | | |
558 | 575 | | |
| |||
566 | 583 | | |
567 | 584 | | |
568 | 585 | | |
| 586 | + | |
569 | 587 | | |
570 | | - | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
571 | 595 | | |
572 | 596 | | |
573 | 597 | | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
574 | 601 | | |
575 | 602 | | |
576 | 603 | | |
| |||
Lines changed: 22 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
73 | 74 | | |
74 | 75 | | |
75 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
76 | 98 | | |
77 | 99 | | |
78 | 100 | | |
| |||
0 commit comments