backendArchitect commented on code in PR #7795:
URL: https://github.com/apache/datafusion-comet/pull/7795#discussion_r4735694450


##########
native/core/src/execution/jni_api.rs:
##########
@@ -1054,6 +1055,13 @@ fn configure_skip_partial_aggregation(config: &mut 
SessionConfig, plan: &Operato
                         && agg.agg_exprs.iter().all(|expr| {
                             matches!(&expr.expr_struct, 
Some(AggExprStruct::Count(count))
                                 if count.children.len() == 1)
+                                // A decimal result is built as `AvgDecimal`. 
Any other result is
+                                // Comet's Float64 `Avg`, which cannot convert 
rows to states.
+                                || matches!(&expr.expr_struct, 
Some(AggExprStruct::Avg(avg))
+                                    if avg.child.is_some()
+                                        && 
avg.datatype.as_ref().is_some_and(|datatype| {
+                                            datatype.type_id == 
DataTypeId::Decimal as i32

Review Comment:
   Thanks, confirmed: with your data the new test got `NULL` from Comet and 
`0.5000` from Spark on the previous commit. The gate now admits an `AvgDecimal` 
only when its sum precision is below 38. Spark makes the sum 10 digits wider 
than the input up to 38, so below 38 any partial sum of n values stays under 
n·10^p, and no order of additions can overflow unless one group has more than 
10^10 values. That keeps inputs of precision 28 and above out, including 
`DECIMAL(38,0)`. "skip partial aggregation keeps decimal AVG whose sum can 
overflow when regrouped" covers your case: two tasks with `[M, 1 - M]` after 
skipping starts, in legacy and ANSI mode.
   
   



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