github-actions[bot] commented on code in PR #66942:
URL: https://github.com/apache/doris/pull/66942#discussion_r3850040028
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/AggCombinerFunctionBuilder.java:
##########
@@ -159,7 +181,8 @@ public String parameterDisplayString() {
public static boolean isAggStateCombinator(String name) {
return name.toLowerCase().endsWith(STATE_SUFFIX) ||
name.toLowerCase().endsWith(MERGE_SUFFIX)
- || name.toLowerCase().endsWith(UNION_SUFFIX) ||
name.toLowerCase().endsWith(FOREACH_SUFFIX);
+ || name.toLowerCase().endsWith(UNION_SUFFIX) ||
name.toLowerCase().endsWith(COMBINE_SUFFIX)
Review Comment:
The current head still misses the argument-applicability part of this
thread. With the default `prefer_udf_over_builtin=false`, an exact two-argument
scalar UDF named `avg_combine` is still classified as aggregate before binding:
`isAggregateFunction()` sees the base `avg` builders by name and returns true.
Actual argument-aware resolution then rejects the synthesized one-argument AVG
combinator for two arguments and falls back to that scalar UDF. HAVING/ORDER BY
have already bound its alias-colliding arguments in aggregate-input scope, so
they bind the raw input (or fail grouping validation) instead of the
aggregate-output alias.
Please make pre-binding classification use the same applicability/priority
decision as final resolution (or defer/retry scope binding), and add exact
suffix-named scalar-UDF collision coverage for inapplicable built-in arities in
both HAVING and ORDER BY.
##########
be/src/exprs/aggregate/aggregate_function_state_combine.h:
##########
@@ -0,0 +1,231 @@
+// 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.
+
+#pragma once
+
+#include <utility>
+
+#include "exprs/aggregate/aggregate_function.h"
+
+namespace doris {
+const static std::string AGG_COMBINE_SUFFIX = "_combine";
+
+class AggregateStateCombine final : public
IAggregateFunctionHelper<AggregateStateCombine> {
+public:
+ AggregateStateCombine(AggregateFunctionPtr function, const DataTypes&
argument_types_,
+ DataTypePtr return_type)
+ : IAggregateFunctionHelper(argument_types_),
+ _function(std::move(function)),
+ _return_type(std::move(return_type)) {}
+
+ static AggregateFunctionPtr create(AggregateFunctionPtr function,
+ const DataTypes& argument_types_,
+ const DataTypePtr& return_type) {
+ if (function == nullptr) {
+ return nullptr;
+ }
+ return std::make_shared<AggregateStateCombine>(function,
argument_types_, return_type);
+ }
+
+ void set_version(const int version_) override {
+ IAggregateFunctionHelper::set_version(version_);
+ _function->set_version(version_);
+ }
+
+ void create(AggregateDataPtr __restrict place) const override {
_function->create(place); }
+
+ void destroy_vec(AggregateDataPtr __restrict place,
+ const size_t num_rows) const noexcept override {
+ _function->destroy_vec(place, num_rows);
+ }
+
+ String get_name() const override { return _function->get_name() +
AGG_COMBINE_SUFFIX; }
+
+ DataTypePtr get_return_type() const override { return _return_type; }
+
+ void add(AggregateDataPtr __restrict place, const IColumn** columns,
ssize_t row_num,
+ Arena& arena) const override {
+ _function->add(place, columns, row_num, arena);
+ }
+
+ void add_batch(size_t batch_size, AggregateDataPtr* places, size_t
place_offset,
+ const IColumn** columns, Arena& arena, bool agg_many) const
override {
+ _function->add_batch(batch_size, places, place_offset, columns, arena,
agg_many);
+ }
+
+ void add_batch_selected(size_t batch_size, AggregateDataPtr* places,
size_t place_offset,
+ const IColumn** columns, Arena& arena) const
override {
+ _function->add_batch_selected(batch_size, places, place_offset,
columns, arena);
+ }
+
+ void add_batch_single_place(size_t batch_size, AggregateDataPtr place,
const IColumn** columns,
+ Arena& arena) const override {
+ _function->add_batch_single_place(batch_size, place, columns, arena);
+ }
+
+ void add_batch_range(size_t batch_begin, size_t batch_end,
AggregateDataPtr place,
+ const IColumn** columns, Arena& arena, bool has_null)
override {
+ _function->add_batch_range(batch_begin, batch_end, place, columns,
arena, has_null);
+ }
+
+ void add_range_single_place(int64_t partition_start, int64_t
partition_end, int64_t frame_start,
+ int64_t frame_end, AggregateDataPtr place,
const IColumn** columns,
+ Arena& arena, UInt8* use_null_result,
+ UInt8* could_use_previous_result) const
override {
+ _function->add_range_single_place(partition_start, partition_end,
frame_start, frame_end,
+ place, columns, arena,
use_null_result,
+ could_use_previous_result);
+ }
+
+ void reset(AggregateDataPtr place) const override {
_function->reset(place); }
+
+ void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs,
+ Arena& arena) const override {
+ _function->merge(place, rhs, arena);
+ }
+
+ void merge_vec(const AggregateDataPtr __restrict* __restrict places,
size_t offset,
+ ConstAggregateDataPtr __restrict rhs, Arena& arena,
+ const size_t num_rows) const override {
+ _function->merge_vec(places, offset, rhs, arena, num_rows);
+ }
+
+ void merge_vec_selected(const AggregateDataPtr __restrict* __restrict
places, size_t offset,
+ ConstAggregateDataPtr __restrict rhs, Arena& arena,
+ const size_t num_rows) const override {
+ _function->merge_vec_selected(places, offset, rhs, arena, num_rows);
+ }
+
+ void serialize(ConstAggregateDataPtr __restrict place, BufferWritable&
buf) const override {
+ _function->serialize(place, buf);
+ }
+
+ void serialize_vec(const std::vector<AggregateDataPtr>& places, size_t
offset,
+ BufferWritable& buf, const size_t num_rows) const
override {
+ _function->serialize_vec(places, offset, buf, num_rows);
+ }
+
+ void serialize_to_column(const std::vector<AggregateDataPtr>& places,
size_t offset,
+ MutableColumnPtr& dst, const size_t num_rows)
const override {
+ _function->serialize_to_column(places, offset, dst, num_rows);
+ }
+
+ void serialize_without_key_to_column(ConstAggregateDataPtr __restrict
place,
+ IColumn& to) const override {
+ _function->serialize_without_key_to_column(place, to);
+ }
+
+ void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf,
+ Arena& arena) const override {
+ _function->deserialize(place, buf, arena);
+ }
+
+ void deserialize_vec(AggregateDataPtr places, const ColumnString* column,
Arena& arena,
+ size_t num_rows) const override {
+ _function->deserialize_vec(places, column, arena, num_rows);
+ }
+
+ void deserialize_and_merge_vec(const AggregateDataPtr* places, size_t
offset,
+ AggregateDataPtr rhs, const IColumn*
column, Arena& arena,
+ const size_t num_rows) const override {
+ _function->deserialize_and_merge_vec(places, offset, rhs, column,
arena, num_rows);
+ }
+
+ void deserialize_and_merge_vec_selected(const AggregateDataPtr* places,
size_t offset,
+ AggregateDataPtr rhs, const
IColumn* column,
+ Arena& arena, const size_t
num_rows) const override {
+ _function->deserialize_and_merge_vec_selected(places, offset, rhs,
column, arena, num_rows);
+ }
+
+ void deserialize_and_merge(AggregateDataPtr __restrict place,
AggregateDataPtr __restrict rhs,
+ BufferReadable& buf, Arena& arena) const
override {
+ _function->deserialize_and_merge(place, rhs, buf, arena);
+ }
+
+ void deserialize_and_merge_from_column_range(AggregateDataPtr __restrict
place,
+ const IColumn& column, size_t
begin, size_t end,
+ Arena& arena) const override {
+ _function->deserialize_and_merge_from_column_range(place, column,
begin, end, arena);
+ }
+
+ void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn&
to) const override {
+ auto serialized_column = _function->create_serialize_column();
+ _function->serialize_without_key_to_column(place, *serialized_column);
+ DORIS_CHECK_EQ(serialized_column->size(), 1);
+ to.insert_from(*serialized_column, 0);
+ }
+
+ void insert_result_into_vec(const std::vector<AggregateDataPtr>& places,
const size_t offset,
+ IColumn& to, const size_t num_rows) const
override {
+ auto serialized_column = _function->create_serialize_column();
+ _function->serialize_to_column(places, offset, serialized_column,
num_rows);
+ DORIS_CHECK_EQ(serialized_column->size(), num_rows);
+ to.insert_range_from(*serialized_column, 0, num_rows);
Review Comment:
[P1] Avoid a second full copy of variable-width states
The nested `serialize_to_column()` call already copies the current batch's
complete state payload into `serialized_column`, and this `insert_range_from()`
recursively copies it again into `to`. This is a deep copy for supported,
unfenced `array_agg_combine`/`map_agg*_combine`: with live state payload H and
output payload B, normal direct finalization is roughly H+B with one O(B) copy,
while this path reaches H+2B and performs two O(B) copies (about 2B to 3B peak
when H is approximately B). Large groups can therefore OOM or spend twice the
finalization copy work even though this combinator is intended to remove
redundant state materialization. Production output columns are
empty/capacity-reused on this path; please provide an append-safe direct or
ownership-transfer path for empty destinations while retaining the temporary
fallback needed for nonempty nullable-count appends, and cover a large grouped
array/map state.
--
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]