Indian-boult opened a new issue, #20328:
URL: https://github.com/apache/pinot/issues/20328

   In the multi-stage engine, `SUM(DISTINCT x)` returns `SUM(x)`, and 
`AVG(DISTINCT x)` returns `SUM(x)` divided by `COUNT(DISTINCT x)`. The DISTINCT 
keyword is dropped with no error, so the query returns a wrong number. The 
single-stage engine handles both by rewriting them to `DISTINCTSUM` and 
`DISTINCTAVG`.
   
   With `int_col` values 2, 2, 3, 100, 101, 150 and 175
   
       SELECT SUM(DISTINCT int_col), AVG(DISTINCT int_col) FROM tbl
   
   returns `533, 88.83` on master. The correct result is `531, 88.5`. The same 
happens with GROUP BY and with `usePhysicalOptimizer=true`.
   
   `PinotAggregateExchangeNodeInsertRule.buildAggCall` and its copy in 
`AggregatePushdownRule.buildAggCall` handle `isDistinct()` only for COUNT, 
LISTAGG and ARRAY_AGG, and then build the new call with the distinct flag set 
to false. By then `PinotAggregateReduceFunctionsRule` has turned `SUM(DISTINCT 
x)` into `$SUM0(DISTINCT x)` and `AVG(DISTINCT x)` into `$SUM0(DISTINCT x) / 
COUNT(DISTINCT x)`. COUNT keeps its DISTINCT through `DISTINCTCOUNT`, but 
`$SUM0` loses it.
   


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