Coverage Report

Created: 2026-03-14 13:33

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
322
                                             const AggregateFunctionAttr& attr) {
69
322
    if (!argument_types.empty()) {
70
0
        throw doris::Exception(
71
0
                Status::InternalError("create_window: argument_types must be empty"));
72
0
    }
73
322
    std::unique_ptr<IAggregateFunction> result =
74
322
            std::make_unique<AggregateFunctionTemplate>(argument_types);
75
322
    CHECK_AGG_FUNCTION_SERIALIZED_TYPE(AggregateFunctionTemplate);
76
322
    return AggregateFunctionPtr(result.release());
77
322
}
_ZN5doris23create_empty_arg_windowINS_23WindowFunctionDenseRankEEESt10shared_ptrINS_18IAggregateFunctionEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorIS2_IKNS_9IDataTypeEESaISG_EERKSG_bRKNS_21AggregateFunctionAttrE
Line
Count
Source
68
14
                                             const AggregateFunctionAttr& attr) {
69
14
    if (!argument_types.empty()) {
70
0
        throw doris::Exception(
71
0
                Status::InternalError("create_window: argument_types must be empty"));
72
0
    }
73
14
    std::unique_ptr<IAggregateFunction> result =
74
14
            std::make_unique<AggregateFunctionTemplate>(argument_types);
75
14
    CHECK_AGG_FUNCTION_SERIALIZED_TYPE(AggregateFunctionTemplate);
76
14
    return AggregateFunctionPtr(result.release());
77
14
}
_ZN5doris23create_empty_arg_windowINS_18WindowFunctionRankEEESt10shared_ptrINS_18IAggregateFunctionEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorIS2_IKNS_9IDataTypeEESaISG_EERKSG_bRKNS_21AggregateFunctionAttrE
Line
Count
Source
68
156
                                             const AggregateFunctionAttr& attr) {
69
156
    if (!argument_types.empty()) {
70
0
        throw doris::Exception(
71
0
                Status::InternalError("create_window: argument_types must be empty"));
72
0
    }
73
156
    std::unique_ptr<IAggregateFunction> result =
74
156
            std::make_unique<AggregateFunctionTemplate>(argument_types);
75
156
    CHECK_AGG_FUNCTION_SERIALIZED_TYPE(AggregateFunctionTemplate);
76
156
    return AggregateFunctionPtr(result.release());
77
156
}
_ZN5doris23create_empty_arg_windowINS_25WindowFunctionPercentRankEEESt10shared_ptrINS_18IAggregateFunctionEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorIS2_IKNS_9IDataTypeEESaISG_EERKSG_bRKNS_21AggregateFunctionAttrE
Line
Count
Source
68
8
                                             const AggregateFunctionAttr& attr) {
69
8
    if (!argument_types.empty()) {
70
0
        throw doris::Exception(
71
0
                Status::InternalError("create_window: argument_types must be empty"));
72
0
    }
73
8
    std::unique_ptr<IAggregateFunction> result =
74
8
            std::make_unique<AggregateFunctionTemplate>(argument_types);
75
8
    CHECK_AGG_FUNCTION_SERIALIZED_TYPE(AggregateFunctionTemplate);
76
8
    return AggregateFunctionPtr(result.release());
77
8
}
_ZN5doris23create_empty_arg_windowINS_23WindowFunctionRowNumberEEESt10shared_ptrINS_18IAggregateFunctionEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorIS2_IKNS_9IDataTypeEESaISG_EERKSG_bRKNS_21AggregateFunctionAttrE
Line
Count
Source
68
136
                                             const AggregateFunctionAttr& attr) {
69
136
    if (!argument_types.empty()) {
70
0
        throw doris::Exception(
71
0
                Status::InternalError("create_window: argument_types must be empty"));
72
0
    }
73
136
    std::unique_ptr<IAggregateFunction> result =
74
136
            std::make_unique<AggregateFunctionTemplate>(argument_types);
75
136
    CHECK_AGG_FUNCTION_SERIALIZED_TYPE(AggregateFunctionTemplate);
76
136
    return AggregateFunctionPtr(result.release());
77
136
}
_ZN5doris23create_empty_arg_windowINS_22WindowFunctionCumeDistEEESt10shared_ptrINS_18IAggregateFunctionEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorIS2_IKNS_9IDataTypeEESaISG_EERKSG_bRKNS_21AggregateFunctionAttrE
Line
Count
Source
68
8
                                             const AggregateFunctionAttr& attr) {
69
8
    if (!argument_types.empty()) {
70
0
        throw doris::Exception(
71
0
                Status::InternalError("create_window: argument_types must be empty"));
72
0
    }
73
8
    std::unique_ptr<IAggregateFunction> result =
74
8
            std::make_unique<AggregateFunctionTemplate>(argument_types);
75
8
    CHECK_AGG_FUNCTION_SERIALIZED_TYPE(AggregateFunctionTemplate);
76
8
    return AggregateFunctionPtr(result.release());
77
8
}
78
79
6
void register_aggregate_function_window_rank(AggregateFunctionSimpleFactory& factory) {
80
6
    factory.register_function("dense_rank", create_empty_arg_window<WindowFunctionDenseRank>);
81
6
    factory.register_function("rank", create_empty_arg_window<WindowFunctionRank>);
82
6
    factory.register_function("percent_rank", create_empty_arg_window<WindowFunctionPercentRank>);
83
6
    factory.register_function("row_number", create_empty_arg_window<WindowFunctionRowNumber>);
84
6
    factory.register_function("ntile", creator_without_type::creator<WindowFunctionNTile>);
85
6
    factory.register_function("cume_dist", create_empty_arg_window<WindowFunctionCumeDist>);
86
6
}
87
88
void register_aggregate_function_window_lead_lag_first_last(
89
6
        AggregateFunctionSimpleFactory& factory) {
90
6
    factory.register_function_both("lead", create_aggregate_function_window_lead);
91
6
    factory.register_function_both("lag", create_aggregate_function_window_lag);
92
6
    factory.register_function_both("first_value", create_aggregate_function_window_first);
93
6
    factory.register_function_both("last_value", create_aggregate_function_window_last);
94
6
    factory.register_function_both("nth_value", create_aggregate_function_window_nth_value);
95
6
}
96
97
} // namespace doris