Commit a7a1d9a
committed
Fix ClassCastException in PPL multisearch on indexes with @timestamp alias field
Fixes #5533.
When `@timestamp` is defined as a field-type alias in the index mapping,
multisearch queries threw:
ClassCastException: RelCompositeTrait cannot be cast to RelCollation
Root cause: `reIndexCollations()` in `CalciteLogicalIndexScan` and
`pushDownSort()` in `AbstractCalciteIndexScan` both called
`RelTraitSet.plus()` to update the collation trait on a scan node.
`plus()` *composes* traits — if the trait set already contains a
`RelCollation`, it merges the old and new collations into a
`RelCompositeTrait`. Calcite's `RelTraitSet.getCollation()` then does
an unchecked cast `(RelCollation) getTrait(...)` which fails at runtime
for `RelCompositeTrait`.
The `@timestamp` alias path specifically triggers this because
`wrapProjectForAliasFields()` adds a project on top of each sub-scan
which is later pushed back down via `pushDownProject()`.
`pushDownProject()` calls `reIndexCollations()` to remap field indices
inside an existing collation — but re-using `plus()` here composes the
existing sort collation with the re-indexed one, producing the bad
composite.
Fix: use `RelTraitSet.replace()` in both locations. `replace()`
substitutes the collation trait in-place regardless of what was there
before, which is the correct semantics for "this scan is now sorted by
these columns".
Added a regression IT (`testMultisearchWithTimestampAliasFieldDoesNotThrow`)
that runs a multisearch against `TEST_INDEX_ALIAS`, whose mapping defines
`@timestamp` as an alias for `original_date`.
Signed-off-by: Radhakrishnan Pachyappan <gingeekrishna@gmail.com>1 parent 4c4166b commit a7a1d9a
3 files changed
Lines changed: 38 additions & 2 deletions
File tree
- integ-test/src/test/java/org/opensearch/sql/calcite/remote
- opensearch/src/main/java/org/opensearch/sql/opensearch/storage/scan
Lines changed: 36 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| 35 | + | |
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
| |||
462 | 464 | | |
463 | 465 | | |
464 | 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 | + | |
465 | 501 | | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
323 | 323 | | |
324 | 324 | | |
325 | 325 | | |
326 | | - | |
| 326 | + | |
327 | 327 | | |
328 | 328 | | |
329 | 329 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
321 | 321 | | |
322 | 322 | | |
323 | 323 | | |
324 | | - | |
| 324 | + | |
325 | 325 | | |
326 | 326 | | |
327 | 327 | | |
| |||
0 commit comments