Coverage Report

Created: 2026-03-14 20:54

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/aggregate/aggregate_function_quantile_state.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 <stddef.h>
21
22
#include <memory>
23
#include <string>
24
25
#include "common/compiler_util.h" // IWYU pragma: keep
26
#include "core/assert_cast.h"
27
#include "core/column/column_complex.h"
28
#include "core/column/column_nullable.h"
29
#include "core/data_type/data_type_quantilestate.h"
30
#include "core/types.h"
31
#include "core/value/quantile_state.h"
32
#include "exprs/aggregate/aggregate_function.h"
33
34
namespace doris {
35
#include "common/compile_check_begin.h"
36
class Arena;
37
class BufferReadable;
38
class BufferWritable;
39
class IColumn;
40
} // namespace doris
41
42
namespace doris {
43
44
struct AggregateFunctionQuantileStateUnionOp {
45
    static constexpr auto name = "quantile_union";
46
47
0
    static void add(QuantileState& res, const double& data, bool& is_first) { res.add_value(data); }
48
49
0
    static void add(QuantileState& res, const QuantileState& data, bool& is_first) {
50
0
        if (UNLIKELY(is_first)) {
51
0
            res = data;
52
0
            is_first = false;
53
0
        } else {
54
0
            res.merge(data);
55
0
        }
56
0
    }
57
58
0
    static void merge(QuantileState& res, const QuantileState& data, bool& is_first) {
59
0
        if (UNLIKELY(is_first)) {
60
0
            res = data;
61
0
            is_first = false;
62
0
        } else {
63
0
            res.merge(data);
64
0
        }
65
0
    }
66
};
67
68
template <typename Op>
69
struct AggregateFunctionQuantileStateData {
70
    using DataType = QuantileState;
71
    DataType value;
72
    bool is_first = true;
73
74
    template <typename T>
75
0
    void add(const T& data) {
76
0
        Op::add(value, data, is_first);
77
0
    }
78
79
0
    void merge(const DataType& data) { Op::merge(value, data, is_first); }
80
81
0
    void write(BufferWritable& buf) const {
82
0
        DataTypeQuantileState::serialize_as_stream(value, buf);
83
0
    }
84
85
0
    void read(BufferReadable& buf) { DataTypeQuantileState::deserialize_as_stream(value, buf); }
86
87
0
    void reset() { is_first = true; }
88
89
    DataType& get() { return value; }
90
91
0
    const DataType& get() const { return value; }
92
};
93
94
template <bool arg_is_nullable, typename Op>
95
class AggregateFunctionQuantileStateOp final
96
        : public IAggregateFunctionDataHelper<
97
                  AggregateFunctionQuantileStateData<Op>,
98
                  AggregateFunctionQuantileStateOp<arg_is_nullable, Op>> {
99
public:
100
    using ResultDataType = QuantileState;
101
    using ColVecType = ColumnQuantileState;
102
    using ColVecResult = ColumnQuantileState;
103
104
0
    String get_name() const override { return Op::name; }
Unexecuted instantiation: _ZNK5doris32AggregateFunctionQuantileStateOpILb1ENS_37AggregateFunctionQuantileStateUnionOpEE8get_nameB5cxx11Ev
Unexecuted instantiation: _ZNK5doris32AggregateFunctionQuantileStateOpILb0ENS_37AggregateFunctionQuantileStateUnionOpEE8get_nameB5cxx11Ev
105
106
    AggregateFunctionQuantileStateOp(const DataTypes& argument_types_)
107
0
            : IAggregateFunctionDataHelper<AggregateFunctionQuantileStateData<Op>,
108
0
                                           AggregateFunctionQuantileStateOp<arg_is_nullable, Op>>(
109
0
                      argument_types_) {}
Unexecuted instantiation: _ZN5doris32AggregateFunctionQuantileStateOpILb1ENS_37AggregateFunctionQuantileStateUnionOpEEC2ERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE
Unexecuted instantiation: _ZN5doris32AggregateFunctionQuantileStateOpILb0ENS_37AggregateFunctionQuantileStateUnionOpEEC2ERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE
110
111
0
    DataTypePtr get_return_type() const override {
112
0
        return std::make_shared<DataTypeQuantileState>();
113
0
    }
Unexecuted instantiation: _ZNK5doris32AggregateFunctionQuantileStateOpILb1ENS_37AggregateFunctionQuantileStateUnionOpEE15get_return_typeEv
Unexecuted instantiation: _ZNK5doris32AggregateFunctionQuantileStateOpILb0ENS_37AggregateFunctionQuantileStateUnionOpEE15get_return_typeEv
114
115
    void add(AggregateDataPtr __restrict place, const IColumn** columns, ssize_t row_num,
116
0
             Arena&) const override {
117
0
        if constexpr (arg_is_nullable) {
118
0
            auto& nullable_column =
119
0
                    assert_cast<const ColumnNullable&, TypeCheckOnRelease::DISABLE>(*columns[0]);
120
0
            if (!nullable_column.is_null_at(row_num)) {
121
0
                const auto& column = assert_cast<const ColVecType&, TypeCheckOnRelease::DISABLE>(
122
0
                        nullable_column.get_nested_column());
123
0
                this->data(place).add(column.get_data()[row_num]);
124
0
            }
125
0
        } else {
126
0
            const auto& column =
127
0
                    assert_cast<const ColVecType&, TypeCheckOnRelease::DISABLE>(*columns[0]);
128
0
            this->data(place).add(column.get_data()[row_num]);
129
0
        }
130
0
    }
Unexecuted instantiation: _ZNK5doris32AggregateFunctionQuantileStateOpILb1ENS_37AggregateFunctionQuantileStateUnionOpEE3addEPcPPKNS_7IColumnElRNS_5ArenaE
Unexecuted instantiation: _ZNK5doris32AggregateFunctionQuantileStateOpILb0ENS_37AggregateFunctionQuantileStateUnionOpEE3addEPcPPKNS_7IColumnElRNS_5ArenaE
131
132
    void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs,
133
0
               Arena&) const override {
134
0
        this->data(place).merge(this->data(rhs).get());
135
0
    }
Unexecuted instantiation: _ZNK5doris32AggregateFunctionQuantileStateOpILb1ENS_37AggregateFunctionQuantileStateUnionOpEE5mergeEPcPKcRNS_5ArenaE
Unexecuted instantiation: _ZNK5doris32AggregateFunctionQuantileStateOpILb0ENS_37AggregateFunctionQuantileStateUnionOpEE5mergeEPcPKcRNS_5ArenaE
136
137
0
    void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const override {
138
0
        this->data(place).write(buf);
139
0
    }
Unexecuted instantiation: _ZNK5doris32AggregateFunctionQuantileStateOpILb1ENS_37AggregateFunctionQuantileStateUnionOpEE9serializeEPKcRNS_14BufferWritableE
Unexecuted instantiation: _ZNK5doris32AggregateFunctionQuantileStateOpILb0ENS_37AggregateFunctionQuantileStateUnionOpEE9serializeEPKcRNS_14BufferWritableE
140
141
    void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf,
142
0
                     Arena&) const override {
143
0
        this->data(place).read(buf);
144
0
    }
