You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "AdamGS (via GitHub)" <gi...@apache.org> on 2026/07/24 13:18:57 UTC
Re: [PR] feat: Calculate non-distinct `sum` from column statistics when available [datafusion]
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org