asolimando commented on code in PR #20768:
URL: https://github.com/apache/datafusion/pull/20768#discussion_r2907856653


##########
datafusion/common/src/utils/aggregate.rs:
##########
@@ -0,0 +1,117 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Scalar-level aggregation utilities for statistics merging.
+//!
+//! Provides a cheap pairwise [`ScalarValue`] addition that directly
+//! extracts inner primitive values, avoiding the expensive
+//! `ScalarValue::add` path (which round-trips through Arrow arrays).
+
+use crate::stats::Precision;
+use crate::{Result, ScalarValue};
+
+/// Add two [`ScalarValue`]s by directly extracting and adding their
+/// inner primitive values.
+///
+/// This avoids `ScalarValue::add` which converts both operands to
+/// single-element Arrow arrays, runs the `add_wrapping` kernel, and
+/// converts the result back — 3 heap allocations per call.
+///
+/// For non-primitive types, falls back to `ScalarValue::add`.
+pub(crate) fn scalar_add(lhs: &ScalarValue, rhs: &ScalarValue) -> 
Result<ScalarValue> {
+    macro_rules! add_wrapping {
+        ($lhs:expr, $rhs:expr, $VARIANT:ident) => {
+            match ($lhs, $rhs) {
+                (ScalarValue::$VARIANT(Some(a)), 
ScalarValue::$VARIANT(Some(b))) => {
+                    Ok(ScalarValue::$VARIANT(Some(a.wrapping_add(*b))))

Review Comment:
   Checked the new commit, thanks for addressing the comment and filing the 
issue, marking as resolved!
   
   EDIT: it looks I lack privileges, I will let you do that if you want



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