Coverage Report

Created: 2026-03-16 04:30

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/aggregate/aggregate_function_state_union.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 "core/data_type/data_type_agg_state.h"
23
#include "exprs/aggregate/aggregate_function.h"
24
25
namespace doris {
26
#include "common/compile_check_begin.h"
27
const static std::string AGG_UNION_SUFFIX = "_union";
28
29
class AggregateStateUnion : public IAggregateFunctionHelper<AggregateStateUnion> {
30
public:
31
    AggregateStateUnion(AggregateFunctionPtr function, const DataTypes& argument_types_,
32
                        DataTypePtr return_type)
33
0
            : IAggregateFunctionHelper(argument_types_),
34
0
              _function(std::move(function)),
35
0
              _return_type(std::move(return_type)) {}
36
0
    ~AggregateStateUnion() override = default;
37
38
    static AggregateFunctionPtr create(AggregateFunctionPtr function,
39
                                       const DataTypes& argument_types_,
40
0
                                       const DataTypePtr& return_type) {
41
0
        CHECK(argument_types_.size() == 1);
42
0
        if (function == nullptr) {
43
0
            return nullptr;
44
0
        }
45
0
        return std::make_shared<AggregateStateUnion>(function, argument_types_, return_type);
46
0
    }
47
48
0
    void set_version(const int version_) override {
49
0
        IAggregateFunctionHelper::set_version(version_);
50
0
        _function->set_version(version_);
51
0
    }
52
53
0
    void create(AggregateDataPtr __restrict place) const override { _function->create(place); }
54
55
0
    String get_name() const override { return _function->get_name() + AGG_UNION_SUFFIX; }
56
57
0
    DataTypePtr get_return_type() const override { return _return_type; }
58
59
    void add(AggregateDataPtr __restrict place, const IColumn** columns, ssize_t row_num,
60
0
             Arena& arena) const override {
61
        //the range is [begin, end]
62
0
        _function->deserialize_and_merge_from_column_range(place, *columns[0], row_num, row_num,
63
0
                                                           arena);
64
0
    }
65
66
    void add_batch_single_place(size_t batch_size, AggregateDataPtr place, const IColumn** columns,
67
0
                                Arena& arena) const override {
68
0
        _function->deserialize_and_merge_from_column_range(place, *columns[0], 0, batch_size - 1,
69
0
                                                           arena);
70
0
    }
71
72
    void add_batch(size_t batch_size, AggregateDataPtr* places, size_t place_offset,
73
0
                   const IColumn** columns, Arena& arena, bool agg_many) const override {
74
0
        for (size_t i = 0; i < batch_size; ++i) {
75
            //the range is [i, i]
76
0
            _function->deserialize_and_merge_from_column_range(places[i] + place_offset,
77
0
                                                               *columns[0], i, i, arena);
78
0
        }
79
0
    }
80
0
    void reset(AggregateDataPtr place) const override { _function->reset(place); }
81
82
    void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs,
83
0
               Arena& arena) const override {
84
0
        _function->merge(place, rhs, arena);
85
0
    }
86
87
0
    void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const override {
88
0
        _function->serialize(place, buf);
89
0
    }
90
91
    void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf,
92
0
                     Arena& arena) const override {
93
0
        _function->deserialize(place, buf, arena);
94
0
    }
95
96
0
    void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override {
97
0
        _function->serialize_without_key_to_column(place, to);
98
0
    }
99
100
0
    void destroy(AggregateDataPtr __restrict place) const noexcept override {
101
0
        _function->destroy(place);
102
0
    }
103
104
0
    bool is_trivial() const override { return false; }
105
106
0
    size_t size_of_data() const override { return _function->size_of_data(); }
107
108
0
    size_t align_of_data() const override { return _function->align_of_data(); }
109
110
protected:
111
    AggregateFunctionPtr _function;
112
    DataTypePtr _return_type;
113
};
114
115
} // namespace doris
116
117
#include "common/compile_check_end.h"