Commit e8678df
committed
Make addcoltotals/addtotals summary row backend-deterministic
addcoltotals (and addtotals with col=true) lowers to UNION ALL(data,
single SUM row). SQL UNION ALL has no ordering guarantee: the v2 engine
preserves input order incidentally, but the DataFusion backend on the
analytics-engine route does not, so the summary row landed in a
non-deterministic position. The command contract and user docs require the
summary row to be last.
Separately, the synthesized column for a new `labelfield` was typed as a
bounded VARCHAR(n), which renders as a Substrait VarChar(n) literal that the
DataFusion substrait consumer rejects ("Unsupported literal_type: VarChar").
Both fixes are in CalciteRelNodeVisitor.buildAddRowTotalAggregate:
- Tag each union branch with a constant ordering key (0 = data rows,
1 = summary row), sort on it, then drop the helper column, so the summary
row is deterministically last regardless of backend. Reuses the existing
streamstats sort-then-projectExcept idiom; adds PlanUtils constant
ORDER_COLUMN_FOR_ADDCOLTOTALS.
- Type the synthesized label column as an unbounded VARCHAR, matching how
OpenSearchTypeFactory maps STRING fields.
Regenerated the affected CalcitePPLAddColTotalsTest / CalcitePPLAddTotalsTest
plan and Spark-SQL expectations and the explain_add_col_totals /
explain_add_totals YAML plans; result rows are unchanged.
Signed-off-by: Kai Huang <ahkcs@amazon.com>1 parent bcbbc59 commit e8678df
6 files changed
Lines changed: 271 additions & 166 deletions
File tree
- core/src/main/java/org/opensearch/sql/calcite
- utils
- integ-test/src/test/resources/expectedOutput/calcite
- ppl/src/test/java/org/opensearch/sql/ppl/calcite
Lines changed: 21 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
3370 | 3371 | | |
3371 | 3372 | | |
3372 | 3373 | | |
3373 | | - | |
3374 | | - | |
3375 | | - | |
3376 | | - | |
3377 | 3374 | | |
| 3375 | + | |
| 3376 | + | |
| 3377 | + | |
3378 | 3378 | | |
3379 | | - | |
| 3379 | + | |
3380 | 3380 | | |
3381 | 3381 | | |
3382 | 3382 | | |
| |||
3483 | 3483 | | |
3484 | 3484 | | |
3485 | 3485 | | |
3486 | | - | |
| 3486 | + | |
| 3487 | + | |
| 3488 | + | |
| 3489 | + | |
| 3490 | + | |
3487 | 3491 | | |
| 3492 | + | |
| 3493 | + | |
| 3494 | + | |
3488 | 3495 | | |
3489 | | - | |
| 3496 | + | |
| 3497 | + | |
| 3498 | + | |
| 3499 | + | |
| 3500 | + | |
| 3501 | + | |
| 3502 | + | |
| 3503 | + | |
3490 | 3504 | | |
3491 | 3505 | | |
3492 | 3506 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
93 | 99 | | |
94 | 100 | | |
95 | 101 | | |
| |||
Lines changed: 15 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
10 | 8 | | |
11 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
12 | 14 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
Lines changed: 16 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
14 | 15 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
0 commit comments