Coverage Report

Created: 2026-04-16 21:18

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