codewithsruthi opened a new pull request, #20408:
URL: https://github.com/apache/pinot/pull/20408

   Fixes #20295
   
   ### Summary
   While direct `GROUP BY ARRAY_TO_MV(tags) HAVING ARRAY_TO_MV(tags) = 'vip'` 
already stays above `Aggregate`, three gaps remained:
   1. **Correctness bug:** Nested `ARRAY_TO_MV` group keys (e.g. 
`LOWER(ARRAY_TO_MV(strMv))`, `CAST(ARRAY_TO_MV(intMv) AS VARCHAR)`) were still 
pushed below `Aggregate`, returning extra groups from other array elements in 
matching rows.
   2. **Missed pushdown:** Mixed `HAVING` / outer `WHERE` filters like 
`ARRAY_TO_MV(tags) = 'vip' AND region = 'US'` blocked pushing even the 
independent single-value conjunct `region = 'US'`.
   3. **Missing leaf pre-filter optimization:** Positive leaf `HAVING` / outer 
`WHERE` filters on `ARRAY_TO_MV(col)` scanned and aggregated every row in the 
table without copying a sound existential MV pre-filter below the aggregate.
   
   ### Changes
   - **`ArrayToMvGroupKeys` & `PinotProjectJoinTransposeRule` 
(`pinot-query-planner`):**
     - Centralized `containsArrayToMv(RexNode)` and added 
`containsArrayToMvColumn(RelNode, int)` walking inline and stacked 
`Filter`/`Project` chains to detect bare and nested `ARRAY_TO_MV` expressions 
while keeping `detect(Aggregate)` and `isArrayToMvCall` strictly top-level.
   - **`PinotFilterAggregateTransposeRule` (`pinot-query-planner`):**
     - Replaced the all-or-nothing guard with per-conjunct splitting over 
`RelOptUtil.conjunctions(...)`: independent SV conjuncts push below `Aggregate` 
(with proper output-to-input remapping, including non-`SIMPLE` `GROUPING 
SETS`), while bare and nested MV-key conjuncts stay above `Aggregate`.
   - **`PinotMvAggregatePreFilterRule`, `QueryEnvironment`, & 
`CommonConstants.Broker.PlannerRuleNames` (`pinot-query-planner`, 
`pinot-spi`):**
     - Added `PinotMvAggregatePreFilterRule` 
(`PlannerRuleNames.MV_AGGREGATE_PRE_FILTER = "MvAggregatePreFilter"`), wired 
after the second `FILTER_PUSHDOWN_RULES` and before `PRUNE_RULES`.
     - Copies strictly sound positive existential predicates (`=`, `<`, `<=`, 
`>`, `>=`, asymmetric `BETWEEN`, positive `SEARCH` / 
`PinotSealedSearchOperator` with an O(1) `sarg.isPoints()` fast path, and 
same-key `OR` / `AND`) on bare `ARRAY_TO_MV(tableScanCol)` group keys into a 
merged leaf `Filter` directly over `TableScan` (strictly requiring `Project* -> 
Filter* -> TableScan` and inserting below `Project` so 
`AggregateProjectPullUpConstantsRule` never drops the MV key and 
`ServerPlanRequestVisitor` sees a single leaf `Filter`), while keeping the 
original post-aggregate `Filter` intact.
     - Explicitly excludes `<>`, `NOT IN`, `NOT (...)`, `IS NULL` / `IS NOT 
NULL`, `SYMMETRIC_BETWEEN`, wrapped transforms, cross-column comparisons, and 
non-scan inputs.
   - **Tests (`pinot-query-planner`, `pinot-query-runtime`):**
     - Added `PinotFilterAggregateTransposeRuleTest` and 
`PinotMvAggregatePreFilterRuleTest`, and expanded `ArrayToMvGroupKeysTest`, 
`MvAggregatePlanTest`, and `MvAggregate.json`.
   
   ### Verification
   - Planner tests (805/805 passed): `ArrayToMvGroupKeysTest` (10/10), 
`PinotFilterAggregateTransposeRuleTest` (8/8), 
`PinotMvAggregatePreFilterRuleTest` (11/11), `MvAggregatePlanTest` (19/19), 
`ResourceBasedQueryPlansTest` (full 720/720), `PinotRuleSetTest` (5/5), 
`QueryPlannerRuleOptionsTest` (32/32)
   - Runtime tests: `ServerPlanRequestVisitorMvAggregateTest` (5/5), 
`MvAggregateOperatorTest` (44/44), `ResourceBasedQueriesTest` 
(`MvAggregate.json`, 66/66 executed)
   - Integration test: `MultiStageEngineIntegrationTest` (121/121 passed)
   - Pre-commit checks (`spotless:apply`, `license:check`, `checkstyle:check`, 
compiler warnings on added lines): clean across `pinot-spi`, 
`pinot-query-planner`, `pinot-query-runtime`.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

  • [PR] Fix nested ARRAY_TO_MV gro... codewithsruthi (via GitHub) via commits

Reply via email to