AdamGS commented on code in PR #23863:
URL: https://github.com/apache/datafusion/pull/23863#discussion_r3645596374
##########
datafusion/common/src/stats.rs:
##########
@@ -21,9 +21,50 @@ use std::fmt::{self, Debug, Display};
use crate::{Result, ScalarValue};
-use crate::error::_plan_err;
+use crate::error::{_exec_err, _plan_err};
use crate::utils::aggregate::precision_add;
-use arrow::datatypes::{DataType, Schema};
+use arrow::datatypes::{
+ DECIMAL32_MAX_PRECISION, DECIMAL64_MAX_PRECISION, DECIMAL128_MAX_PRECISION,
+ DECIMAL256_MAX_PRECISION, DataType, Schema,
+};
+
+/// Returns the output type for SQL `SUM` with a single argument of `arg_type`.
+///
+/// Decimal SUM follows Spark-compatible widening:
+/// `DECIMAL(p, s) -> DECIMAL(min(max_precision, p + 10), s)`.
+/// See
<https://github.com/apache/spark/blob/fcf636d9eb8d645c24be3db2d599aba2d7e2955a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/Sum.scala#L66>.
+pub fn sum_return_type(arg_type: &DataType) -> Result<DataType> {
Review Comment:
This is useful because both `Precision<ScalarValue>` and `Sum::return_type`
expose this functionality, and they currently don't match for floats and
decimals
--
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]