Unexecuted instantiation: _ZNK5doris32AggregateFunctionQuantileStateOpILb1ENS_37AggregateFunctionQuantileStateUnionOpEE11deserializeEPcRNS_14BufferReadableERNS_5ArenaE
Unexecuted instantiation: _ZNK5doris32AggregateFunctionQuantileStateOpILb0ENS_37AggregateFunctionQuantileStateUnionOpEE11deserializeEPcRNS_14BufferReadableERNS_5ArenaE
145
146
0
    void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override {
147
0
        auto& column = assert_cast<ColVecResult&>(to);
148
0
        column.get_data().push_back(this->data(place).get());
149
0
    }
Unexecuted instantiation: _ZNK5doris32AggregateFunctionQuantileStateOpILb1ENS_37AggregateFunctionQuantileStateUnionOpEE18insert_result_intoEPKcRNS_7IColumnE
Unexecuted instantiation: _ZNK5doris32AggregateFunctionQuantileStateOpILb0ENS_37AggregateFunctionQuantileStateUnionOpEE18insert_result_intoEPKcRNS_7IColumnE
150
151
0
    void reset(AggregateDataPtr __restrict place) const override { this->data(place).reset(); }
Unexecuted instantiation: _ZNK5doris32AggregateFunctionQuantileStateOpILb1ENS_37AggregateFunctionQuantileStateUnionOpEE5resetEPc
Unexecuted instantiation: _ZNK5doris32AggregateFunctionQuantileStateOpILb0ENS_37AggregateFunctionQuantileStateUnionOpEE5resetEPc
152
};
153
154
AggregateFunctionPtr create_aggregate_function_quantile_state_union(
155
        const std::string& name, const DataTypes& argument_types, const DataTypePtr& result_type,
156
        const bool result_is_nullable, const AggregateFunctionAttr& attr);
157
158
} // namespace doris
159
160
#include "common/compile_check_end.h"