codewithsruthi commented on PR #20365:
URL: https://github.com/apache/pinot/pull/20365#issuecomment-7148056770

   Thanks for the thorough testing @xiangfu0 — both points are valid 
(especially `AVG(v)` flipping from `NULL` to `0.0` on default schemas, and 
`autoRewriteAggregationType=true` disagreeing with the default path).
   
   Looking closely at the two options:
   
   - **Runtime `Sum0AggregationFunction` (current PR):** Fixes `$SUM0` globally 
at runtime, but changes `SUM`/`AVG` on all-null groups from `NULL` to `0`/`0.0` 
when `enableColumnBasedNullHandling=false` and `enableNullHandling=true` (and 
changes leaf explain / `getType()` from `SUM` to `SUM0`). Also, making 
`autoRewriteAggregationType=true` agree without introducing new 
`SUM0INT`/`SUM0LONG` wire functions would require either dropping the 
`needsSum0NullCoalesce` shortcut (breaking `SortAggregate` group trim for plain 
`SUM(v)`) or threading null-handling config into 
`PinotAggregateFunctionRewriteRule`.
   - **Planner-only fix (e.g. a Pinot variant of 
`AggregateCaseToFilterRule`):** Leaves runtime `SUM0` mapped to 
`SumAggregationFunction` and rewrites only `$SUM0(CASE WHEN c THEN x ELSE 0 
END)` to a nullable `SUM(x) FILTER (WHERE c)` wrapped in `CASE(IS NOT 
NULL(sum), sum, 0)` (nullable so Calcite's `RexSimplify` won't fold away `IS 
NOT NULL`). This preserves `NULL` for `SUM`/`AVG` (and explicit `SUM(...) 
FILTER`) on default schemas, avoids redundant `CASE` wrappers on normal 
`SUM(col)` when `enableColumnBasedNullHandling=true`, keeps 
`autoRewriteAggregationType` and `SortAggregate` group trim consistent, leaves 
Star-Tree / leaf explain / `AggregationFunctionType.SUM` untouched, and takes 
effect as soon as brokers are upgraded. (The trade-off is that runtime `SUM0` 
itself still returns `NULL` on empty input if other rules like opt-in 
`AggregateJoinTransposeExtended` emit ungrouped `$SUM0`.)
   
   @gortiz @Jackie-Jiang — how would you like to handle the default 
(`enableColumnBasedNullHandling=false` + `enableNullHandling=true`) case? 
Should we switch to the planner-only fix to preserve `NULL` there, or keep the 
runtime `Sum0AggregationFunction` change with `backward-incompat`?


-- 
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]

Reply via email to