Coverage Report

Created: 2026-09-02 00:54

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/aggregate/aggregate_function_state_combine.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#pragma once
19
20
#include <utility>
21
22
#include "exprs/aggregate/aggregate_function.h"
23
24
namespace doris {
25
const static std::string AGG_COMBINE_SUFFIX = "_combine";
26
27
class AggregateStateCombine final : public IAggregateFunctionHelper<AggregateStateCombine> {
28
public:
29
    AggregateStateCombine(AggregateFunctionPtr function, const DataTypes& argument_types_,
30
                          DataTypePtr return_type)
31
4
            : IAggregateFunctionHelper(argument_types_),
32
4
              _function(std::move(function)),
33
4
              _return_type(std::move(return_type)) {}
34
35
    static AggregateFunctionPtr create(AggregateFunctionPtr function,
36
                                       const DataTypes& argument_types_,
37
4
                                       const DataTypePtr& return_type) {
38
4
        if (function == nullptr) {
39
0
            return nullptr;
40
0
        }
41
4
        return std::make_shared<AggregateStateCombine>(function, argument_types_, return_type);
42
4
    }
43
44
0
    void set_version(const int version_) override {
45
0
        IAggregateFunctionHelper::set_version(version_);
46
0
        _function->set_version(version_);
47
0
    }
48
49
14
    void create(AggregateDataPtr __restrict place) const override { _function->create(place); }
50
51
    void destroy_vec(AggregateDataPtr __restrict place,
52
0
                     const size_t num_rows) const noexcept override {
53
0
        _function->destroy_vec(place, num_rows);
54
0
    }
55
56
0
    String get_name() const override { return _function->get_name() + AGG_COMBINE_SUFFIX; }
57
58
0
    DataTypePtr get_return_type() const override { return _return_type; }
59
60
    void add(AggregateDataPtr __restrict place, const IColumn** columns, ssize_t row_num,
61
0
             Arena& arena) const override {
62
0
        _function->add(place, columns, row_num, arena);
63
0
    }
64
65
    void add_batch(size_t batch_size, AggregateDataPtr* places, size_t place_offset,
66
2
                   const IColumn** columns, Arena& arena, bool agg_many) const override {
67
2
        _function->add_batch(batch_size, places, place_offset, columns, arena, agg_many);
68
2
    }
69
70
    void add_batch_selected(size_t batch_size, AggregateDataPtr* places, size_t place_offset,
71
0
                            const IColumn** columns, Arena& arena) const override {
72
0
        _function->add_batch_selected(batch_size, places, place_offset, columns, arena);
73
0
    }
74
75
    void add_batch_single_place(size_t batch_size, AggregateDataPtr place, const IColumn** columns,
76
3
                                Arena& arena) const override {
77
3
        _function->add_batch_single_place(batch_size, place, columns, arena);
78
3
    }
79
80
    void add_batch_range(size_t batch_begin, size_t batch_end, AggregateDataPtr place,
81
0
                         const IColumn** columns, Arena& arena, bool has_null) override {
82
0
        _function->add_batch_range(batch_begin, batch_end, place, columns, arena, has_null);
83
0
    }
84
85
    void add_range_single_place(int64_t partition_start, int64_t partition_end, int64_t frame_start,
86
                                int64_t frame_end, AggregateDataPtr place, const IColumn** columns,
87
                                Arena& arena, UInt8* use_null_result,
88
0
                                UInt8* could_use_previous_result) const override {
89
0
        _function->add_range_single_place(partition_start, partition_end, frame_start, frame_end,
90
0
                                          place, columns, arena, use_null_result,
91
0
                                          could_use_previous_result);
92
0
    }
93
94
0
    void reset(AggregateDataPtr place) const override { _function->reset(place); }
95
96
    void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs,
97
0
               Arena& arena) const override {
98
0
        _function->merge(place, rhs, arena);
99
0
    }
100
101
    void merge_vec(const AggregateDataPtr __restrict* __restrict places, size_t offset,
102
                   ConstAggregateDataPtr __restrict rhs, Arena& arena,
103
0
                   const size_t num_rows) const override {
104
0
        _function->merge_vec(places, offset, rhs, arena, num_rows);
105
0
    }
106
107
    void merge_vec_selected(const AggregateDataPtr __restrict* __restrict places, size_t offset,
108
                            ConstAggregateDataPtr __restrict rhs, Arena& arena,
109
0
                            const size_t num_rows) const override {
110
0
        _function->merge_vec_selected(places, offset, rhs, arena, num_rows);
111
0
    }
112
113
0
    void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const override {
114
0
        _function->serialize(place, buf);
115
0
    }
116
117
    void serialize_vec(const std::vector<AggregateDataPtr>& places, size_t offset,
118
0
                       BufferWritable& buf, const size_t num_rows) const override {
119
0
        _function->serialize_vec(places, offset, buf, num_rows);
120
0
    }
121
122
    void serialize_to_column(const std::vector<AggregateDataPtr>& places, size_t offset,
123
0
                             MutableColumnPtr& dst, const size_t num_rows) const override {
124
0
        _function->serialize_to_column(places, offset, dst, num_rows);
125
0
    }
126
127
    void serialize_without_key_to_column(ConstAggregateDataPtr __restrict place,
128
1
                                         IColumn& to) const override {
129
1
        _function->serialize_without_key_to_column(place, to);
130
1
    }
131
132
    void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf,
133
0
                     Arena& arena) const override {
134
0
        _function->deserialize(place, buf, arena);
135
0
    }
