morrySnow opened a new pull request, #67818:
URL: https://github.com/apache/doris/pull/67818

   ## Problem
   
   The aggregate CASE rewrite can remove rows that carry NULL values even when 
the target aggregate preserves those values. For example, array_agg over a CASE 
expression returns the wrong array size after the rewrite filters the unmatched 
rows.
   
   ## Root cause
   
   EliminateAggCaseWhen applied the filter rewrite without checking the 
aggregate input-row semantics. The existing NullIgnoringAggregateFunction trait 
also covered only a small subset of built-in aggregate implementations, so it 
could not serve as a complete semantic guard.
   
   ## Reproduction
   
   Create a table containing at least two rows, then run:
   
       SELECT array_size(array_agg(CASE WHEN k = 1 THEN k END)) FROM t;
   
   The unmatched row contributes a NULL element to array_agg, but the old plan 
filtered that row and returned a smaller array.
   
   ## Fix
   
   Require NullIgnoringAggregateFunction before applying EliminateAggCaseWhen. 
Audit all built-in scalar aggregate implementations and attach the trait only 
to functions whose every signature ignores rows containing NULL aggregate 
arguments. Keep NULL-sensitive aggregates, including array_agg, count_by_enum, 
group_concat variants, and map_agg variants, unmarked.
   
   ## Tests
   
   - Full FE build and Checkstyle
   - eliminate_aggregate_casewhen regression suite
   - Plan and result coverage for NULL-preserving array_agg and NULL-ignoring 
collect_list and bool_or
   


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