-
Notifications
You must be signed in to change notification settings - Fork 0
2817: feat: Support ANSI mode avg expr #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1893,19 +1893,24 @@ impl PhysicalPlanner { | |
| let child = self.create_expr(expr.child.as_ref().unwrap(), Arc::clone(&schema))?; | ||
| let datatype = to_arrow_datatype(expr.datatype.as_ref().unwrap()); | ||
| let input_datatype = to_arrow_datatype(expr.sum_datatype.as_ref().unwrap()); | ||
| let eval_mode = from_protobuf_eval_mode(expr.eval_mode)?; | ||
|
|
||
| let builder = match datatype { | ||
| DataType::Decimal128(_, _) => { | ||
| let func = | ||
| AggregateUDF::new_from_impl(AvgDecimal::new(datatype, input_datatype)); | ||
| AggregateExprBuilder::new(Arc::new(func), vec![child]) | ||
| } | ||
| _ => { | ||
| // cast to the result data type of AVG if the result data type is different | ||
| // from the input type, e.g. AVG(Int32). We should not expect a cast | ||
| // failure since it should have already been checked at Spark side. | ||
| // For all other numeric types (Int8/16/32/64, Float32/64): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Decimal AVG ignores eval_mode parameterThe
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. value:useful; category:bug; feedback: The Bugbot AI reviewer is correct that the eval_mode is ignored for the AvgDecimal implementation. https://github.com/apache/spark/blob/211dd995b221f135340375159672dcb77ef90ef4/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/Average.scala#L113 shows that it is used in the Spark implementation. Prevents wrong behavior in DataFusion Comet compared to Spark. |
||
| // Cast to Float64 for accumulation | ||
| let child: Arc<dyn PhysicalExpr> = | ||
| Arc::new(CastExpr::new(Arc::clone(&child), datatype.clone(), None)); | ||
| let func = AggregateUDF::new_from_impl(Avg::new("avg", datatype)); | ||
| Arc::new(CastExpr::new(Arc::clone(&child), DataType::Float64, None)); | ||
| let func = AggregateUDF::new_from_impl(Avg::new( | ||
| "avg", | ||
| DataType::Float64, | ||
| eval_mode, | ||
| )); | ||
| AggregateExprBuilder::new(Arc::new(func), vec![child]) | ||
| } | ||
| }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eval_modeis computed for AVG but not used in the Decimal branch (AvgDecimal::new), so ANSI/TRY mode won’t affect Decimal AVG (e.g., overflow behavior). Consider propagatingeval_modeto the decimal implementation to ensure semantics match Spark’s modes (also applies givengetSupportLevelremoval in Scala).🤖 Was this useful? React with 👍 or 👎
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value:useful; category:bug; feedback: The Augment AI reviewer is correct that the eval_mode is ignored for the AvgDecimal implementation. https://github.com/apache/spark/blob/211dd995b221f135340375159672dcb77ef90ef4/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/Average.scala#L113 shows that it is used in the Spark implementation. Prevents wrong behavior in DataFusion Comet compared to Spark.