136
137
    void deserialize_vec(AggregateDataPtr places, const ColumnString* column, Arena& arena,
138
0
                         size_t num_rows) const override {
139
0
        _function->deserialize_vec(places, column, arena, num_rows);
140
0
    }
141
142
    void deserialize_and_merge_vec(const AggregateDataPtr* places, size_t offset,
143
                                   AggregateDataPtr rhs, const IColumn* column, Arena& arena,
144
0
                                   const size_t num_rows) const override {
145
0
        _function->deserialize_and_merge_vec(places, offset, rhs, column, arena, num_rows);
146
0
    }
147
148
    void deserialize_and_merge_vec_selected(const AggregateDataPtr* places, size_t offset,
149
                                            AggregateDataPtr rhs, const IColumn* column,
150
0
                                            Arena& arena, const size_t num_rows) const override {
151
0
        _function->deserialize_and_merge_vec_selected(places, offset, rhs, column, arena, num_rows);
152
0
    }
153
154
    void deserialize_and_merge(AggregateDataPtr __restrict place, AggregateDataPtr __restrict rhs,
155
0
                               BufferReadable& buf, Arena& arena) const override {
156
0
        _function->deserialize_and_merge(place, rhs, buf, arena);
157
0
    }
158
159
    void deserialize_and_merge_from_column_range(AggregateDataPtr __restrict place,
160
                                                 const IColumn& column, size_t begin, size_t end,
161
1
                                                 Arena& arena) const override {
162
1
        _function->deserialize_and_merge_from_column_range(place, column, begin, end, arena);
163
1
    }
164
165
5
    void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override {
166
5
        if (to.empty()) {
167
4
            _function->serialize_without_key_to_column(place, to);
168
4
            DORIS_CHECK_EQ(to.size(), 1);
169
4
            return;
170
4
        }
171
172
1
        auto serialized_column = _function->create_serialize_column();
173
1
        _function->serialize_without_key_to_column(place, *serialized_column);
174
1
        DORIS_CHECK_EQ(serialized_column->size(), 1);
175
1
        to.insert_from(*serialized_column, 0);
176
1
    }
177
178
    void insert_result_into_vec(const std::vector<AggregateDataPtr>& places, const size_t offset,
179
2
                                IColumn& to, const size_t num_rows) const override {
180
2
        if (to.empty()) {
181
2
            auto mutable_to = to.assert_mutable();
182
2
            _function->serialize_to_column(places, offset, mutable_to, num_rows);
183
2
            DORIS_CHECK_EQ(to.size(), num_rows);
184
2
            return;
185
2
        }
186
187
0
        auto serialized_column = _function->create_serialize_column();
188
0
        _function->serialize_to_column(places, offset, serialized_column, num_rows);
189
0
        DORIS_CHECK_EQ(serialized_column->size(), num_rows);
190
0
        to.insert_range_from(*serialized_column, 0, num_rows);
191
0
    }
192
193
    void streaming_agg_serialize_to_column(const IColumn** columns, MutableColumnPtr& dst,
194
1
                                           const size_t num_rows, Arena& arena) const override {
195
1
        _function->streaming_agg_serialize_to_column(columns, dst, num_rows, arena);
196
1
    }
197
198
14
    void destroy(AggregateDataPtr __restrict place) const noexcept override {
199
14
        _function->destroy(place);
200
14
    }
201
202
0
    bool is_trivial() const override { return _function->is_trivial(); }
203
204
14
    size_t size_of_data() const override { return _function->size_of_data(); }
205
206
0
    size_t align_of_data() const override { return _function->align_of_data(); }
207
208
0
    void check_input_columns_type(const IColumn** columns) const override {
209
0
        _function->check_input_columns_type(columns);
210
0
    }
211
212
1
    MutableColumnPtr create_serialize_column() const override {
213
1
        return _function->create_serialize_column();
214
1
    }
215
216
1
    DataTypePtr get_serialized_type() const override { return _function->get_serialized_type(); }
217
218
0
    bool supported_incremental_mode() const override {
219
0
        return _function->supported_incremental_mode();
220
0
    }
221
222
    void execute_function_with_incremental(int64_t partition_start, int64_t partition_end,
223
                                           int64_t frame_start, int64_t frame_end,
224
                                           AggregateDataPtr place, const IColumn** columns,
225
                                           Arena& arena, bool previous_is_nul, bool end_is_nul,
226
                                           bool has_null, UInt8* use_null_result,
227
0
                                           UInt8* could_use_previous_result) const override {
228
0
        _function->execute_function_with_incremental(
229
0
                partition_start, partition_end, frame_start, frame_end, place, columns, arena,
230
0
                previous_is_nul, end_is_nul, has_null, use_null_result, could_use_previous_result);
231
0
    }
232
233
0
    void set_query_context(QueryContext* context) override {
234
0
        _function->set_query_context(context);
235
0
    }
236
237
0
    bool is_blockable() const override { return _function->is_blockable(); }
238
239
private:
240
    AggregateFunctionPtr _function;
241
    DataTypePtr _return_type;
242
};
243
244
} // namespace doris