Coverage Report

Created: 2026-03-13 12:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/aggregate/aggregate_function_window.cpp
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
// This file is copied from
18
// https://github.com/ClickHouse/ClickHouse/blob/master/src/Processors/Transforms/WindowTransform.cpp
19
// and modified by Doris
20
21
#include "exprs/aggregate/aggregate_function_window.h"
22
23
#include <string>
24
25
#include "exprs/aggregate/aggregate_function_simple_factory.h"
26
#include "exprs/aggregate/helpers.h"
27
28
namespace doris {
29
#include "common/compile_check_begin.h"
30
31
// Defined in separate translation units to reduce per-file template instantiation cost:
32
//   aggregate_function_window_lag.cpp
33
//   aggregate_function_window_lead.cpp
34
//   aggregate_function_window_first.cpp
35
//   aggregate_function_window_last.cpp
36
//   aggregate_function_window_nth_value.cpp
37
AggregateFunctionPtr create_aggregate_function_window_lag(const std::string& name,
38
                                                          const DataTypes& argument_types,
39
                                                          const DataTypePtr& result_type,
40
                                                          const bool result_is_nullable,
41
                                                          const AggregateFunctionAttr& attr);
42
AggregateFunctionPtr create_aggregate_function_window_lead(const std::string& name,
43
                                                           const DataTypes& argument_types,
44
                                                           const DataTypePtr& result_type,
45
                                                           const bool result_is_nullable,
46
                                                           const AggregateFunctionAttr& attr);
47
AggregateFunctionPtr create_aggregate_function_window_first(const std::string& name,
48
                                                            const DataTypes& argument_types,
49
                                                            const DataTypePtr& result_type,
50
                                                            const bool result_is_nullable,
51
                                                            const AggregateFunctionAttr& attr);
52
AggregateFunctionPtr create_aggregate_function_window_last(const std::string& name,
53
                                                           const DataTypes& argument_types,
54
                                                           const DataTypePtr& result_type,
55
                                                           const bool result_is_nullable,
56
                                                           const AggregateFunctionAttr& attr);
57
AggregateFunctionPtr create_aggregate_function_window_nth_value(const std::string& name,
58
                                                                const DataTypes& argument_types,
59
                                                                const DataTypePtr& result_type,
60
                                                                const bool result_is_nullable,
61
                                                                const AggregateFunctionAttr& attr);
62
63
template <typename AggregateFunctionTemplate>
64
AggregateFunctionPtr create_empty_arg_window(const std::string& name,
65
                                             const DataTypes& argument_types,
66
                                             const DataTypePtr& result_type,
67
                                             const bool result_is_nullable,
68
19
                                             const AggregateFunctionAttr& attr) {
69
19
    if (!argument_types.empty()) {
70
0
        throw doris::Exception(
71
0
                Status::InternalError("create_window: argument_types must be empty"));
72
0
    }
73
19
    std::unique_ptr<IAggregateFunction> result =
74
19
            std::make_unique<AggregateFunctionTemplate>(argument_types);
75
19
    CHECK_AGG_FUNCTION_SERIALIZED_TYPE(AggregateFunctionTemplate);
76
19
    return AggregateFunctionPtr(result.release());
77
19
}
_ZN5doris23create_empty_arg_windowINS_23WindowFunctionDenseRankEEESt10shared_ptrINS_18IAggregateFunctionEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorIS2_IKNS_9IDataTypeEESaISG_EERKSG_bRKNS_21AggregateFunctionAttrE
Line
Count
Source
68
3
                                             const AggregateFunctionAttr& attr) {
69
3
    if (!argument_types.empty()) {
70
0
        throw doris::Exception(
71
0
                Status::InternalError("create_window: argument_types must be empty"));
72
0
    }
73
3
    std::unique_ptr<IAggregateFunction> result =
74
3
            std::make_unique<AggregateFunctionTemplate>(argument_types);
75
3
    CHECK_AGG_FUNCTION_SERIALIZED_TYPE(AggregateFunctionTemplate);
76
3
    return AggregateFunctionPtr(result.release());
77
3
}
_ZN5doris23create_empty_arg_windowINS_18WindowFunctionRankEEESt10shared_ptrINS_18IAggregateFunctionEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorIS2_IKNS_9IDataTypeEESaISG_EERKSG_bRKNS_21AggregateFunctionAttrE
Line
Count
Source
68
5
                                             const AggregateFunctionAttr& attr) {
69
5
    if (!argument_types.empty()) {
70
0
        throw doris::Exception(
71
0
                Status::InternalError("create_window: argument_types must be empty"));
72
0
    }
73
5
    std::unique_ptr<IAggregateFunction> result =
74
5
            std::make_unique<AggregateFunctionTemplate>(argument_types);
75
5
    CHECK_AGG_FUNCTION_SERIALIZED_TYPE(AggregateFunctionTemplate);
76
5
    return AggregateFunctionPtr(result.release());
77
5
}
Unexecuted instantiation: _ZN5doris23create_empty_arg_windowINS_25WindowFunctionPercentRankEEESt10shared_ptrINS_18IAggregateFunctionEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorIS2_IKNS_9IDataTypeEESaISG_EERKSG_bRKNS_21AggregateFunctionAttrE
_ZN5doris23create_empty_arg_windowINS_23WindowFunctionRowNumberEEESt10shared_ptrINS_18IAggregateFunctionEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorIS2_IKNS_9IDataTypeEESaISG_EERKSG_bRKNS_21AggregateFunctionAttrE
Line
Count
Source
68
11
                                             const AggregateFunctionAttr& attr) {
69
11
    if (!argument_types.empty()) {
70
0
        throw doris::Exception(
71
0
                Status::InternalError("create_window: argument_types must be empty"));
72
0
    }
73
11
    std::unique_ptr<IAggregateFunction> result =
74
11
            std::make_unique<AggregateFunctionTemplate>(argument_types);
75
11
    CHECK_AGG_FUNCTION_SERIALIZED_TYPE(AggregateFunctionTemplate);
76
11
    return AggregateFunctionPtr(result.release());
77
11
}
Unexecuted instantiation: _ZN5doris23create_empty_arg_windowINS_22WindowFunctionCumeDistEEESt10shared_ptrINS_18IAggregateFunctionEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorIS2_IKNS_9IDataTypeEESaISG_EERKSG_bRKNS_21AggregateFunctionAttrE
78
79
8
void register_aggregate_function_window_rank(AggregateFunctionSimpleFactory& factory) {
80
8
    factory.register_function("dense_rank", create_empty_arg_window<WindowFunctionDenseRank>);
81
8
    factory.register_function("rank", create_empty_arg_window<WindowFunctionRank>);
82
8
    factory.register_function("percent_rank", create_empty_arg_window<WindowFunctionPercentRank>);
83
8
    factory.register_function("row_number", create_empty_arg_window<WindowFunctionRowNumber>);
84
8
    factory.register_function("ntile", creator_without_type::creator<WindowFunctionNTile>);
85
8
    factory.register_function("cume_dist", create_empty_arg_window<WindowFunctionCumeDist>);
86
8
}
87
88
void register_aggregate_function_window_lead_lag_first_last(
89
8
        AggregateFunctionSimpleFactory& factory) {
90
8
    factory.register_function_both("lead", create_aggregate_function_window_lead);
91
8
    factory.register_function_both("lag", create_aggregate_function_window_lag);
92
8
    factory.register_function_both("first_value", create_aggregate_function_window_first);
93
8
    factory.register_function_both("last_value", create_aggregate_function_window_last);
94
8
    factory.register_function_both("nth_value", create_aggregate_function_window_nth_value);
95
8
}
96
97
} // namespace doris