Commit 0a4d40e
authored
Fix ClassCastException in PPL multisearch on indexes with @timestamp alias field (#5577)
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 cc65d75 commit 0a4d40e
3 files changed
Lines changed: 43 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: 41 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| 36 | + | |
34 | 37 | | |
35 | 38 | | |
36 | 39 | | |
| |||
462 | 465 | | |
463 | 466 | | |
464 | 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 | + | |
465 | 506 | | |
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