Commit 8f2d058
authored
[Analytics Engine] Wire window-function support for PPL top / rare (#21593)
* [Analytics Engine] Wire window-function support for PPL top / rare
PPL `top` and `rare` lower (via `CalciteRelNodeVisitor#visitRareTopN`) to a
`LogicalProject` containing
`ROW_NUMBER() OVER (PARTITION BY ... ORDER BY ...)`. On the analytics-engine
route, `OpenSearchProjectRule.annotateExpr` treated the `RexOver` as an
ordinary `RexCall` and fell into the scalar-function viability path. That
path keys on `ScalarFunction.fromSqlOperatorWithFallback`, which returns
null for window-only aggregates like `ROW_NUMBER`, so every `top` / `rare`
query died with "No backend supports scalar function [ROW_NUMBER] among
[datafusion]" before substrait emission.
Add `EngineCapability.WINDOW` and detect `RexOver` ahead of the standard
RexCall branch in `OpenSearchProjectRule#annotateExpr`. When the child's
viable backends include a WINDOW-capable backend, wrap the call in an
`AnnotatedProjectExpression` exactly like other annotated calls — the
existing strip path's `OperatorAnnotation::unwrap` returns the original
`RexOver` unchanged, so isthmus's `RexExpressionConverter#visitOver` emits
an inline substrait `WindowFunctionInvocation` (the substrait standard
catalog already binds `ROW_NUMBER`, so DataFusion's substrait consumer
decodes it natively — no separate substrait Window rel needed).
WINDOW is intentionally coarse (one boolean per backend rather than a
per-window-function `WindowCapability`). The substrait standard catalog
already constrains which window aggregates the backend's substrait
consumer can decode; a runtime decode failure is a clearer error than a
duplicated registry split between SPI and backend. The existing
`AggregateFunction` / `AggregateCapability` model remains right for
ordinary aggregates; once a second backend with different window support
lands, or a window-only function carries a non-standard call shape,
WINDOW can be promoted to a per-function class without disturbing the
planner-side annotation flow.
Result on `CalciteTopCommandIT` / `CalciteRareCommandIT` against the
force-routed analytics-engine path:
- `CalciteTopCommandIT`: 0/6 → 5/6 (only legacy-preferred test out-of-scope)
- `CalciteRareCommandIT`: 0/5 → 3/5 (legacy-preferred + sort-tie out-of-scope)
- combined: 0/11 → 8/11
Tests added in `ProjectRuleTests`:
- `testRowNumberOverPartitionByOrderByMarksAsWindow` — happy path
- `testRowNumberWithoutWindowCapabilityErrors` — capability-gap message
names the window function
- `testStripAnnotationsPreservesRexOver` — strip path returns plain
`LogicalProject(RexOver)` so isthmus can decode it
Signed-off-by: Kai Huang <ahkcs@amazon.com>
* [QA] Add self-contained Top + Rare CommandITs
Self-contained integration tests under sandbox/qa/analytics-engine-rest
mirroring CalciteTopCommandIT / CalciteRareCommandIT (and their PPL
bases TopCommandIT / RareCommandIT) from the opensearch-project/sql
repository. Each test sends a PPL query through POST /_analytics/ppl
(exposed by test-ppl-frontend), exercising the same UnifiedQueryPlanner
→ CalciteRelNodeVisitor#visitRareTopN → ROW_NUMBER() OVER (...) →
Substrait WindowFunctionInvocation → DataFusion pipeline that this
PR enables via EngineCapability.WINDOW.
TopCommandIT (5 tests on the calcs dataset):
- testTopWithoutGroup: top str0 → 3 rows with distinct counts (deterministic)
- testTopNWithoutGroup: top 1 str0 → 1 row
- testTopNWithGroup: top 1 str3 by str0 → 3 rows (one per str0 group)
- testTopCommandUseNull: top int0 → 8 buckets (7 non-null + 1 null)
- testTopCommandUseNullFalse: top usenull=false int0 → 7 non-null buckets
RareCommandIT (4 tests):
- testRareWithoutGroup: rare str0 → 3 rows ASC by count (deterministic)
- testRareWithGroup: rare str3 by str0 → 5 distinct (str0, str3) pairs
- testRareCommandUseNull: rare int0 → 8 buckets
- testRareCommandUseNullFalse: rare usenull=false int0 → 7 non-null buckets
The legacy-preferred=false variants from CalciteTopCommandIT /
CalciteRareCommandIT are not mirrored — they require a cluster-level
PPL syntax setting toggle that the QA harness doesn't expose. The
default usenull behaviour (PPL_SYNTAX_LEGACY_PREFERRED=true) is the
production-default code path and is covered by the four usenull
variants above.
All 9 pass against the QA test cluster (`./gradlew
:sandbox:qa:analytics-engine-rest:integTest --tests "*TopCommandIT"
--tests "*RareCommandIT"`).
Signed-off-by: Kai Huang <ahkcs@amazon.com>
---------
Signed-off-by: Kai Huang <ahkcs@amazon.com>1 parent bc96138 commit 8f2d058
4 files changed
Lines changed: 439 additions & 1 deletion
File tree
- sandbox
- plugins/analytics-engine/src/test/java/org/opensearch/analytics/planner
- qa/analytics-engine-rest/src/test/java/org/opensearch/analytics/qa
Lines changed: 10 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
143 | | - | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
144 | 153 | | |
145 | 154 | | |
146 | 155 | | |
| |||
Lines changed: 135 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| 17 | + | |
| 18 | + | |
16 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
17 | 23 | | |
18 | 24 | | |
19 | 25 | | |
| |||
323 | 329 | | |
324 | 330 | | |
325 | 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 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
326 | 461 | | |
327 | 462 | | |
328 | 463 | | |
| |||
Lines changed: 141 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
0 commit comments