alamb commented on code in PR #25710:
URL: https://github.com/apache/datafusion/pull/25710#discussion_r4232342894


##########
docs/source/library-user-guide/upgrading/56.0.0.md:
##########
@@ -623,6 +623,17 @@ This guarantees unique aggregate state field names and 
allows
 Users or integrations that inspect aggregate state field names directly,
 including custom UDAFs and FFI integrations.
 
+### `avg` intermediate state for groups with no values
+
+The `Accumulator` for `avg` now returns `NULL` for both the count and the sum

Review Comment:
   I think this is a bug fix -- I am not sure it needs an entry in the upgrade 
guide 🤔 



##########
datafusion/functions-aggregate/src/testing/state_compat.rs:
##########
@@ -0,0 +1,1017 @@
+// 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.
+
+//! Checks that the intermediate state produced by an aggregate's
+//! [`Accumulator`] and its [`GroupsAccumulator`] are interchangeable.
+//!
+//! # Built-in aggregate invariant
+//!
+//! DataFusion's own execution never mixes the two kinds of accumulator when
+//! merging state, so this is not a requirement of the `AggregateUDFImpl` API.
+//! It is, however, an invariant that every built-in aggregate function with a
+//! native [`GroupsAccumulator`] maintains, so that systems built on DataFusion
+//! can merge state produced by either kind with the other:
+//!
+//! * Each row of the state returned by `GroupsAccumulator::state` or
+//!   `GroupsAccumulator::convert_to_state` is accepted by
+//!   `Accumulator::merge_batch`.
+//! * `GroupsAccumulator::merge_batch` accepts state returned by
+//!   `Accumulator::state`.
+//! * Merging state from the other kind produces the same result as merging
+//!   the equivalent state from the same kind.
+//!
+//! The `builtin_accumulator_and_groups_accumulator_states_are_compatible` test
+//! below enforces this for every function in
+//! [`all_default_aggregate_functions`]. A new built-in function that the test
+//! cannot exercise must be added to its `NOT_EXERCISED` list with the reason.
+//!
+//! [`all_default_aggregate_functions`]: crate::all_default_aggregate_functions
+//! [`Accumulator`]: datafusion_expr::Accumulator
+//! [`GroupsAccumulator`]: datafusion_expr::GroupsAccumulator
+
+use std::collections::BTreeSet;
+use std::panic::{AssertUnwindSafe, catch_unwind};
+use std::sync::Arc;
+
+use arrow::array::{Array, ArrayRef, Int64Array, UInt32Array};
+use arrow::compute::{cast, concat, take};
+use arrow::datatypes::{DataType, Field, FieldRef, Schema, TimeUnit};
+use arrow::record_batch::{RecordBatch, RecordBatchOptions};
+use datafusion_common::{DataFusionError, Result, ScalarValue, exec_err};
+use datafusion_expr::type_coercion::functions::fields_with_udf;
+use datafusion_expr::{AggregateUDF, EmitTo};
+use datafusion_physical_expr::PhysicalSortExpr;
+use datafusion_physical_expr::aggregate::{AggregateExprBuilder, 
AggregateFunctionExpr};
+use datafusion_physical_expr::expressions::{Column, Literal};
+use datafusion_physical_expr_common::physical_expr::PhysicalExpr;
+
+/// Checks that `udaf`'s [`Accumulator`] and [`GroupsAccumulator`] can each

Review Comment:
   this feels like a lot of code / complexity for DataFusion 🤔 I understand it 
might be useful to people who implement accumulators out of the core, but it 
seems to me like this would be better placed in the `#[test]` config as a real 
unit / integration test and then duplicated if necesary into a downstream (e.g. 
Coralogix's) code base



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