Jackie-Jiang opened a new pull request, #20063:
URL: https://github.com/apache/pinot/pull/20063

   ## Summary
   
   The `is_leaf_return_final_result` aggregate hint only took effect for 
group-by queries. For an aggregation without `GROUP BY`, the planner already 
marked the LEAF and FINAL aggregates as returning final results, but:
   - The leaf server was asked for `serverReturnFinalResultKeyUnpartitioned`, 
which only applies to group-by queries, so it returned intermediate results.
   - `MultistageAggregationExecutor` ignored the flag (`TODO: Allow leaf return 
final result for non-group-by queries` in `AggregateOperator`).
   
   The leaf therefore returned intermediate results while the plan typed them 
as final, which breaks any function whose intermediate type differs from its 
final type (e.g. `COUNT(DISTINCT)`).
   
   This PR makes the hint work for aggregations without `GROUP BY`, similar to 
`serverReturnFinalResult` in the single-stage engine:
   - `ServerPlanRequestVisitor` maps the hint to `serverReturnFinalResult` when 
there is no group-by key, and keeps `serverReturnFinalResultKeyUnpartitioned` 
for group-by queries.
   - `MultistageAggregationExecutor` honors `leafReturnFinalResult`: the LEAF 
extracts final results, and the FINAL merges them with `mergeFinalResult`. When 
no row reaches the FINAL (e.g. all segments pruned), it still returns the final 
result of the empty input (`0` for `COUNT`, `null` for `SUM`).
   
   Example:
   ```sql
   SELECT /*+ aggOptions(is_leaf_return_final_result='true') */ COUNT(DISTINCT 
col)
   FROM myTable /*+ tableOptions(partition_function='hashcode', 
partition_key='col', partition_size='4') */
   ```
   
   As with group-by queries, the hint is only correct when the aggregated 
values are partitioned across the leaf stage workers.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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