Commit 4f6bcf5
authored
[analytics-engine] Wire FINAL aggregate filter drop and join-condition adapter dispatch (opensearch-project#21911)
* [analytics-engine] Wire FINAL aggregate filter drop and join-condition adapter dispatch
Two small fixes that together unblock CalciteTransposeCommandIT on the
analytics-engine route end-to-end. Both surface only when a single PPL
command produces (a) a non-prefix groupSet, (b) a FILTER aggCall, and
(c) a Join whose condition carries PPL UDFs — which is how PPL transpose
lowers via RelBuilder.unpivot()/pivot(). Today transpose is the only
PPL command that hits this combination, but the bugs are general.
1. DistributedAggregateRewriter.buildOne — drop filterArg on FINAL
-----------------------------------------------------------------
FINAL's input is PARTIAL output, laid out as [group keys, agg states].
The boolean column referenced by an aggCall's FILTER predicate exists
only on the ORIGINAL child input that PARTIAL consumed; PARTIAL has
already applied the filter while accumulating state. The Aggregate
constructor's `isPredicate(input, filterArg)` check then fires when it
reads filterArg=N against PARTIAL output that has fewer than N+1
columns (or whose Nth column is non-boolean).
Set filterArg = -1 (Calcite's "no FILTER" sentinel — there's no
create() overload that omits it) on the FINAL call. Semantically
correct: FILTER is a row-level gate consumed once during accumulation;
merging states never re-applies it. This generalises to multi-stage
chains (PARTIAL → PARTIAL2 → FINAL): only the first stage that
consumes raw rows keeps filterArg.
Without this fix, transpose IT fails with
`IllegalArgumentException: filter must be BOOLEAN NOT NULL` from
Aggregate.<init>:178.
2. BackendPlanAdapter — dispatch OpenSearchJoin for adapter rewrite
------------------------------------------------------------------
adaptNode() walks Filter / Project / Aggregate(FINAL) and runs each
RexNode through the backend's ScalarFunctionAdapter chain
(e.g. ToStringFunctionAdapter rewrites NUMBER_TO_STRING to a plain
CAST that isthmus understands). Calcite's FILTER_INTO_JOIN rule
inlines an outer Filter's predicate into an inner Join's condition,
so any PPL UDF that lived in the Project below the Filter rides
into the Join condition. With Join missing from adaptNode's dispatch
list, that copy of the UDF reaches isthmus unrewritten and trips
"Unable to convert call NUMBER_TO_STRING(fp64?)" in
RexExpressionConverter.
Add an OpenSearchJoin branch that runs the join's condition through
adaptRex with concatenated left+right field storage — same convention
OpenSearchJoin#getOutputFieldStorage() uses on the output side.
Verified
--------
CalciteTransposeCommandIT (with `-Dtests.analytics.parquet_indices=true`)
on 21804-merged main:
* Without these fixes: 0/5 pass (5/5 hit "filter must be BOOLEAN NOT NULL")
* With #1 only: 4/5 pass (testTransposeWithValueFieldNameCollision
hits "Unable to convert call NUMBER_TO_STRING(fp64?)")
* With #1 + #2: 5/5 pass
Signed-off-by: Songkan Tang <songkant@amazon.com>
* Read join field storage from the join node, not re-derived from children
Address review feedback (expani): use OpenSearchJoin#getOutputFieldStorage()
directly in adaptJoin instead of re-assembling it by unwrapping the children —
same result (the node derives it from left ++ right child storage, which traces
back to the FieldStorageInfo marked on the leaf OpenSearchTableScan), and
consistent with how adaptFilter/adaptProject read storage off their node.
Also drop the fieldStorage.isEmpty() short-circuit: adaptRex never indexes the
storage list (it only hands it to scalar adapters, which no-op when a ref has no
storage), so an empty list flows through harmlessly and yields the same result
as the explicit guard — matching adaptFilter, which has no such check.
BackendPlanAdapterTests 8/8 pass (incl. both join-condition tests).
Signed-off-by: Songkan Tang <songkant@amazon.com>
---------
Signed-off-by: Songkan Tang <songkant@amazon.com>1 parent 4cafb38 commit 4f6bcf5
3 files changed
Lines changed: 120 additions & 1 deletion
File tree
- sandbox/plugins/analytics-engine/src
- main/java/org/opensearch/analytics/planner/dag
- test/java/org/opensearch/analytics/planner/dag
Lines changed: 28 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
104 | 105 | | |
105 | 106 | | |
106 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
107 | 111 | | |
108 | 112 | | |
109 | 113 | | |
| |||
114 | 118 | | |
115 | 119 | | |
116 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
117 | 145 | | |
118 | 146 | | |
119 | 147 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
307 | | - | |
| 307 | + | |
308 | 308 | | |
309 | 309 | | |
310 | 310 | | |
| |||
Lines changed: 91 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| 35 | + | |
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
| |||
311 | 314 | | |
312 | 315 | | |
313 | 316 | | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
314 | 405 | | |
315 | 406 | | |
316 | 407 | | |
| |||
0 commit comments