Coverage Report

Created: 2026-04-17 21:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/aggregate/aggregate_function_sequence_match.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
18
#include "exprs/aggregate/aggregate_function_sequence_match.h"
19
20
#include <boost/iterator/iterator_facade.hpp>
21
22
#include "common/logging.h"
23
#include "core/data_type/data_type.h"
24
#include "exprs/aggregate/aggregate_function_simple_factory.h"
25
#include "exprs/aggregate/helpers.h"
26
27
namespace doris {
28
29
template <template <PrimitiveType> typename AggregateFunction>
30
AggregateFunctionPtr create_aggregate_function_sequence_base(const std::string& name,
31
                                                             const DataTypes& argument_types,
32
                                                             const DataTypePtr& result_type,
33
                                                             const bool result_is_nullable,
34
19
                                                             const AggregateFunctionAttr& attr) {
35
19
    const auto arg_count = argument_types.size();
36
37
19
    if (arg_count < 4) {
38
0
        LOG(WARNING) << "Aggregate function " + name + " requires at least 4 arguments.";
39
0
        return nullptr;
40
0
    }
41
19
    if (arg_count - 2 > MAX_EVENTS) {
42
0
        LOG(WARNING) << "Aggregate function " + name + " supports up to " +
43
0
                                std::to_string(MAX_EVENTS) + " event arguments.";
44
0
        return nullptr;
45
0
    }
46
47
19
    switch (argument_types[1]->get_primitive_type()) {
48
19
    case TYPE_DATETIMEV2:
49
19
        return creator_without_type::create<AggregateFunction<TYPE_DATETIMEV2>>(
50
19
                argument_types, result_is_nullable, attr);
51
0
    case TYPE_DATEV2:
52
0
        return creator_without_type::create<AggregateFunction<TYPE_DATEV2>>(
53
0
                argument_types, result_is_nullable, attr);
54
0
    default:
55
0
        return nullptr;
56
19
    }
57
19
}
_ZN5doris39create_aggregate_function_sequence_baseINS_30AggregateFunctionSequenceMatchEEESt10shared_ptrINS_18IAggregateFunctionEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorIS2_IKNS_9IDataTypeEESaISG_EERKSG_bRKNS_21AggregateFunctionAttrE
Line
Count
Source
34
9
                                                             const AggregateFunctionAttr& attr) {
35
9
    const auto arg_count = argument_types.size();
36
37
9
    if (arg_count < 4) {
38
0
        LOG(WARNING) << "Aggregate function " + name + " requires at least 4 arguments.";
39
0
        return nullptr;
40
0
    }
41
9
    if (arg_count - 2 > MAX_EVENTS) {
42
0
        LOG(WARNING) << "Aggregate function " + name + " supports up to " +
43
0
                                std::to_string(MAX_EVENTS) + " event arguments.";
44
0
        return nullptr;
45
0
    }
46
47
9
    switch (argument_types[1]->get_primitive_type()) {
48
9
    case TYPE_DATETIMEV2:
49
9
        return creator_without_type::create<AggregateFunction<TYPE_DATETIMEV2>>(
50
9
                argument_types, result_is_nullable, attr);
51
0
    case TYPE_DATEV2:
52
0
        return creator_without_type::create<AggregateFunction<TYPE_DATEV2>>(
53
0
                argument_types, result_is_nullable, attr);
54
0
    default:
55
0
        return nullptr;
56
9
    }
57
9
}
_ZN5doris39create_aggregate_function_sequence_baseINS_30AggregateFunctionSequenceCountEEESt10shared_ptrINS_18IAggregateFunctionEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorIS2_IKNS_9IDataTypeEESaISG_EERKSG_bRKNS_21AggregateFunctionAttrE
Line
Count
Source
34
10
                                                             const AggregateFunctionAttr& attr) {
35
10
    const auto arg_count = argument_types.size();
36
37
10
    if (arg_count < 4) {
38
0
        LOG(WARNING) << "Aggregate function " + name + " requires at least 4 arguments.";
39
0
        return nullptr;
40
0
    }
41
10
    if (arg_count - 2 > MAX_EVENTS) {
42
0
        LOG(WARNING) << "Aggregate function " + name + " supports up to " +
43
0
                                std::to_string(MAX_EVENTS) + " event arguments.";
44
0
        return nullptr;
45
0
    }
46
47
10
    switch (argument_types[1]->get_primitive_type()) {
48
10
    case TYPE_DATETIMEV2:
49
10
        return creator_without_type::create<AggregateFunction<TYPE_DATETIMEV2>>(
50
10
                argument_types, result_is_nullable, attr);
51
0
    case TYPE_DATEV2:
52
0
        return creator_without_type::create<AggregateFunction<TYPE_DATEV2>>(
53
0
                argument_types, result_is_nullable, attr);
54
0
    default:
55
0
        return nullptr;
56
10
    }
57
10
}
58
59
1
void register_aggregate_function_sequence_match(AggregateFunctionSimpleFactory& factory) {
60
1
    factory.register_function_both(
61
1
            "sequence_match",
62
1
            create_aggregate_function_sequence_base<AggregateFunctionSequenceMatch>);
63
1
    factory.register_function_both(
64
1
            "sequence_count",
65
1
            create_aggregate_function_sequence_base<AggregateFunctionSequenceCount>);
66
1
}
67
} // namespace doris