Coverage Report

Created: 2026-09-17 15:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/aggregate/aggregate_function_sequence_match.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
// This file is copied from
19
// https://github.com/ClickHouse/ClickHouse/blob/master/AggregateFunctionSequenceMatch.h
20
// and modified by Doris
21
22
#pragma once
23
24
#include <string.h>
25
26
#include <algorithm>
27
#include <bitset>
28
#include <boost/iterator/iterator_facade.hpp>
29
#include <cctype>
30
#include <cstdint>
31
#include <functional>
32
#include <iterator>
33
#include <memory>
34
#include <stack>
35
#include <string>
36
#include <tuple>
37
#include <utility>
38
#include <vector>
39
40
#include "common/exception.h"
41
#include "common/logging.h"
42
#include "core/assert_cast.h"
43
#include "core/column/column_string.h"
44
#include "core/column/column_vector.h"
45
#include "core/data_type/data_type_number.h"
46
#include "core/pod_array_fwd.h"
47
#include "core/string_ref.h"
48
#include "core/types.h"
49
#include "exprs/aggregate/aggregate_function.h"
50
#include "util/string_parser.hpp"
51
52
namespace doris {
53
class Arena;
54
class BufferReadable;
55
class BufferWritable;
56
class IColumn;
57
} // namespace doris
58
59
namespace doris {
60
61
template <template <typename> class Comparator>
62
struct ComparePairFirst final {
63
    template <typename T1, typename T2>
64
62
    bool operator()(const std::pair<T1, T2>& lhs, const std::pair<T1, T2>& rhs) const {
65
62
        return Comparator<T1> {}(lhs.first, rhs.first);
66
62
    }
_ZNK5doris16ComparePairFirstISt4lessEclINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEESt6bitsetILm32EEEEbRKSt4pairIT_T0_ESE_
Line
Count
Source
64
62
    bool operator()(const std::pair<T1, T2>& lhs, const std::pair<T1, T2>& rhs) const {
65
62
        return Comparator<T1> {}(lhs.first, rhs.first);
66
62
    }
Unexecuted instantiation: _ZNK5doris16ComparePairFirstISt4lessEclINS_16TimeStampNsValueESt6bitsetILm32EEEEbRKSt4pairIT_T0_ESC_
Unexecuted instantiation: _ZNK5doris16ComparePairFirstISt4lessEclINS_11DateV2ValueINS_15DateV2ValueTypeEEESt6bitsetILm32EEEEbRKSt4pairIT_T0_ESE_
Unexecuted instantiation: _ZNK5doris16ComparePairFirstISt4lessEclINS_16TimestampTzValueESt6bitsetILm32EEEEbRKSt4pairIT_T0_ESC_
67
};
68
69
static constexpr size_t MAX_EVENTS = 32;
70
71
/// Max number of iterations to match the pattern against a sequence, exception thrown when exceeded
72
constexpr auto sequence_match_max_iterations = 1000000l;
73
74
template <PrimitiveType T, typename Derived>
75
struct AggregateFunctionSequenceMatchData final {
76
    using Timestamp = typename PrimitiveTypeTraits<T>::CppType;
77
    using Events = std::bitset<MAX_EVENTS>;
78
    using TimestampEvents = std::pair<Timestamp, Events>;
79
    using Comparator = ComparePairFirst<std::less>;
80
81
451
    AggregateFunctionSequenceMatchData() { reset(); }
_ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEEC2Ev
Line
Count
Source
81
227
    AggregateFunctionSequenceMatchData() { reset(); }
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEEC2Ev
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEEC2Ev
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEEC2Ev
_ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEEC2Ev
Line
Count
Source
81
224
    AggregateFunctionSequenceMatchData() { reset(); }
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEEC2Ev
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEEC2Ev
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEEC2Ev
82
83
public:
84
61
    const std::string get_pattern() const { return pattern; }
_ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEE11get_patternB5cxx11Ev
Line
Count
Source
84
31
    const std::string get_pattern() const { return pattern; }
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEE11get_patternB5cxx11Ev
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEE11get_patternB5cxx11Ev
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEE11get_patternB5cxx11Ev
_ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEE11get_patternB5cxx11Ev
Line
Count
Source
84
30
    const std::string get_pattern() const { return pattern; }
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEE11get_patternB5cxx11Ev
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEE11get_patternB5cxx11Ev
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEE11get_patternB5cxx11Ev
85
86
146
    size_t get_arg_count() const { return arg_count; }
_ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEE13get_arg_countEv
Line
Count
Source
86
74
    size_t get_arg_count() const { return arg_count; }
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEE13get_arg_countEv
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEE13get_arg_countEv
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEE13get_arg_countEv
_ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEE13get_arg_countEv
Line
Count
Source
86
72
    size_t get_arg_count() const { return arg_count; }
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEE13get_arg_countEv
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEE13get_arg_countEv
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEE13get_arg_countEv
87
88
432
    void init(const std::string pattern_, size_t arg_count_) {
89
432
        if (!init_flag) {
90
383
            this->pattern = pattern_;
91
383
            this->arg_count = arg_count_;
92
383
            parse_pattern();
93
383
            init_flag = true;
94
383
        }
95
432
    }
_ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEE4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm
Line
Count
Source
88
219
    void init(const std::string pattern_, size_t arg_count_) {
89
219
        if (!init_flag) {
90
193
            this->pattern = pattern_;
91
193
            this->arg_count = arg_count_;
92
193
            parse_pattern();
93
193
            init_flag = true;
94
193
        }
95
219
    }
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEE4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEE4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEE4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm
_ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEE4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm
Line
Count
Source
88
213
    void init(const std::string pattern_, size_t arg_count_) {
89
213
        if (!init_flag) {
90
190
            this->pattern = pattern_;
91
190
            this->arg_count = arg_count_;
92
190
            parse_pattern();
93
190
            init_flag = true;
94
190
        }
95
213
    }
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEE4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEE4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEE4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEm
96
97
497
    void reset() {
98
497
        sorted = true;
99
497
        init_flag = false;
100
497
        pattern_has_time = false;
101
497
        pattern = "";
102
497
        arg_count = 0;
103
497
        conditions_met.reset();
104
497
        conditions_in_pattern.reset();
105
106
497
        events_list.clear();
107
497
        actions.clear();
108
497
        dfa_states.clear();
109
497
    }
_ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEE5resetEv
Line
Count
Source
97
250
    void reset() {
98
250
        sorted = true;
99
250
        init_flag = false;
100
250
        pattern_has_time = false;
101
250
        pattern = "";
102
250
        arg_count = 0;
103
250
        conditions_met.reset();
104
250
        conditions_in_pattern.reset();
105
106
250
        events_list.clear();
107
250
        actions.clear();
108
250
        dfa_states.clear();
109
250
    }
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEE5resetEv
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEE5resetEv
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEE5resetEv
_ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEE5resetEv
Line
Count
Source
97
247
    void reset() {
98
247
        sorted = true;
99
247
        init_flag = false;
100
247
        pattern_has_time = false;
101
247
        pattern = "";
102
247
        arg_count = 0;
103
247
        conditions_met.reset();
104
247
        conditions_in_pattern.reset();
105
106
247
        events_list.clear();
107
247
        actions.clear();
108
247
        dfa_states.clear();
109
247
    }
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEE5resetEv
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEE5resetEv
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEE5resetEv
110
111
333
    void add(const Timestamp& timestamp, const Events& events) {
112
        /// store information exclusively for rows with at least one event
113
333
        if (events.any()) {
114
190
            events_list.emplace_back(timestamp, events);
115
190
            sorted = false;
116
190
            conditions_met |= events;
117
190
        }
118
333
    }
_ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEE3addERKNS_11DateV2ValueINS_19DateTimeV2ValueTypeEEERKSt6bitsetILm32EE
Line
Count
Source
111
169
    void add(const Timestamp& timestamp, const Events& events) {
112
        /// store information exclusively for rows with at least one event
113
169
        if (events.any()) {
114
96
            events_list.emplace_back(timestamp, events);
115
96
            sorted = false;
116
96
            conditions_met |= events;
117
96
        }
118
169
    }
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEE3addERKNS_16TimeStampNsValueERKSt6bitsetILm32EE
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEE3addERKNS_11DateV2ValueINS_15DateV2ValueTypeEEERKSt6bitsetILm32EE
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEE3addERKNS_16TimestampTzValueERKSt6bitsetILm32EE
_ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEE3addERKNS_11DateV2ValueINS_19DateTimeV2ValueTypeEEERKSt6bitsetILm32EE
Line
Count
Source
111
164
    void add(const Timestamp& timestamp, const Events& events) {
112
        /// store information exclusively for rows with at least one event
113
164
        if (events.any()) {
114
94
            events_list.emplace_back(timestamp, events);
115
94
            sorted = false;
116
94
            conditions_met |= events;
117
94
        }
118
164
    }
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEE3addERKNS_16TimeStampNsValueERKSt6bitsetILm32EE
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEE3addERKNS_11DateV2ValueINS_15DateV2ValueTypeEEERKSt6bitsetILm32EE
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEE3addERKNS_16TimestampTzValueERKSt6bitsetILm32EE
119
120
160
    void merge(const AggregateFunctionSequenceMatchData& other) {
121
160
        if (other.events_list.empty()) {
122
88
            return;
123
88
        }
124
125
72
        if (events_list.empty()) {
126
38
            reset();
127
38
            init(other.pattern, other.arg_count);
128
38
        } else if (UNLIKELY(pattern != other.pattern || arg_count != other.arg_count)) {
129
16
            throw Exception(ErrorCode::INVALID_ARGUMENT,
130
16
                            "sequence aggregate states have incompatible patterns or event counts");
131
16
        }
132
133
56
        events_list.insert(std::end(events_list), std::begin(other.events_list),
134
56
                           std::end(other.events_list));
135
56
        sorted = false;
136
56
        conditions_met |= other.conditions_met;
137
56
    }
_ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEE5mergeERKS4_
Line
Count
Source
120
80
    void merge(const AggregateFunctionSequenceMatchData& other) {
121
80
        if (other.events_list.empty()) {
122
44
            return;
123
44
        }
124
125
36
        if (events_list.empty()) {
126
19
            reset();
127
19
            init(other.pattern, other.arg_count);
128
19
        } else if (UNLIKELY(pattern != other.pattern || arg_count != other.arg_count)) {
129
8
            throw Exception(ErrorCode::INVALID_ARGUMENT,
130
8
                            "sequence aggregate states have incompatible patterns or event counts");
131
8
        }
132
133
28
        events_list.insert(std::end(events_list), std::begin(other.events_list),
134
28
                           std::end(other.events_list));
135
28
        sorted = false;
136
28
        conditions_met |= other.conditions_met;
137
28
    }
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEE5mergeERKS4_
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEE5mergeERKS4_
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEE5mergeERKS4_
_ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEE5mergeERKS4_
Line
Count
Source
120
80
    void merge(const AggregateFunctionSequenceMatchData& other) {
121
80
        if (other.events_list.empty()) {
122
44
            return;
123
44
        }
124
125
36
        if (events_list.empty()) {
126
19
            reset();
127
19
            init(other.pattern, other.arg_count);
128
19
        } else if (UNLIKELY(pattern != other.pattern || arg_count != other.arg_count)) {
129
8
            throw Exception(ErrorCode::INVALID_ARGUMENT,
130
8
                            "sequence aggregate states have incompatible patterns or event counts");
131
8
        }
132
133
28
        events_list.insert(std::end(events_list), std::begin(other.events_list),
134
28
                           std::end(other.events_list));
135
28
        sorted = false;
136
28
        conditions_met |= other.conditions_met;
137
28
    }
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEE5mergeERKS4_
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEE5mergeERKS4_
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEE5mergeERKS4_
138
139
    // todo: rethink the sort method.
140
77
    void sort() {
141
77
        if (sorted) return;
142
143
77
        std::sort(std::begin(events_list), std::end(events_list), Comparator {});
144
77
        sorted = true;
145
77
    }
_ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEE4sortEv
Line
Count
Source
140
39
    void sort() {
141
39
        if (sorted) return;
142
143
39
        std::sort(std::begin(events_list), std::end(events_list), Comparator {});
144
39
        sorted = true;
145
39
    }
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEE4sortEv
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEE4sortEv
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEE4sortEv
_ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEE4sortEv
Line
Count
Source
140
38
    void sort() {
141
38
        if (sorted) return;
142
143
38
        std::sort(std::begin(events_list), std::end(events_list), Comparator {});
144
38
        sorted = true;
145
38
    }
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEE4sortEv
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEE4sortEv
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEE4sortEv
146
147
77
    void write(BufferWritable& buf) const {
148
77
        buf.write_binary(sorted);
149
77
        buf.write_binary(events_list.size());
150
151
77
        for (const auto& events : events_list) {
152
43
            buf.write_binary(events.first);
153
43
            buf.write_binary(events.second.to_ulong());
154
43
        }
155
156
        // This is std::bitset<32>, which will not exceed 32 bits.
157
77
        UInt32 conditions_met_value = (UInt32)conditions_met.to_ulong();
158
77
        buf.write_binary(conditions_met_value);
159
160
77
        buf.write_binary(pattern);
161
77
        buf.write_binary(arg_count);
162
77
    }
_ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEE5writeERNS_14BufferWritableE
Line
Count
Source
147
39
    void write(BufferWritable& buf) const {
148
39
        buf.write_binary(sorted);
149
39
        buf.write_binary(events_list.size());
150
151
39
        for (const auto& events : events_list) {
152
22
            buf.write_binary(events.first);
153
22
            buf.write_binary(events.second.to_ulong());
154
22
        }
155
156
        // This is std::bitset<32>, which will not exceed 32 bits.
157
39
        UInt32 conditions_met_value = (UInt32)conditions_met.to_ulong();
158
39
        buf.write_binary(conditions_met_value);
159
160
39
        buf.write_binary(pattern);
161
39
        buf.write_binary(arg_count);
162
39
    }
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEE5writeERNS_14BufferWritableE
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEE5writeERNS_14BufferWritableE
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEE5writeERNS_14BufferWritableE
_ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEE5writeERNS_14BufferWritableE
Line
Count
Source
147
38
    void write(BufferWritable& buf) const {
148
38
        buf.write_binary(sorted);
149
38
        buf.write_binary(events_list.size());
150
151
38
        for (const auto& events : events_list) {
152
21
            buf.write_binary(events.first);
153
21
            buf.write_binary(events.second.to_ulong());
154
21
        }
155
156
        // This is std::bitset<32>, which will not exceed 32 bits.
157
38
        UInt32 conditions_met_value = (UInt32)conditions_met.to_ulong();
158
38
        buf.write_binary(conditions_met_value);
159
160
38
        buf.write_binary(pattern);
161
38
        buf.write_binary(arg_count);
162
38
    }
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEE5writeERNS_14BufferWritableE
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEE5writeERNS_14BufferWritableE
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEE5writeERNS_14BufferWritableE
163
164
85
    void read(BufferReadable& buf) {
165
85
        buf.read_binary(sorted);
166
167
85
        size_t events_list_size;
168
85
        buf.read_binary(events_list_size);
169
170
85
        events_list.clear();
171
85
        events_list.reserve(events_list_size);
172
173
136
        for (size_t i = 0; i < events_list_size; ++i) {
174
51
            Timestamp timestamp;
175
51
            buf.read_binary(timestamp);
176
177
51
            UInt64 events;
178
51
            buf.read_binary(events);
179
180
51
            events_list.emplace_back(timestamp, Events {events});
181
51
        }
182
183
85
        UInt32 conditions_met_value;
184
85
        buf.read_binary(conditions_met_value);
185
85
        conditions_met = conditions_met_value;
186
187
85
        buf.read_binary(pattern);
188
85
        buf.read_binary(arg_count);
189
85
    }
_ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEE4readERNS_14BufferReadableE
Line
Count
Source
164
43
    void read(BufferReadable& buf) {
165
43
        buf.read_binary(sorted);
166
167
43
        size_t events_list_size;
168
43
        buf.read_binary(events_list_size);
169
170
43
        events_list.clear();
171
43
        events_list.reserve(events_list_size);
172
173
69
        for (size_t i = 0; i < events_list_size; ++i) {
174
26
            Timestamp timestamp;
175
26
            buf.read_binary(timestamp);
176
177
26
            UInt64 events;
178
26
            buf.read_binary(events);
179
180
26
            events_list.emplace_back(timestamp, Events {events});
181
26
        }
182
183
43
        UInt32 conditions_met_value;
184
43
        buf.read_binary(conditions_met_value);
185
43
        conditions_met = conditions_met_value;
186
187
43
        buf.read_binary(pattern);
188
43
        buf.read_binary(arg_count);
189
43
    }
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEE4readERNS_14BufferReadableE
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEE4readERNS_14BufferReadableE
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEE4readERNS_14BufferReadableE
_ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEE4readERNS_14BufferReadableE
Line
Count
Source
164
42
    void read(BufferReadable& buf) {
165
42
        buf.read_binary(sorted);
166
167
42
        size_t events_list_size;
168
42
        buf.read_binary(events_list_size);
169
170
42
        events_list.clear();
171
42
        events_list.reserve(events_list_size);
172
173
67
        for (size_t i = 0; i < events_list_size; ++i) {
174
25
            Timestamp timestamp;
175
25
            buf.read_binary(timestamp);
176
177
25
            UInt64 events;
178
25
            buf.read_binary(events);
179
180
25
            events_list.emplace_back(timestamp, Events {events});
181
25
        }
182
183
42
        UInt32 conditions_met_value;
184
42
        buf.read_binary(conditions_met_value);
185
42
        conditions_met = conditions_met_value;
186
187
42
        buf.read_binary(pattern);
188
42
        buf.read_binary(arg_count);
189
42
    }
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEE4readERNS_14BufferReadableE
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEE4readERNS_14BufferReadableE
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEE4readERNS_14BufferReadableE
190
191
private:
192
    enum class PatternActionType {
193
        SpecificEvent,
194
        AnyEvent,
195
        KleeneStar,
196
        TimeLessOrEqual,
197
        TimeLess,
198
        TimeGreaterOrEqual,
199
        TimeGreater,
200
        TimeEqual
201
    };
202
203
    struct PatternAction final {
204
        PatternActionType type;
205
        std::uint64_t extra;
206
207
        PatternAction() = default;
208
        explicit PatternAction(const PatternActionType type_, const std::uint64_t extra_ = 0)
209
776
                : type {type_}, extra {extra_} {}
_ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEE13PatternActionC2ENS4_17PatternActionTypeEm
Line
Count
Source
209
393
                : type {type_}, extra {extra_} {}
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEE13PatternActionC2ENS4_17PatternActionTypeEm
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEE13PatternActionC2ENS4_17PatternActionTypeEm
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEE13PatternActionC2ENS4_17PatternActionTypeEm
_ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEE13PatternActionC2ENS4_17PatternActionTypeEm
Line
Count
Source
209
383
                : type {type_}, extra {extra_} {}
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEE13PatternActionC2ENS4_17PatternActionTypeEm
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEE13PatternActionC2ENS4_17PatternActionTypeEm
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEE13PatternActionC2ENS4_17PatternActionTypeEm
210
    };
211
212
    using PatternActions = PODArrayWithStackMemory<PatternAction, 64>;
213
214
    Derived& derived() { return assert_cast<Derived&, TypeCheckOnRelease::DISABLE>(*this); }
215
216
383
    void parse_pattern() {
217
383
        actions.clear();
218
383
        actions.emplace_back(PatternActionType::KleeneStar);
219
220
383
        dfa_states.clear();
221
383
        dfa_states.emplace_back(true);
222
223
383
        pattern_has_time = false;
224
383
        conditions_in_pattern.reset();
225
226
383
        const char* pos = pattern.data();
227
383
        const char* begin = pos;
228
383
        const char* end = pos + pattern.size();
229
383
        const size_t event_count = arg_count - 2;
230
231
        // Pattern is checked in fe, so pattern should be valid here, we check it and if pattern is invalid, we return.
232
383
        auto fail_parse = [&]() {
233
5
            actions.clear();
234
5
            dfa_states.clear();
235
5
            conditions_in_pattern.reset();
236
5
            pattern_has_time = false;
237
5
        };
_ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEE13parse_patternEvENKUlvE_clEv
Line
Count
Source
232
3
        auto fail_parse = [&]() {
233
3
            actions.clear();
234
3
            dfa_states.clear();
235
3
            conditions_in_pattern.reset();
236
3
            pattern_has_time = false;
237
3
        };
Unexecuted instantiation: _ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEE13parse_patternEvENKUlvE_clEv
Unexecuted instantiation: _ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEE13parse_patternEvENKUlvE_clEv
Unexecuted instantiation: _ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEE13parse_patternEvENKUlvE_clEv
_ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEE13parse_patternEvENKUlvE_clEv
Line
Count
Source
232
2
        auto fail_parse = [&]() {
233
2
            actions.clear();
234
2
            dfa_states.clear();
235
2
            conditions_in_pattern.reset();
236
2
            pattern_has_time = false;
237
2
        };
Unexecuted instantiation: _ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEE13parse_patternEvENKUlvE_clEv
Unexecuted instantiation: _ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEE13parse_patternEvENKUlvE_clEv
Unexecuted instantiation: _ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEE13parse_patternEvENKUlvE_clEv
238
239
383
        auto throw_exception = [&](const std::string& msg) {
240
5
            LOG(WARNING) << msg + " '" + std::string(pos, end) + "' at position " +
241
5
                                    std::to_string(pos - begin);
242
5
            fail_parse();
243
5
        };
_ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEE13parse_patternEvENKUlRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE_clESC_
Line
Count
Source
239
3
        auto throw_exception = [&](const std::string& msg) {
240
            LOG(WARNING) << msg + " '" + std::string(pos, end) + "' at position " +
241
3
                                    std::to_string(pos - begin);
242
3
            fail_parse();
243
3
        };
Unexecuted instantiation: _ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEE13parse_patternEvENKUlRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE_clESC_
Unexecuted instantiation: _ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEE13parse_patternEvENKUlRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE_clESC_
Unexecuted instantiation: _ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEE13parse_patternEvENKUlRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE_clESC_
_ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEE13parse_patternEvENKUlRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE_clESC_
Line
Count
Source
239
2
        auto throw_exception = [&](const std::string& msg) {
240
            LOG(WARNING) << msg + " '" + std::string(pos, end) + "' at position " +
241
2
                                    std::to_string(pos - begin);
242
2
            fail_parse();
243
2
        };
Unexecuted instantiation: _ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEE13parse_patternEvENKUlRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE_clESC_
Unexecuted instantiation: _ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEE13parse_patternEvENKUlRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE_clESC_
Unexecuted instantiation: _ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEE13parse_patternEvENKUlRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE_clESC_
244
245
1.19k
        auto match = [&pos, end](const char* str) mutable {
246
1.19k
            size_t length = strlen(str);
247
1.19k
            if (pos + length <= end && 0 == memcmp(pos, str, length)) {
248
797
                pos += length;
249
797
                return true;
250
797
            }
251
395
            return false;
252
1.19k
        };
_ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEE13parse_patternEvENUlPKcE_clES6_
Line
Count
Source
245
609
        auto match = [&pos, end](const char* str) mutable {
246
609
            size_t length = strlen(str);
247
609
            if (pos + length <= end && 0 == memcmp(pos, str, length)) {
248
409
                pos += length;
249
409
                return true;
250
409
            }
251
200
            return false;
252
609
        };
Unexecuted instantiation: _ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEE13parse_patternEvENUlPKcE_clES6_
Unexecuted instantiation: _ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEE13parse_patternEvENUlPKcE_clES6_
Unexecuted instantiation: _ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEE13parse_patternEvENUlPKcE_clES6_
_ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEE13parse_patternEvENUlPKcE_clES6_
Line
Count
Source
245
583
        auto match = [&pos, end](const char* str) mutable {
246
583
            size_t length = strlen(str);
247
583
            if (pos + length <= end && 0 == memcmp(pos, str, length)) {
248
388
                pos += length;
249
388
                return true;
250
388
            }
251
195
            return false;
252
583
        };
Unexecuted instantiation: _ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEE13parse_patternEvENUlPKcE_clES6_
Unexecuted instantiation: _ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEE13parse_patternEvENUlPKcE_clES6_
Unexecuted instantiation: _ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEE13parse_patternEvENUlPKcE_clES6_
253
254
398
        auto parse_uint = [&pos, end](auto& value) {
255
398
            const auto* start = pos;
256
797
            while (pos < end && std::isdigit(static_cast<unsigned char>(*pos))) {
257
399
                ++pos;
258
399
            }
259
260
398
            if (pos == start) {
261
1
                return false;
262
1
            }
263
264
397
            StringParser::ParseResult result;
265
397
            value = StringParser::string_to_int<std::decay_t<decltype(value)>, false>(
266
397
                    start, pos - start, &result);
267
397
            return result == StringParser::PARSE_SUCCESS;
268
398
        };
_ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEE13parse_patternEvENKUlRT_E_clImEEDaS6_
Line
Count
Source
254
203
        auto parse_uint = [&pos, end](auto& value) {
255
203
            const auto* start = pos;
256
406
            while (pos < end && std::isdigit(static_cast<unsigned char>(*pos))) {
257
203
                ++pos;
258
203
            }
259
260
203
            if (pos == start) {
261
1
                return false;
262
1
            }
263
264
202
            StringParser::ParseResult result;
265
202
            value = StringParser::string_to_int<std::decay_t<decltype(value)>, false>(
266
202
                    start, pos - start, &result);
267
202
            return result == StringParser::PARSE_SUCCESS;
268
203
        };
Unexecuted instantiation: _ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEE13parse_patternEvENKUlRT_E_clImEEDaS6_
Unexecuted instantiation: _ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEE13parse_patternEvENKUlRT_E_clImEEDaS6_
Unexecuted instantiation: _ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEE13parse_patternEvENKUlRT_E_clImEEDaS6_
_ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEE13parse_patternEvENKUlRT_E_clImEEDaS6_
Line
Count
Source
254
195
        auto parse_uint = [&pos, end](auto& value) {
255
195
            const auto* start = pos;
256
391
            while (pos < end && std::isdigit(static_cast<unsigned char>(*pos))) {
257
196
                ++pos;
258
196
            }
259
260
195
            if (pos == start) {
261
0
                return false;
262
0
            }
263
264
195
            StringParser::ParseResult result;
265
195
            value = StringParser::string_to_int<std::decay_t<decltype(value)>, false>(
266
195
                    start, pos - start, &result);
267
195
            return result == StringParser::PARSE_SUCCESS;
268
195
        };
Unexecuted instantiation: _ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEE13parse_patternEvENKUlRT_E_clImEEDaS6_
Unexecuted instantiation: _ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEE13parse_patternEvENKUlRT_E_clImEEDaS6_
Unexecuted instantiation: _ZZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEE13parse_patternEvENKUlRT_E_clImEEDaS6_
269
270
776
        while (pos < end) {
271
398
            if (match("(?")) {
272
398
                if (match("t")) {
273
3
                    PatternActionType type;
274
275
3
                    if (match("<="))
276
3
                        type = PatternActionType::TimeLessOrEqual;
277
0
                    else if (match("<"))
278
0
                        type = PatternActionType::TimeLess;
279
0
                    else if (match(">="))
280
0
                        type = PatternActionType::TimeGreaterOrEqual;
281
0
                    else if (match(">"))
282
0
                        type = PatternActionType::TimeGreater;
283
0
                    else if (match("=="))
284
0
                        type = PatternActionType::TimeEqual;
285
0
                    else {
286
0
                        throw_exception("Unknown time condition");
287
0
                        return;
288
0
                    }
289
290
3
                    uint64_t duration = 0;
291
3
                    if (!parse_uint(duration)) {
292
1
                        throw_exception("Could not parse number");
293
1
                        return;
294
1
                    }
295
296
2
                    if (actions.back().type != PatternActionType::SpecificEvent &&
297
2
                        actions.back().type != PatternActionType::AnyEvent &&
298
2
                        actions.back().type != PatternActionType::KleeneStar) {
299
0
                        throw_exception(
300
0
                                "Temporal condition should be preceded by an event condition");
301
0
                        return;
302
0
                    }
303
304
2
                    pattern_has_time = true;
305
2
                    actions.emplace_back(type, duration);
306
395
                } else {
307
395
                    UInt64 event_number = 0;
308
395
                    if (!parse_uint(event_number)) {
309
0
                        throw_exception("Could not parse number");
310
0
                        return;
311
0
                    }
312
313
395
                    if (event_number == 0 || event_number > event_count) {
314
4
                        throw_exception("Event number " + std::to_string(event_number) +
315
4
                                        " is out of range");
316
4
                        return;
317
4
                    }
318
319
391
                    const auto event_index = event_number - 1;
320
391
                    actions.emplace_back(PatternActionType::SpecificEvent, event_index);
321
391
                    dfa_states.back().transition = DFATransition::SpecificEvent;
322
391
                    dfa_states.back().event = static_cast<uint32_t>(event_index);
323
391
                    dfa_states.emplace_back();
324
391
                    conditions_in_pattern.set(event_index);
325
391
                }
326
327
393
                if (!match(")")) {
328
0
                    throw_exception("Expected closing parenthesis, found");
329
0
                    return;
330
0
                }
331
332
393
            } else if (match(".*")) {
333
0
                actions.emplace_back(PatternActionType::KleeneStar);
334
0
                dfa_states.back().has_kleene = true;
335
0
            } else if (match(".")) {
336
0
                actions.emplace_back(PatternActionType::AnyEvent);
337
0
                dfa_states.back().transition = DFATransition::AnyEvent;
338
0
                dfa_states.emplace_back();
339
0
            } else {
340
0
                throw_exception("Could not parse pattern, unexpected starting symbol");
341
0
                return;
342
0
            }
343
398
        }
344
383
    }
_ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEE13parse_patternEv
Line
Count
Source
216
193
    void parse_pattern() {
217
193
        actions.clear();
218
193
        actions.emplace_back(PatternActionType::KleeneStar);
219
220
193
        dfa_states.clear();
221
193
        dfa_states.emplace_back(true);
222
223
193
        pattern_has_time = false;
224
193
        conditions_in_pattern.reset();
225
226
193
        const char* pos = pattern.data();
227
193
        const char* begin = pos;
228
193
        const char* end = pos + pattern.size();
229
193
        const size_t event_count = arg_count - 2;
230
231
        // Pattern is checked in fe, so pattern should be valid here, we check it and if pattern is invalid, we return.
232
193
        auto fail_parse = [&]() {
233
193
            actions.clear();
234
193
            dfa_states.clear();
235
193
            conditions_in_pattern.reset();
236
193
            pattern_has_time = false;
237
193
        };
238
239
193
        auto throw_exception = [&](const std::string& msg) {
240
193
            LOG(WARNING) << msg + " '" + std::string(pos, end) + "' at position " +
241
193
                                    std::to_string(pos - begin);
242
193
            fail_parse();
243
193
        };
244
245
193
        auto match = [&pos, end](const char* str) mutable {
246
193
            size_t length = strlen(str);
247
193
            if (pos + length <= end && 0 == memcmp(pos, str, length)) {
248
193
                pos += length;
249
193
                return true;
250
193
            }
251
193
            return false;
252
193
        };
253
254
193
        auto parse_uint = [&pos, end](auto& value) {
255
193
            const auto* start = pos;
256
193
            while (pos < end && std::isdigit(static_cast<unsigned char>(*pos))) {
257
193
                ++pos;
258
193
            }
259
260
193
            if (pos == start) {
261
193
                return false;
262
193
            }
263
264
193
            StringParser::ParseResult result;
265
193
            value = StringParser::string_to_int<std::decay_t<decltype(value)>, false>(
266
193
                    start, pos - start, &result);
267
193
            return result == StringParser::PARSE_SUCCESS;
268
193
        };
269
270
393
        while (pos < end) {
271
203
            if (match("(?")) {
272
203
                if (match("t")) {
273
3
                    PatternActionType type;
274
275
3
                    if (match("<="))
276
3
                        type = PatternActionType::TimeLessOrEqual;
277
0
                    else if (match("<"))
278
0
                        type = PatternActionType::TimeLess;
279
0
                    else if (match(">="))
280
0
                        type = PatternActionType::TimeGreaterOrEqual;
281
0
                    else if (match(">"))
282
0
                        type = PatternActionType::TimeGreater;
283
0
                    else if (match("=="))
284
0
                        type = PatternActionType::TimeEqual;
285
0
                    else {
286
0
                        throw_exception("Unknown time condition");
287
0
                        return;
288
0
                    }
289
290
3
                    uint64_t duration = 0;
291
3
                    if (!parse_uint(duration)) {
292
1
                        throw_exception("Could not parse number");
293
1
                        return;
294
1
                    }
295
296
2
                    if (actions.back().type != PatternActionType::SpecificEvent &&
297
2
                        actions.back().type != PatternActionType::AnyEvent &&
298
2
                        actions.back().type != PatternActionType::KleeneStar) {
299
0
                        throw_exception(
300
0
                                "Temporal condition should be preceded by an event condition");
301
0
                        return;
302
0
                    }
303
304
2
                    pattern_has_time = true;
305
2
                    actions.emplace_back(type, duration);
306
200
                } else {
307
200
                    UInt64 event_number = 0;
308
200
                    if (!parse_uint(event_number)) {
309
0
                        throw_exception("Could not parse number");
310
0
                        return;
311
0
                    }
312
313
200
                    if (event_number == 0 || event_number > event_count) {
314
2
                        throw_exception("Event number " + std::to_string(event_number) +
315
2
                                        " is out of range");
316
2
                        return;
317
2
                    }
318
319
198
                    const auto event_index = event_number - 1;
320
198
                    actions.emplace_back(PatternActionType::SpecificEvent, event_index);
321
198
                    dfa_states.back().transition = DFATransition::SpecificEvent;
322
198
                    dfa_states.back().event = static_cast<uint32_t>(event_index);
323
198
                    dfa_states.emplace_back();
324
198
                    conditions_in_pattern.set(event_index);
325
198
                }
326
327
200
                if (!match(")")) {
328
0
                    throw_exception("Expected closing parenthesis, found");
329
0
                    return;
330
0
                }
331
332
200
            } else if (match(".*")) {
333
0
                actions.emplace_back(PatternActionType::KleeneStar);
334
0
                dfa_states.back().has_kleene = true;
335
0
            } else if (match(".")) {
336
0
                actions.emplace_back(PatternActionType::AnyEvent);
337
0
                dfa_states.back().transition = DFATransition::AnyEvent;
338
0
                dfa_states.emplace_back();
339
0
            } else {
340
0
                throw_exception("Could not parse pattern, unexpected starting symbol");
341
0
                return;
342
0
            }
343
203
        }
344
193
    }
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEE13parse_patternEv
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEE13parse_patternEv
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEE13parse_patternEv
_ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEE13parse_patternEv
Line
Count
Source
216
190
    void parse_pattern() {
217
190
        actions.clear();
218
190
        actions.emplace_back(PatternActionType::KleeneStar);
219
220
190
        dfa_states.clear();
221
190
        dfa_states.emplace_back(true);
222
223
190
        pattern_has_time = false;
224
190
        conditions_in_pattern.reset();
225
226
190
        const char* pos = pattern.data();
227
190
        const char* begin = pos;
228
190
        const char* end = pos + pattern.size();
229
190
        const size_t event_count = arg_count - 2;
230
231
        // Pattern is checked in fe, so pattern should be valid here, we check it and if pattern is invalid, we return.
232
190
        auto fail_parse = [&]() {
233
190
            actions.clear();
234
190
            dfa_states.clear();
235
190
            conditions_in_pattern.reset();
236
190
            pattern_has_time = false;
237
190
        };
238
239
190
        auto throw_exception = [&](const std::string& msg) {
240
190
            LOG(WARNING) << msg + " '" + std::string(pos, end) + "' at position " +
241
190
                                    std::to_string(pos - begin);
242
190
            fail_parse();
243
190
        };
244
245
190
        auto match = [&pos, end](const char* str) mutable {
246
190
            size_t length = strlen(str);
247
190
            if (pos + length <= end && 0 == memcmp(pos, str, length)) {
248
190
                pos += length;
249
190
                return true;
250
190
            }
251
190
            return false;
252
190
        };
253
254
190
        auto parse_uint = [&pos, end](auto& value) {
255
190
            const auto* start = pos;
256
190
            while (pos < end && std::isdigit(static_cast<unsigned char>(*pos))) {
257
190
                ++pos;
258
190
            }
259
260
190
            if (pos == start) {
261
190
                return false;
262
190
            }
263
264
190
            StringParser::ParseResult result;
265
190
            value = StringParser::string_to_int<std::decay_t<decltype(value)>, false>(
266
190
                    start, pos - start, &result);
267
190
            return result == StringParser::PARSE_SUCCESS;
268
190
        };
269
270
383
        while (pos < end) {
271
195
            if (match("(?")) {
272
195
                if (match("t")) {
273
0
                    PatternActionType type;
274
275
0
                    if (match("<="))
276
0
                        type = PatternActionType::TimeLessOrEqual;
277
0
                    else if (match("<"))
278
0
                        type = PatternActionType::TimeLess;
279
0
                    else if (match(">="))
280
0
                        type = PatternActionType::TimeGreaterOrEqual;
281
0
                    else if (match(">"))
282
0
                        type = PatternActionType::TimeGreater;
283
0
                    else if (match("=="))
284
0
                        type = PatternActionType::TimeEqual;
285
0
                    else {
286
0
                        throw_exception("Unknown time condition");
287
0
                        return;
288
0
                    }
289
290
0
                    uint64_t duration = 0;
291
0
                    if (!parse_uint(duration)) {
292
0
                        throw_exception("Could not parse number");
293
0
                        return;
294
0
                    }
295
296
0
                    if (actions.back().type != PatternActionType::SpecificEvent &&
297
0
                        actions.back().type != PatternActionType::AnyEvent &&
298
0
                        actions.back().type != PatternActionType::KleeneStar) {
299
0
                        throw_exception(
300
0
                                "Temporal condition should be preceded by an event condition");
301
0
                        return;
302
0
                    }
303
304
0
                    pattern_has_time = true;
305
0
                    actions.emplace_back(type, duration);
306
195
                } else {
307
195
                    UInt64 event_number = 0;
308
195
                    if (!parse_uint(event_number)) {
309
0
                        throw_exception("Could not parse number");
310
0
                        return;
311
0
                    }
312
313
195
                    if (event_number == 0 || event_number > event_count) {
314
2
                        throw_exception("Event number " + std::to_string(event_number) +
315
2
                                        " is out of range");
316
2
                        return;
317
2
                    }
318
319
193
                    const auto event_index = event_number - 1;
320
193
                    actions.emplace_back(PatternActionType::SpecificEvent, event_index);
321
193
                    dfa_states.back().transition = DFATransition::SpecificEvent;
322
193
                    dfa_states.back().event = static_cast<uint32_t>(event_index);
323
193
                    dfa_states.emplace_back();
324
193
                    conditions_in_pattern.set(event_index);
325
193
                }
326
327
193
                if (!match(")")) {
328
0
                    throw_exception("Expected closing parenthesis, found");
329
0
                    return;
330
0
                }
331
332
193
            } else if (match(".*")) {
333
0
                actions.emplace_back(PatternActionType::KleeneStar);
334
0
                dfa_states.back().has_kleene = true;
335
0
            } else if (match(".")) {
336
0
                actions.emplace_back(PatternActionType::AnyEvent);
337
0
                dfa_states.back().transition = DFATransition::AnyEvent;
338
0
                dfa_states.emplace_back();
339
0
            } else {
340
0
                throw_exception("Could not parse pattern, unexpected starting symbol");
341
0
                return;
342
0
            }
343
195
        }
344
190
    }
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEE13parse_patternEv
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEE13parse_patternEv
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEE13parse_patternEv
345
346
public:
347
    /// Uses a DFA based approach in order to better handle patterns without
348
    /// time assertions.
349
    ///
350
    /// NOTE: This implementation relies on the assumption that the pattern is *small*.
351
    ///
352
    /// This algorithm performs in O(mn) (with m the number of DFA states and N the number
353
    /// of events) with a memory consumption and memory allocations in O(m). It means that
354
    /// if n >>> m (which is expected to be the case), this algorithm can be considered linear.
355
    template <typename EventEntry>
356
37
    bool dfa_match(EventEntry& events_it, const EventEntry events_end) const {
357
37
        using ActiveStates = std::vector<bool>;
358
        /// Those two vectors keep track of which states should be considered for the current
359
        /// event as well as the states which should be considered for the next event.
360
37
        ActiveStates active_states(dfa_states.size(), false);
361
37
        ActiveStates next_active_states(dfa_states.size(), false);
362
37
        active_states[0] = true;
363
364
        /// Keeps track of dead-ends in order not to iterate over all the events to realize that
365
        /// the match failed.
366
37
        size_t n_active = 1;
367
368
77
        for (/* empty */; events_it != events_end && n_active > 0 && !active_states.back();
369
40
             ++events_it) {
370
40
            n_active = 0;
371
40
            next_active_states.assign(dfa_states.size(), false);
372
373
126
            for (size_t state = 0; state < dfa_states.size(); ++state) {
374
86
                if (!active_states[state]) {
375
43
                    continue;
376
43
                }
377
378
43
                switch (dfa_states[state].transition) {
379
0
                case DFATransition::None:
380
0
                    break;
381
0
                case DFATransition::AnyEvent:
382
0
                    next_active_states[state + 1] = true;
383
0
                    ++n_active;
384
0
                    break;
385
43
                case DFATransition::SpecificEvent:
386
43
                    if (events_it->second.test(dfa_states[state].event)) {
387
40
                        next_active_states[state + 1] = true;
388
40
                        ++n_active;
389
40
                    }
390
43
                    break;
391
43
                }
392
393
43
                if (dfa_states[state].has_kleene) {
394
40
                    next_active_states[state] = true;
395
40
                    ++n_active;
396
40
                }
397
43
            }
398
40
            swap(active_states, next_active_states);
399
40
        }
400
401
37
        return active_states.back();
402
37
    }
_ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEE9dfa_matchIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEESt6bitsetILm32EEESt6vectorISE_SaISE_EEEEEEbRT_SL_
Line
Count
Source
356
37
    bool dfa_match(EventEntry& events_it, const EventEntry events_end) const {
357
37
        using ActiveStates = std::vector<bool>;
358
        /// Those two vectors keep track of which states should be considered for the current
359
        /// event as well as the states which should be considered for the next event.
360
37
        ActiveStates active_states(dfa_states.size(), false);
361
37
        ActiveStates next_active_states(dfa_states.size(), false);
362
37
        active_states[0] = true;
363
364
        /// Keeps track of dead-ends in order not to iterate over all the events to realize that
365
        /// the match failed.
366
37
        size_t n_active = 1;
367
368
77
        for (/* empty */; events_it != events_end && n_active > 0 && !active_states.back();
369
40
             ++events_it) {
370
40
            n_active = 0;
371
40
            next_active_states.assign(dfa_states.size(), false);
372
373
126
            for (size_t state = 0; state < dfa_states.size(); ++state) {
374
86
                if (!active_states[state]) {
375
43
                    continue;
376
43
                }
377
378
43
                switch (dfa_states[state].transition) {
379
0
                case DFATransition::None:
380
0
                    break;
381
0
                case DFATransition::AnyEvent:
382
0
                    next_active_states[state + 1] = true;
383
0
                    ++n_active;
384
0
                    break;
385
43
                case DFATransition::SpecificEvent:
386
43
                    if (events_it->second.test(dfa_states[state].event)) {
387
40
                        next_active_states[state + 1] = true;
388
40
                        ++n_active;
389
40
                    }
390
43
                    break;
391
43
                }
392
393
43
                if (dfa_states[state].has_kleene) {
394
40
                    next_active_states[state] = true;
395
40
                    ++n_active;
396
40
                }
397
43
            }
398
40
            swap(active_states, next_active_states);
399
40
        }
400
401
37
        return active_states.back();
402
37
    }
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEE9dfa_matchIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_16TimeStampNsValueESt6bitsetILm32EEESt6vectorISC_SaISC_EEEEEEbRT_SJ_
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEE9dfa_matchIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_11DateV2ValueINS_15DateV2ValueTypeEEESt6bitsetILm32EEESt6vectorISE_SaISE_EEEEEEbRT_SL_
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEE9dfa_matchIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_16TimestampTzValueESt6bitsetILm32EEESt6vectorISC_SaISC_EEEEEEbRT_SJ_
403
404
    template <typename EventEntry>
405
49
    bool backtracking_match(EventEntry& events_it, const EventEntry events_end) const {
406
49
        const auto action_begin = std::begin(actions);
407
49
        const auto action_end = std::end(actions);
408
49
        auto action_it = action_begin;
409
410
49
        const auto events_begin = events_it;
411
49
        auto base_it = events_it;
412
413
        /// an iterator to action plus an iterator to row in events list plus timestamp at the start of sequence
414
49
        using backtrack_info = std::tuple<decltype(action_it), EventEntry, EventEntry>;
415
49
        std::stack<backtrack_info> back_stack;
416
417
        /// backtrack if possible
418
49
        const auto do_backtrack = [&] {
419
2
            while (!back_stack.empty()) {
420
2
                auto& top = back_stack.top();
421
422
2
                action_it = std::get<0>(top);
423
2
                events_it = std::next(std::get<1>(top));
424
2
                base_it = std::get<2>(top);
425
426
2
                back_stack.pop();
427
428
2
                if (events_it != events_end) return true;
429
2
            }
430
431
0
            return false;
432
2
        };
_ZZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEE18backtracking_matchIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEESt6bitsetILm32EEESt6vectorISE_SaISE_EEEEEEbRT_SL_ENKUlvE_clEv
Line
Count
Source
418
2
        const auto do_backtrack = [&] {
419
2
            while (!back_stack.empty()) {
420
2
                auto& top = back_stack.top();
421
422
2
                action_it = std::get<0>(top);
423
2
                events_it = std::next(std::get<1>(top));
424
2
                base_it = std::get<2>(top);
425
426
2
                back_stack.pop();
427
428
2
                if (events_it != events_end) return true;
429
2
            }
430
431
0
            return false;
432
2
        };
Unexecuted instantiation: _ZZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEE18backtracking_matchIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_16TimeStampNsValueESt6bitsetILm32EEESt6vectorISC_SaISC_EEEEEEbRT_SJ_ENKUlvE_clEv
Unexecuted instantiation: _ZZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEE18backtracking_matchIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_11DateV2ValueINS_15DateV2ValueTypeEEESt6bitsetILm32EEESt6vectorISE_SaISE_EEEEEEbRT_SL_ENKUlvE_clEv
Unexecuted instantiation: _ZZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEE18backtracking_matchIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_16TimestampTzValueESt6bitsetILm32EEESt6vectorISC_SaISC_EEEEEEbRT_SJ_ENKUlvE_clEv
Unexecuted instantiation: _ZZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEE18backtracking_matchIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEESt6bitsetILm32EEESt6vectorISE_SaISE_EEEEEEbRT_SL_ENKUlvE_clEv
Unexecuted instantiation: _ZZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEE18backtracking_matchIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_16TimeStampNsValueESt6bitsetILm32EEESt6vectorISC_SaISC_EEEEEEbRT_SJ_ENKUlvE_clEv
Unexecuted instantiation: _ZZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEE18backtracking_matchIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_11DateV2ValueINS_15DateV2ValueTypeEEESt6bitsetILm32EEESt6vectorISE_SaISE_EEEEEEbRT_SL_ENKUlvE_clEv
Unexecuted instantiation: _ZZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEE18backtracking_matchIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_16TimestampTzValueESt6bitsetILm32EEESt6vectorISC_SaISC_EEEEEEbRT_SJ_ENKUlvE_clEv
433
434
49
        size_t i = 0;
435
162
        while (action_it != action_end && events_it != events_end) {
436
113
            if (action_it->type == PatternActionType::SpecificEvent) {
437
60
                if (events_it->second.test(action_it->extra)) {
438
                    /// move to the next action and events
439
58
                    base_it = events_it;
440
58
                    ++action_it, ++events_it;
441
58
                } else if (!do_backtrack())
442
                    /// backtracking failed, bail out
443
0
                    break;
444
60
            } else if (action_it->type == PatternActionType::AnyEvent) {
445
0
                base_it = events_it;
446
0
                ++action_it, ++events_it;
447
53
            } else if (action_it->type == PatternActionType::KleeneStar) {
448
49
                back_stack.emplace(action_it, events_it, base_it);
449
49
                base_it = events_it;
450
49
                ++action_it;
451
49
            } else if (action_it->type == PatternActionType::TimeLessOrEqual) {
452
4
                if (events_it->first.datetime_diff_in_seconds(base_it->first) <= action_it->extra) {
453
                    /// condition satisfied, move onto next action
454
4
                    back_stack.emplace(action_it, events_it, base_it);
455
4
                    base_it = events_it;
456
4
                    ++action_it;
457
4
                } else if (!do_backtrack())
458
0
                    break;
459
4
            } else if (action_it->type == PatternActionType::TimeLess) {
460
0
                if (events_it->first.datetime_diff_in_seconds(base_it->first) < action_it->extra) {
461
0
                    back_stack.emplace(action_it, events_it, base_it);
462
0
                    base_it = events_it;
463
0
                    ++action_it;
464
0
                } else if (!do_backtrack())
465
0
                    break;
466
0
            } else if (action_it->type == PatternActionType::TimeGreaterOrEqual) {
467
0
                if (events_it->first.datetime_diff_in_seconds(base_it->first) >= action_it->extra) {
468
0
                    back_stack.emplace(action_it, events_it, base_it);
469
0
                    base_it = events_it;
470
0
                    ++action_it;
471
0
                } else if (++events_it == events_end && !do_backtrack())
472
0
                    break;
473
0
            } else if (action_it->type == PatternActionType::TimeGreater) {
474
0
                if (events_it->first.datetime_diff_in_seconds(base_it->first) > action_it->extra) {
475
0
                    back_stack.emplace(action_it, events_it, base_it);
476
0
                    base_it = events_it;
477
0
                    ++action_it;
478
0
                } else if (++events_it == events_end && !do_backtrack())
479
0
                    break;
480
0
            } else if (action_it->type == PatternActionType::TimeEqual) {
481
0
                if (events_it->first.datetime_diff_in_seconds(base_it->first) == action_it->extra) {
482
0
                    back_stack.emplace(action_it, events_it, base_it);
483
0
                    base_it = events_it;
484
0
                    ++action_it;
485
0
                } else if (++events_it == events_end && !do_backtrack())
486
0
                    break;
487
0
            } else {
488
0
                LOG(WARNING) << "Unknown PatternActionType";
489
0
                return false;
490
0
            }
491
492
113
            if (++i > sequence_match_max_iterations) {
493
0
                LOG(WARNING)
494
0
                        << "Pattern application proves too difficult, exceeding max iterations (" +
495
0
                                   std::to_string(sequence_match_max_iterations) + ")";
496
0
                return false;
497
0
            }
498
113
        }
499
500
        /// if there are some actions remaining
501
49
        if (action_it != action_end) {
502
            /// match multiple empty strings at end
503
0
            while (action_it->type == PatternActionType::KleeneStar ||
504
0
                   action_it->type == PatternActionType::TimeLessOrEqual ||
505
0
                   action_it->type == PatternActionType::TimeLess ||
506
0
                   (action_it->type == PatternActionType::TimeGreaterOrEqual &&
507
0
                    action_it->extra == 0))
508
0
                ++action_it;
509
0
        }
510
511
49
        if (events_it == events_begin) ++events_it;
512
513
49
        return action_it == action_end;
514
49
    }
_ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEE18backtracking_matchIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEESt6bitsetILm32EEESt6vectorISE_SaISE_EEEEEEbRT_SL_
Line
Count
Source
405
2
    bool backtracking_match(EventEntry& events_it, const EventEntry events_end) const {
406
2
        const auto action_begin = std::begin(actions);
407
2
        const auto action_end = std::end(actions);
408
2
        auto action_it = action_begin;
409
410
2
        const auto events_begin = events_it;
411
2
        auto base_it = events_it;
412
413
        /// an iterator to action plus an iterator to row in events list plus timestamp at the start of sequence
414
2
        using backtrack_info = std::tuple<decltype(action_it), EventEntry, EventEntry>;
415
2
        std::stack<backtrack_info> back_stack;
416
417
        /// backtrack if possible
418
2
        const auto do_backtrack = [&] {
419
2
            while (!back_stack.empty()) {
420
2
                auto& top = back_stack.top();
421
422
2
                action_it = std::get<0>(top);
423
2
                events_it = std::next(std::get<1>(top));
424
2
                base_it = std::get<2>(top);
425
426
2
                back_stack.pop();
427
428
2
                if (events_it != events_end) return true;
429
2
            }
430
431
2
            return false;
432
2
        };
433
434
2
        size_t i = 0;
435
14
        while (action_it != action_end && events_it != events_end) {
436
12
            if (action_it->type == PatternActionType::SpecificEvent) {
437
6
                if (events_it->second.test(action_it->extra)) {
438
                    /// move to the next action and events
439
4
                    base_it = events_it;
440
4
                    ++action_it, ++events_it;
441
4
                } else if (!do_backtrack())
442
                    /// backtracking failed, bail out
443
0
                    break;
444
6
            } else if (action_it->type == PatternActionType::AnyEvent) {
445
0
                base_it = events_it;
446
0
                ++action_it, ++events_it;
447
6
            } else if (action_it->type == PatternActionType::KleeneStar) {
448
2
                back_stack.emplace(action_it, events_it, base_it);
449
2
                base_it = events_it;
450
2
                ++action_it;
451
4
            } else if (action_it->type == PatternActionType::TimeLessOrEqual) {
452
4
                if (events_it->first.datetime_diff_in_seconds(base_it->first) <= action_it->extra) {
453
                    /// condition satisfied, move onto next action
454
4
                    back_stack.emplace(action_it, events_it, base_it);
455
4
                    base_it = events_it;
456
4
                    ++action_it;
457
4
                } else if (!do_backtrack())
458
0
                    break;
459
4
            } else if (action_it->type == PatternActionType::TimeLess) {
460
0
                if (events_it->first.datetime_diff_in_seconds(base_it->first) < action_it->extra) {
461
0
                    back_stack.emplace(action_it, events_it, base_it);
462
0
                    base_it = events_it;
463
0
                    ++action_it;
464
0
                } else if (!do_backtrack())
465
0
                    break;
466
0
            } else if (action_it->type == PatternActionType::TimeGreaterOrEqual) {
467
0
                if (events_it->first.datetime_diff_in_seconds(base_it->first) >= action_it->extra) {
468
0
                    back_stack.emplace(action_it, events_it, base_it);
469
0
                    base_it = events_it;
470
0
                    ++action_it;
471
0
                } else if (++events_it == events_end && !do_backtrack())
472
0
                    break;
473
0
            } else if (action_it->type == PatternActionType::TimeGreater) {
474
0
                if (events_it->first.datetime_diff_in_seconds(base_it->first) > action_it->extra) {
475
0
                    back_stack.emplace(action_it, events_it, base_it);
476
0
                    base_it = events_it;
477
0
                    ++action_it;
478
0
                } else if (++events_it == events_end && !do_backtrack())
479
0
                    break;
480
0
            } else if (action_it->type == PatternActionType::TimeEqual) {
481
0
                if (events_it->first.datetime_diff_in_seconds(base_it->first) == action_it->extra) {
482
0
                    back_stack.emplace(action_it, events_it, base_it);
483
0
                    base_it = events_it;
484
0
                    ++action_it;
485
0
                } else if (++events_it == events_end && !do_backtrack())
486
0
                    break;
487
0
            } else {
488
0
                LOG(WARNING) << "Unknown PatternActionType";
489
0
                return false;
490
0
            }
491
492
12
            if (++i > sequence_match_max_iterations) {
493
0
                LOG(WARNING)
494
0
                        << "Pattern application proves too difficult, exceeding max iterations (" +
495
0
                                   std::to_string(sequence_match_max_iterations) + ")";
496
0
                return false;
497
0
            }
498
12
        }
499
500
        /// if there are some actions remaining
501
2
        if (action_it != action_end) {
502
            /// match multiple empty strings at end
503
0
            while (action_it->type == PatternActionType::KleeneStar ||
504
0
                   action_it->type == PatternActionType::TimeLessOrEqual ||
505
0
                   action_it->type == PatternActionType::TimeLess ||
506
0
                   (action_it->type == PatternActionType::TimeGreaterOrEqual &&
507
0
                    action_it->extra == 0))
508
0
                ++action_it;
509
0
        }
510
511
2
        if (events_it == events_begin) ++events_it;
512
513
2
        return action_it == action_end;
514
2
    }
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEE18backtracking_matchIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_16TimeStampNsValueESt6bitsetILm32EEESt6vectorISC_SaISC_EEEEEEbRT_SJ_
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEE18backtracking_matchIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_11DateV2ValueINS_15DateV2ValueTypeEEESt6bitsetILm32EEESt6vectorISE_SaISE_EEEEEEbRT_SL_
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEE18backtracking_matchIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_16TimestampTzValueESt6bitsetILm32EEESt6vectorISC_SaISC_EEEEEEbRT_SJ_
_ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEE18backtracking_matchIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEESt6bitsetILm32EEESt6vectorISE_SaISE_EEEEEEbRT_SL_
Line
Count
Source
405
47
    bool backtracking_match(EventEntry& events_it, const EventEntry events_end) const {
406
47
        const auto action_begin = std::begin(actions);
407
47
        const auto action_end = std::end(actions);
408
47
        auto action_it = action_begin;
409
410
47
        const auto events_begin = events_it;
411
47
        auto base_it = events_it;
412
413
        /// an iterator to action plus an iterator to row in events list plus timestamp at the start of sequence
414
47
        using backtrack_info = std::tuple<decltype(action_it), EventEntry, EventEntry>;
415
47
        std::stack<backtrack_info> back_stack;
416
417
        /// backtrack if possible
418
47
        const auto do_backtrack = [&] {
419
47
            while (!back_stack.empty()) {
420
47
                auto& top = back_stack.top();
421
422
47
                action_it = std::get<0>(top);
423
47
                events_it = std::next(std::get<1>(top));
424
47
                base_it = std::get<2>(top);
425
426
47
                back_stack.pop();
427
428
47
                if (events_it != events_end) return true;
429
47
            }
430
431
47
            return false;
432
47
        };
433
434
47
        size_t i = 0;
435
148
        while (action_it != action_end && events_it != events_end) {
436
101
            if (action_it->type == PatternActionType::SpecificEvent) {
437
54
                if (events_it->second.test(action_it->extra)) {
438
                    /// move to the next action and events
439
54
                    base_it = events_it;
440
54
                    ++action_it, ++events_it;
441
54
                } else if (!do_backtrack())
442
                    /// backtracking failed, bail out
443
0
                    break;
444
54
            } else if (action_it->type == PatternActionType::AnyEvent) {
445
0
                base_it = events_it;
446
0
                ++action_it, ++events_it;
447
47
            } else if (action_it->type == PatternActionType::KleeneStar) {
448
47
                back_stack.emplace(action_it, events_it, base_it);
449
47
                base_it = events_it;
450
47
                ++action_it;
451
47
            } else if (action_it->type == PatternActionType::TimeLessOrEqual) {
452
0
                if (events_it->first.datetime_diff_in_seconds(base_it->first) <= action_it->extra) {
453
                    /// condition satisfied, move onto next action
454
0
                    back_stack.emplace(action_it, events_it, base_it);
455
0
                    base_it = events_it;
456
0
                    ++action_it;
457
0
                } else if (!do_backtrack())
458
0
                    break;
459
0
            } else if (action_it->type == PatternActionType::TimeLess) {
460
0
                if (events_it->first.datetime_diff_in_seconds(base_it->first) < action_it->extra) {
461
0
                    back_stack.emplace(action_it, events_it, base_it);
462
0
                    base_it = events_it;
463
0
                    ++action_it;
464
0
                } else if (!do_backtrack())
465
0
                    break;
466
0
            } else if (action_it->type == PatternActionType::TimeGreaterOrEqual) {
467
0
                if (events_it->first.datetime_diff_in_seconds(base_it->first) >= action_it->extra) {
468
0
                    back_stack.emplace(action_it, events_it, base_it);
469
0
                    base_it = events_it;
470
0
                    ++action_it;
471
0
                } else if (++events_it == events_end && !do_backtrack())
472
0
                    break;
473
0
            } else if (action_it->type == PatternActionType::TimeGreater) {
474
0
                if (events_it->first.datetime_diff_in_seconds(base_it->first) > action_it->extra) {
475
0
                    back_stack.emplace(action_it, events_it, base_it);
476
0
                    base_it = events_it;
477
0
                    ++action_it;
478
0
                } else if (++events_it == events_end && !do_backtrack())
479
0
                    break;
480
0
            } else if (action_it->type == PatternActionType::TimeEqual) {
481
0
                if (events_it->first.datetime_diff_in_seconds(base_it->first) == action_it->extra) {
482
0
                    back_stack.emplace(action_it, events_it, base_it);
483
0
                    base_it = events_it;
484
0
                    ++action_it;
485
0
                } else if (++events_it == events_end && !do_backtrack())
486
0
                    break;
487
0
            } else {
488
0
                LOG(WARNING) << "Unknown PatternActionType";
489
0
                return false;
490
0
            }
491
492
101
            if (++i > sequence_match_max_iterations) {
493
0
                LOG(WARNING)
494
0
                        << "Pattern application proves too difficult, exceeding max iterations (" +
495
0
                                   std::to_string(sequence_match_max_iterations) + ")";
496
0
                return false;
497
0
            }
498
101
        }
499
500
        /// if there are some actions remaining
501
47
        if (action_it != action_end) {
502
            /// match multiple empty strings at end
503
0
            while (action_it->type == PatternActionType::KleeneStar ||
504
0
                   action_it->type == PatternActionType::TimeLessOrEqual ||
505
0
                   action_it->type == PatternActionType::TimeLess ||
506
0
                   (action_it->type == PatternActionType::TimeGreaterOrEqual &&
507
0
                    action_it->extra == 0))
508
0
                ++action_it;
509
0
        }
510
511
47
        if (events_it == events_begin) ++events_it;
512
513
47
        return action_it == action_end;
514
47
    }
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEE18backtracking_matchIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_16TimeStampNsValueESt6bitsetILm32EEESt6vectorISC_SaISC_EEEEEEbRT_SJ_
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEE18backtracking_matchIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_11DateV2ValueINS_15DateV2ValueTypeEEESt6bitsetILm32EEESt6vectorISE_SaISE_EEEEEEbRT_SL_
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEE18backtracking_matchIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_16TimestampTzValueESt6bitsetILm32EEESt6vectorISC_SaISC_EEEEEEbRT_SJ_
515
516
    /// Splits the pattern into deterministic parts separated by non-deterministic fragments
517
    /// (time constraints and Kleene stars), and tries to match the deterministic parts in their specified order,
518
    /// ignoring the non-deterministic fragments.
519
    /// This function can quickly check that a full match is not possible if some deterministic fragment is missing.
520
    template <typename EventEntry>
521
    bool could_match_deterministic_parts(const EventEntry events_begin, const EventEntry events_end,
522
40
                                         bool limit_iterations = true) const {
523
40
        size_t events_processed = 0;
524
40
        auto events_it = events_begin;
525
526
40
        const auto actions_end = std::end(actions);
527
40
        auto actions_it = std::begin(actions);
528
40
        auto det_part_begin = actions_it;
529
530
40
        auto match_deterministic_part = [&events_it, events_end, &events_processed, det_part_begin,
531
82
                                         actions_it, limit_iterations]() {
532
82
            auto events_it_init = events_it;
533
82
            auto det_part_it = det_part_begin;
534
535
82
            while (det_part_it != actions_it && events_it != events_end) {
536
                /// matching any event
537
0
                if (det_part_it->type == PatternActionType::AnyEvent) ++events_it, ++det_part_it;
538
539
                /// matching specific event
540
0
                else {
541
0
                    if (events_it->second.test(det_part_it->extra)) ++events_it, ++det_part_it;
542
543
                    /// abandon current matching, try to match the deterministic fragment further in the list
544
0
                    else {
545
0
                        events_it = ++events_it_init;
546
0
                        det_part_it = det_part_begin;
547
0
                    }
548
0
                }
549
550
0
                if (limit_iterations && ++events_processed > sequence_match_max_iterations) {
551
0
                    LOG(WARNING) << "Pattern application proves too difficult, exceeding max "
552
0
                                    "iterations are " +
553
0
                                            std::to_string(sequence_match_max_iterations);
554
0
                    return false;
555
0
                }
556
0
            }
557
558
82
            return det_part_it == actions_it;
559
82
        };
_ZZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEE31could_match_deterministic_partsIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEESt6bitsetILm32EEESt6vectorISE_SaISE_EEEEEEbT_SL_bENKUlvE_clEv
Line
Count
Source
531
6
                                         actions_it, limit_iterations]() {
532
6
            auto events_it_init = events_it;
533
6
            auto det_part_it = det_part_begin;
534
535
6
            while (det_part_it != actions_it && events_it != events_end) {
536
                /// matching any event
537
0
                if (det_part_it->type == PatternActionType::AnyEvent) ++events_it, ++det_part_it;
538
539
                /// matching specific event
540
0
                else {
541
0
                    if (events_it->second.test(det_part_it->extra)) ++events_it, ++det_part_it;
542
543
                    /// abandon current matching, try to match the deterministic fragment further in the list
544
0
                    else {
545
0
                        events_it = ++events_it_init;
546
0
                        det_part_it = det_part_begin;
547
0
                    }
548
0
                }
549
550
0
                if (limit_iterations && ++events_processed > sequence_match_max_iterations) {
551
0
                    LOG(WARNING) << "Pattern application proves too difficult, exceeding max "
552
0
                                    "iterations are " +
553
0
                                            std::to_string(sequence_match_max_iterations);
554
0
                    return false;
555
0
                }
556
0
            }
557
558
6
            return det_part_it == actions_it;
559
6
        };
Unexecuted instantiation: _ZZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEE31could_match_deterministic_partsIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_16TimeStampNsValueESt6bitsetILm32EEESt6vectorISC_SaISC_EEEEEEbT_SJ_bENKUlvE_clEv
Unexecuted instantiation: _ZZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEE31could_match_deterministic_partsIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_11DateV2ValueINS_15DateV2ValueTypeEEESt6bitsetILm32EEESt6vectorISE_SaISE_EEEEEEbT_SL_bENKUlvE_clEv
Unexecuted instantiation: _ZZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEE31could_match_deterministic_partsIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_16TimestampTzValueESt6bitsetILm32EEESt6vectorISC_SaISC_EEEEEEbT_SJ_bENKUlvE_clEv
_ZZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEE31could_match_deterministic_partsIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEESt6bitsetILm32EEESt6vectorISE_SaISE_EEEEEEbT_SL_bENKUlvE_clEv
Line
Count
Source
531
76
                                         actions_it, limit_iterations]() {
532
76
            auto events_it_init = events_it;
533
76
            auto det_part_it = det_part_begin;
534
535
76
            while (det_part_it != actions_it && events_it != events_end) {
536
                /// matching any event
537
0
                if (det_part_it->type == PatternActionType::AnyEvent) ++events_it, ++det_part_it;
538
539
                /// matching specific event
540
0
                else {
541
0
                    if (events_it->second.test(det_part_it->extra)) ++events_it, ++det_part_it;
542
543
                    /// abandon current matching, try to match the deterministic fragment further in the list
544
0
                    else {
545
0
                        events_it = ++events_it_init;
546
0
                        det_part_it = det_part_begin;
547
0
                    }
548
0
                }
549
550
0
                if (limit_iterations && ++events_processed > sequence_match_max_iterations) {
551
0
                    LOG(WARNING) << "Pattern application proves too difficult, exceeding max "
552
0
                                    "iterations are " +
553
0
                                            std::to_string(sequence_match_max_iterations);
554
0
                    return false;
555
0
                }
556
0
            }
557
558
76
            return det_part_it == actions_it;
559
76
        };
Unexecuted instantiation: _ZZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEE31could_match_deterministic_partsIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_16TimeStampNsValueESt6bitsetILm32EEESt6vectorISC_SaISC_EEEEEEbT_SJ_bENKUlvE_clEv
Unexecuted instantiation: _ZZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEE31could_match_deterministic_partsIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_11DateV2ValueINS_15DateV2ValueTypeEEESt6bitsetILm32EEESt6vectorISE_SaISE_EEEEEEbT_SL_bENKUlvE_clEv
Unexecuted instantiation: _ZZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEE31could_match_deterministic_partsIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_16TimestampTzValueESt6bitsetILm32EEESt6vectorISC_SaISC_EEEEEEbT_SJ_bENKUlvE_clEv
560
561
128
        for (; actions_it != actions_end; ++actions_it)
562
88
            if (actions_it->type != PatternActionType::SpecificEvent &&
563
88
                actions_it->type != PatternActionType::AnyEvent) {
564
42
                if (!match_deterministic_part()) return false;
565
42
                det_part_begin = std::next(actions_it);
566
42
            }
567
568
40
        return match_deterministic_part();
569
40
    }
_ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEE31could_match_deterministic_partsIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEESt6bitsetILm32EEESt6vectorISE_SaISE_EEEEEEbT_SL_b
Line
Count
Source
522
2
                                         bool limit_iterations = true) const {
523
2
        size_t events_processed = 0;
524
2
        auto events_it = events_begin;
525
526
2
        const auto actions_end = std::end(actions);
527
2
        auto actions_it = std::begin(actions);
528
2
        auto det_part_begin = actions_it;
529
530
2
        auto match_deterministic_part = [&events_it, events_end, &events_processed, det_part_begin,
531
2
                                         actions_it, limit_iterations]() {
532
2
            auto events_it_init = events_it;
533
2
            auto det_part_it = det_part_begin;
534
535
2
            while (det_part_it != actions_it && events_it != events_end) {
536
                /// matching any event
537
2
                if (det_part_it->type == PatternActionType::AnyEvent) ++events_it, ++det_part_it;
538
539
                /// matching specific event
540
2
                else {
541
2
                    if (events_it->second.test(det_part_it->extra)) ++events_it, ++det_part_it;
542
543
                    /// abandon current matching, try to match the deterministic fragment further in the list
544
2
                    else {
545
2
                        events_it = ++events_it_init;
546
2
                        det_part_it = det_part_begin;
547
2
                    }
548
2
                }
549
550
2
                if (limit_iterations && ++events_processed > sequence_match_max_iterations) {
551
2
                    LOG(WARNING) << "Pattern application proves too difficult, exceeding max "
552
2
                                    "iterations are " +
553
2
                                            std::to_string(sequence_match_max_iterations);
554
2
                    return false;
555
2
                }
556
2
            }
557
558
2
            return det_part_it == actions_it;
559
2
        };
560
561
10
        for (; actions_it != actions_end; ++actions_it)
562
8
            if (actions_it->type != PatternActionType::SpecificEvent &&
563
8
                actions_it->type != PatternActionType::AnyEvent) {
564
4
                if (!match_deterministic_part()) return false;
565
4
                det_part_begin = std::next(actions_it);
566
4
            }
567
568
2
        return match_deterministic_part();
569
2
    }
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEE31could_match_deterministic_partsIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_16TimeStampNsValueESt6bitsetILm32EEESt6vectorISC_SaISC_EEEEEEbT_SJ_b
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEE31could_match_deterministic_partsIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_11DateV2ValueINS_15DateV2ValueTypeEEESt6bitsetILm32EEESt6vectorISE_SaISE_EEEEEEbT_SL_b
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEE31could_match_deterministic_partsIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_16TimestampTzValueESt6bitsetILm32EEESt6vectorISC_SaISC_EEEEEEbT_SJ_b
_ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEE31could_match_deterministic_partsIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEESt6bitsetILm32EEESt6vectorISE_SaISE_EEEEEEbT_SL_b
Line
Count
Source
522
38
                                         bool limit_iterations = true) const {
523
38
        size_t events_processed = 0;
524
38
        auto events_it = events_begin;
525
526
38
        const auto actions_end = std::end(actions);
527
38
        auto actions_it = std::begin(actions);
528
38
        auto det_part_begin = actions_it;
529
530
38
        auto match_deterministic_part = [&events_it, events_end, &events_processed, det_part_begin,
531
38
                                         actions_it, limit_iterations]() {
532
38
            auto events_it_init = events_it;
533
38
            auto det_part_it = det_part_begin;
534
535
38
            while (det_part_it != actions_it && events_it != events_end) {
536
                /// matching any event
537
38
                if (det_part_it->type == PatternActionType::AnyEvent) ++events_it, ++det_part_it;
538
539
                /// matching specific event
540
38
                else {
541
38
                    if (events_it->second.test(det_part_it->extra)) ++events_it, ++det_part_it;
542
543
                    /// abandon current matching, try to match the deterministic fragment further in the list
544
38
                    else {
545
38
                        events_it = ++events_it_init;
546
38
                        det_part_it = det_part_begin;
547
38
                    }
548
38
                }
549
550
38
                if (limit_iterations && ++events_processed > sequence_match_max_iterations) {
551
38
                    LOG(WARNING) << "Pattern application proves too difficult, exceeding max "
552
38
                                    "iterations are " +
553
38
                                            std::to_string(sequence_match_max_iterations);
554
38
                    return false;
555
38
                }
556
38
            }
557
558
38
            return det_part_it == actions_it;
559
38
        };
560
561
118
        for (; actions_it != actions_end; ++actions_it)
562
80
            if (actions_it->type != PatternActionType::SpecificEvent &&
563
80
                actions_it->type != PatternActionType::AnyEvent) {
564
38
                if (!match_deterministic_part()) return false;
565
38
                det_part_begin = std::next(actions_it);
566
38
            }
567
568
38
        return match_deterministic_part();
569
38
    }
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEE31could_match_deterministic_partsIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_16TimeStampNsValueESt6bitsetILm32EEESt6vectorISC_SaISC_EEEEEEbT_SJ_b
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEE31could_match_deterministic_partsIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_11DateV2ValueINS_15DateV2ValueTypeEEESt6bitsetILm32EEESt6vectorISE_SaISE_EEEEEEbT_SL_b
Unexecuted instantiation: _ZNK5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEE31could_match_deterministic_partsIN9__gnu_cxx17__normal_iteratorIPKSt4pairINS_16TimestampTzValueESt6bitsetILm32EEESt6vectorISC_SaISC_EEEEEEbT_SJ_b
570
571
private:
572
    enum class DFATransition : char {
573
        ///   .-------.
574
        ///   |       |
575
        ///   `-------'
576
        None,
577
        ///   .-------.  (?[0-9])
578
        ///   |       | ----------
579
        ///   `-------'
580
        SpecificEvent,
581
        ///   .-------.      .
582
        ///   |       | ----------
583
        ///   `-------'
584
        AnyEvent,
585
    };
586
587
    struct DFAState {
588
        explicit DFAState(bool has_kleene_ = false)
589
774
                : has_kleene {has_kleene_}, event {0}, transition {DFATransition::None} {}
_ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEE8DFAStateC2Eb
Line
Count
Source
589
391
                : has_kleene {has_kleene_}, event {0}, transition {DFATransition::None} {}
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEE8DFAStateC2Eb
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEE8DFAStateC2Eb
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEE8DFAStateC2Eb
_ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEE8DFAStateC2Eb
Line
Count
Source
589
383
                : has_kleene {has_kleene_}, event {0}, transition {DFATransition::None} {}
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEE8DFAStateC2Eb
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEE8DFAStateC2Eb
Unexecuted instantiation: _ZN5doris34AggregateFunctionSequenceMatchDataILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEE8DFAStateC2Eb
590
591
        ///   .-------.
592
        ///   |       | - - -
593
        ///   `-------'
594
        ///     |_^
595
        bool has_kleene;
596
        /// In the case of a state transitions with a `SpecificEvent`,
597
        /// `event` contains the value of the event.
598
        uint32_t event;
599
        /// The kind of transition out of this state.
600
        DFATransition transition;
601
    };
602
603
    using DFAStates = std::vector<DFAState>;
604
605
public:
606
    bool sorted = true;
607
    std::vector<TimestampEvents> events_list;
608
    // sequenceMatch conditions met at least once in events_list
609
    std::bitset<MAX_EVENTS> conditions_met;
610
    // sequenceMatch conditions met at least once in the pattern
611
    std::bitset<MAX_EVENTS> conditions_in_pattern;
612
    // `True` if the parsed pattern contains time assertions (?t...), `false` otherwise.
613
    bool pattern_has_time;
614
615
private:
616
    std::string pattern;
617
    size_t arg_count;
618
    bool init_flag = false;
619
620
    PatternActions actions;
621
    DFAStates dfa_states;
622
};
623
624
template <PrimitiveType T, typename Derived>
625
class AggregateFunctionSequenceBase
626
        : public IAggregateFunctionDataHelper<AggregateFunctionSequenceMatchData<T, Derived>,
627
                                              Derived> {
628
public:
629
    AggregateFunctionSequenceBase(const DataTypes& arguments)
630
35
            : IAggregateFunctionDataHelper<AggregateFunctionSequenceMatchData<T, Derived>, Derived>(
631
35
                      arguments) {
632
35
        arg_count = arguments.size();
633
35
    }
_ZN5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEEC2ERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS9_EE
Line
Count
Source
630
16
            : IAggregateFunctionDataHelper<AggregateFunctionSequenceMatchData<T, Derived>, Derived>(
631
16
                      arguments) {
632
16
        arg_count = arguments.size();
633
16
    }
_ZN5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEEC2ERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS9_EE
Line
Count
Source
630
1
            : IAggregateFunctionDataHelper<AggregateFunctionSequenceMatchData<T, Derived>, Derived>(
631
1
                      arguments) {
632
1
        arg_count = arguments.size();
633
1
    }
Unexecuted instantiation: _ZN5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEEC2ERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS9_EE
Unexecuted instantiation: _ZN5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEEC2ERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS9_EE
_ZN5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEEC2ERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS9_EE
Line
Count
Source
630
17
            : IAggregateFunctionDataHelper<AggregateFunctionSequenceMatchData<T, Derived>, Derived>(
631
17
                      arguments) {
632
17
        arg_count = arguments.size();
633
17
    }
_ZN5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEEC2ERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS9_EE
Line
Count
Source
630
1
            : IAggregateFunctionDataHelper<AggregateFunctionSequenceMatchData<T, Derived>, Derived>(
631
1
                      arguments) {
632
1
        arg_count = arguments.size();
633
1
    }
Unexecuted instantiation: _ZN5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEEC2ERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS9_EE
Unexecuted instantiation: _ZN5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEEC2ERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS9_EE
634
635
8
    void reset(AggregateDataPtr __restrict place) const override { this->data(place).reset(); }
_ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEE5resetEPc
Line
Count
Source
635
4
    void reset(AggregateDataPtr __restrict place) const override { this->data(place).reset(); }
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEE5resetEPc
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEE5resetEPc
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEE5resetEPc
_ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEE5resetEPc
Line
Count
Source
635
4
    void reset(AggregateDataPtr __restrict place) const override { this->data(place).reset(); }
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEE5resetEPc
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEE5resetEPc
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEE5resetEPc
636
637
    void add(AggregateDataPtr __restrict place, const IColumn** columns, const ssize_t row_num,
638
333
             Arena&) const override {
639
333
        std::string pattern =
640
333
                assert_cast<const ColumnString*, TypeCheckOnRelease::DISABLE>(columns[0])
641
333
                        ->get_data_at(0)
642
333
                        .to_string();
643
333
        this->data(place).init(pattern, arg_count);
644
645
333
        const auto& timestamp = assert_cast<const typename PrimitiveTypeTraits<T>::ColumnType&,
646
333
                                            TypeCheckOnRelease::DISABLE>(*columns[1])
647
333
                                        .get_data()[row_num];
648
333
        typename AggregateFunctionSequenceMatchData<T, Derived>::Events events;
649
650
1.07k
        for (auto i = 2; i < arg_count; i++) {
651
737
            const auto event =
652
737
                    assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(columns[i])
653
737
                            ->get_data()[row_num];
654
737
            events.set(i - 2, event);
655
737
        }
656
657
333
        this->data(place).add(timestamp, events);
658
333
    }
_ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEE3addEPcPPKNS_7IColumnElRNS_5ArenaE
Line
Count
Source
638
169
             Arena&) const override {
639
169
        std::string pattern =
640
169
                assert_cast<const ColumnString*, TypeCheckOnRelease::DISABLE>(columns[0])
641
169
                        ->get_data_at(0)
642
169
                        .to_string();
643
169
        this->data(place).init(pattern, arg_count);
644
645
169
        const auto& timestamp = assert_cast<const typename PrimitiveTypeTraits<T>::ColumnType&,
646
169
                                            TypeCheckOnRelease::DISABLE>(*columns[1])
647
169
                                        .get_data()[row_num];
648
169
        typename AggregateFunctionSequenceMatchData<T, Derived>::Events events;
649
650
547
        for (auto i = 2; i < arg_count; i++) {
651
378
            const auto event =
652
378
                    assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(columns[i])
653
378
                            ->get_data()[row_num];
654
378
            events.set(i - 2, event);
655
378
        }
656
657
169
        this->data(place).add(timestamp, events);
658
169
    }
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEE3addEPcPPKNS_7IColumnElRNS_5ArenaE
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEE3addEPcPPKNS_7IColumnElRNS_5ArenaE
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEE3addEPcPPKNS_7IColumnElRNS_5ArenaE
_ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEE3addEPcPPKNS_7IColumnElRNS_5ArenaE
Line
Count
Source
638
164
             Arena&) const override {
639
164
        std::string pattern =
640
164
                assert_cast<const ColumnString*, TypeCheckOnRelease::DISABLE>(columns[0])
641
164
                        ->get_data_at(0)
642
164
                        .to_string();
643
164
        this->data(place).init(pattern, arg_count);
644
645
164
        const auto& timestamp = assert_cast<const typename PrimitiveTypeTraits<T>::ColumnType&,
646
164
                                            TypeCheckOnRelease::DISABLE>(*columns[1])
647
164
                                        .get_data()[row_num];
648
164
        typename AggregateFunctionSequenceMatchData<T, Derived>::Events events;
649
650
523
        for (auto i = 2; i < arg_count; i++) {
651
359
            const auto event =
652
359
                    assert_cast<const ColumnUInt8*, TypeCheckOnRelease::DISABLE>(columns[i])
653
359
                            ->get_data()[row_num];
654
359
            events.set(i - 2, event);
655
359
        }
656
657
164
        this->data(place).add(timestamp, events);
658
164
    }
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEE3addEPcPPKNS_7IColumnElRNS_5ArenaE
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEE3addEPcPPKNS_7IColumnElRNS_5ArenaE
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEE3addEPcPPKNS_7IColumnElRNS_5ArenaE
659
660
    void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs,
661
160
               Arena&) const override {
662
160
        this->data(place).merge(this->data(rhs));
663
160
    }
_ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEE5mergeEPcPKcRNS_5ArenaE
Line
Count
Source
661
80
               Arena&) const override {
662
80
        this->data(place).merge(this->data(rhs));
663
80
    }
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEE5mergeEPcPKcRNS_5ArenaE
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEE5mergeEPcPKcRNS_5ArenaE
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEE5mergeEPcPKcRNS_5ArenaE
_ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEE5mergeEPcPKcRNS_5ArenaE
Line
Count
Source
661
80
               Arena&) const override {
662
80
        this->data(place).merge(this->data(rhs));
663
80
    }
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEE5mergeEPcPKcRNS_5ArenaE
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEE5mergeEPcPKcRNS_5ArenaE
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEE5mergeEPcPKcRNS_5ArenaE
664
665
77
    void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const override {
666
77
        this->data(place).write(buf);
667
77
    }
_ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEE9serializeEPKcRNS_14BufferWritableE
Line
Count
Source
665
39
    void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const override {
666
39
        this->data(place).write(buf);
667
39
    }
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEE9serializeEPKcRNS_14BufferWritableE
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEE9serializeEPKcRNS_14BufferWritableE
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEE9serializeEPKcRNS_14BufferWritableE
_ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEE9serializeEPKcRNS_14BufferWritableE
Line
Count
Source
665
38
    void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const override {
666
38
        this->data(place).write(buf);
667
38
    }
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEE9serializeEPKcRNS_14BufferWritableE
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEE9serializeEPKcRNS_14BufferWritableE
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEE9serializeEPKcRNS_14BufferWritableE
668
669
    void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf,
670
85
                     Arena&) const override {
671
85
        auto& state = AggregateFunctionSequenceBase::data(place);
672
85
        state.read(buf);
673
        // A serialized uninitialized state has no arguments and must stay uninitialized.
674
85
        if (state.get_arg_count() == 0) {
675
24
            return;
676
24
        }
677
61
        state.init(state.get_pattern(), state.get_arg_count());
678
61
    }
_ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEE11deserializeEPcRNS_14BufferReadableERNS_5ArenaE
Line
Count
Source
670
43
                     Arena&) const override {
671
43
        auto& state = AggregateFunctionSequenceBase::data(place);
672
43
        state.read(buf);
673
        // A serialized uninitialized state has no arguments and must stay uninitialized.
674
43
        if (state.get_arg_count() == 0) {
675
12
            return;
676
12
        }
677
31
        state.init(state.get_pattern(), state.get_arg_count());
678
31
    }
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEE11deserializeEPcRNS_14BufferReadableERNS_5ArenaE
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEE11deserializeEPcRNS_14BufferReadableERNS_5ArenaE
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEE11deserializeEPcRNS_14BufferReadableERNS_5ArenaE
_ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEE11deserializeEPcRNS_14BufferReadableERNS_5ArenaE
Line
Count
Source
670
42
                     Arena&) const override {
671
42
        auto& state = AggregateFunctionSequenceBase::data(place);
672
42
        state.read(buf);
673
        // A serialized uninitialized state has no arguments and must stay uninitialized.
674
42
        if (state.get_arg_count() == 0) {
675
12
            return;
676
12
        }
677
30
        state.init(state.get_pattern(), state.get_arg_count());
678
30
    }
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEE11deserializeEPcRNS_14BufferReadableERNS_5ArenaE
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEE11deserializeEPcRNS_14BufferReadableERNS_5ArenaE
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEE11deserializeEPcRNS_14BufferReadableERNS_5ArenaE
679
680
0
    void check_input_columns_type(const IColumn** columns) const override {
681
0
        this->template check_argument_column_type<ColumnString>(columns[0]);
682
0
        this->template check_argument_column_type<typename PrimitiveTypeTraits<T>::ColumnType>(
683
0
                columns[1]);
684
0
        for (size_t i = 2; i < arg_count; ++i) {
685
0
            this->template check_argument_column_type<ColumnUInt8>(columns[i]);
686
0
        }
687
0
    }
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceMatchILS1_26EEEE24check_input_columns_typeEPPKNS_7IColumnE
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceMatchILS1_43EEEE24check_input_columns_typeEPPKNS_7IColumnE
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceMatchILS1_25EEEE24check_input_columns_typeEPPKNS_7IColumnE
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceMatchILS1_42EEEE24check_input_columns_typeEPPKNS_7IColumnE
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE26ENS_30AggregateFunctionSequenceCountILS1_26EEEE24check_input_columns_typeEPPKNS_7IColumnE
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE43ENS_30AggregateFunctionSequenceCountILS1_43EEEE24check_input_columns_typeEPPKNS_7IColumnE
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE25ENS_30AggregateFunctionSequenceCountILS1_25EEEE24check_input_columns_typeEPPKNS_7IColumnE
Unexecuted instantiation: _ZNK5doris29AggregateFunctionSequenceBaseILNS_13PrimitiveTypeE42ENS_30AggregateFunctionSequenceCountILS1_42EEEE24check_input_columns_typeEPPKNS_7IColumnE
688
689
private:
690
    size_t arg_count;
691
};
692
693
template <PrimitiveType T>
694
class AggregateFunctionSequenceMatch final
695
        : public AggregateFunctionSequenceBase<T, AggregateFunctionSequenceMatch<T>>,
696
          VarargsExpression,
697
          NullableAggregateFunction {
698
public:
699
    AggregateFunctionSequenceMatch(const DataTypes& arguments, const String& pattern_)
700
            : AggregateFunctionSequenceBase<T, AggregateFunctionSequenceMatch<T>>(arguments,
701
                                                                                  pattern_) {}
702
703
    using AggregateFunctionSequenceBase<
704
            T, AggregateFunctionSequenceMatch<T>>::AggregateFunctionSequenceBase;
705
706
0
    String get_name() const override { return "sequence_match"; }
Unexecuted instantiation: _ZNK5doris30AggregateFunctionSequenceMatchILNS_13PrimitiveTypeE26EE8get_nameB5cxx11Ev
Unexecuted instantiation: _ZNK5doris30AggregateFunctionSequenceMatchILNS_13PrimitiveTypeE43EE8get_nameB5cxx11Ev
Unexecuted instantiation: _ZNK5doris30AggregateFunctionSequenceMatchILNS_13PrimitiveTypeE25EE8get_nameB5cxx11Ev
Unexecuted instantiation: _ZNK5doris30AggregateFunctionSequenceMatchILNS_13PrimitiveTypeE42EE8get_nameB5cxx11Ev
707
708
104
    DataTypePtr get_return_type() const override { return std::make_shared<DataTypeUInt8>(); }
_ZNK5doris30AggregateFunctionSequenceMatchILNS_13PrimitiveTypeE26EE15get_return_typeEv
Line
Count
Source
708
104
    DataTypePtr get_return_type() const override { return std::make_shared<DataTypeUInt8>(); }
Unexecuted instantiation: _ZNK5doris30AggregateFunctionSequenceMatchILNS_13PrimitiveTypeE43EE15get_return_typeEv
Unexecuted instantiation: _ZNK5doris30AggregateFunctionSequenceMatchILNS_13PrimitiveTypeE25EE15get_return_typeEv
Unexecuted instantiation: _ZNK5doris30AggregateFunctionSequenceMatchILNS_13PrimitiveTypeE42EE15get_return_typeEv
709
710
115
    void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override {
711
115
        auto& output = assert_cast<ColumnUInt8&, TypeCheckOnRelease::DISABLE>(to).get_data();
712
115
        if (!this->data(place).conditions_in_pattern.any()) {
713
16
            output.push_back(false);
714
16
            return;
715
16
        }
716
717
99
        if ((this->data(place).conditions_in_pattern & this->data(place).conditions_met) !=
718
99
            this->data(place).conditions_in_pattern) {
719
60
            output.push_back(false);
720
60
            return;
721
60
        }
722
        // place is essentially an AggregateDataPtr, passed as a ConstAggregateDataPtr.
723
39
        this->data(const_cast<AggregateDataPtr>(place)).sort();
724
725
39
        const auto& data_ref = this->data(place);
726
727
39
        const auto events_begin = std::begin(data_ref.events_list);
728
39
        const auto events_end = std::end(data_ref.events_list);
729
39
        auto events_it = events_begin;
730
731
39
        bool match = (this->data(place).pattern_has_time
732
39
                              ? (this->data(place).could_match_deterministic_parts(events_begin,
733
2
                                                                                   events_end) &&
734
2
                                 this->data(place).backtracking_match(events_it, events_end))
735
39
                              : this->data(place).dfa_match(events_it, events_end));
736
39
        output.push_back(match);
737
39
    }
_ZNK5doris30AggregateFunctionSequenceMatchILNS_13PrimitiveTypeE26EE18insert_result_intoEPKcRNS_7IColumnE
Line
Count
Source
710
115
    void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override {
711
115
        auto& output = assert_cast<ColumnUInt8&, TypeCheckOnRelease::DISABLE>(to).get_data();
712
115
        if (!this->data(place).conditions_in_pattern.any()) {
713
16
            output.push_back(false);
714
16
            return;
715
16
        }
716
717
99
        if ((this->data(place).conditions_in_pattern & this->data(place).conditions_met) !=
718
99
            this->data(place).conditions_in_pattern) {
719
60
            output.push_back(false);
720
60
            return;
721
60
        }
722
        // place is essentially an AggregateDataPtr, passed as a ConstAggregateDataPtr.
723
39
        this->data(const_cast<AggregateDataPtr>(place)).sort();
724
725
39
        const auto& data_ref = this->data(place);
726
727
39
        const auto events_begin = std::begin(data_ref.events_list);
728
39
        const auto events_end = std::end(data_ref.events_list);
729
39
        auto events_it = events_begin;
730
731
39
        bool match = (this->data(place).pattern_has_time
732
39
                              ? (this->data(place).could_match_deterministic_parts(events_begin,
733
2
                                                                                   events_end) &&
734
2
                                 this->data(place).backtracking_match(events_it, events_end))
735
39
                              : this->data(place).dfa_match(events_it, events_end));
736
39
        output.push_back(match);
737
39
    }
Unexecuted instantiation: _ZNK5doris30AggregateFunctionSequenceMatchILNS_13PrimitiveTypeE43EE18insert_result_intoEPKcRNS_7IColumnE
Unexecuted instantiation: _ZNK5doris30AggregateFunctionSequenceMatchILNS_13PrimitiveTypeE25EE18insert_result_intoEPKcRNS_7IColumnE
Unexecuted instantiation: _ZNK5doris30AggregateFunctionSequenceMatchILNS_13PrimitiveTypeE42EE18insert_result_intoEPKcRNS_7IColumnE
738
};
739
740
template <PrimitiveType T>
741
class AggregateFunctionSequenceCount final
742
        : public AggregateFunctionSequenceBase<T, AggregateFunctionSequenceCount<T>>,
743
          VarargsExpression,
744
          NotNullableAggregateFunction {
745
public:
746
    AggregateFunctionSequenceCount(const DataTypes& arguments, const String& pattern_)
747
            : AggregateFunctionSequenceBase<T, AggregateFunctionSequenceCount<T>>(arguments,
748
                                                                                  pattern_) {}
749
750
    using AggregateFunctionSequenceBase<
751
            T, AggregateFunctionSequenceCount<T>>::AggregateFunctionSequenceBase;
752
753
0
    String get_name() const override { return "sequence_count"; }
Unexecuted instantiation: _ZNK5doris30AggregateFunctionSequenceCountILNS_13PrimitiveTypeE26EE8get_nameB5cxx11Ev
Unexecuted instantiation: _ZNK5doris30AggregateFunctionSequenceCountILNS_13PrimitiveTypeE43EE8get_nameB5cxx11Ev
Unexecuted instantiation: _ZNK5doris30AggregateFunctionSequenceCountILNS_13PrimitiveTypeE25EE8get_nameB5cxx11Ev
Unexecuted instantiation: _ZNK5doris30AggregateFunctionSequenceCountILNS_13PrimitiveTypeE42EE8get_nameB5cxx11Ev
754
755
104
    DataTypePtr get_return_type() const override { return std::make_shared<DataTypeInt64>(); }
_ZNK5doris30AggregateFunctionSequenceCountILNS_13PrimitiveTypeE26EE15get_return_typeEv
Line
Count
Source
755
104
    DataTypePtr get_return_type() const override { return std::make_shared<DataTypeInt64>(); }
Unexecuted instantiation: _ZNK5doris30AggregateFunctionSequenceCountILNS_13PrimitiveTypeE43EE15get_return_typeEv
Unexecuted instantiation: _ZNK5doris30AggregateFunctionSequenceCountILNS_13PrimitiveTypeE25EE15get_return_typeEv
Unexecuted instantiation: _ZNK5doris30AggregateFunctionSequenceCountILNS_13PrimitiveTypeE42EE15get_return_typeEv
756
757
112
    void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override {
758
112
        auto& output = assert_cast<ColumnInt64&, TypeCheckOnRelease::DISABLE>(to).get_data();
759
112
        if (!this->data(place).conditions_in_pattern.any()) {
760
15
            output.push_back(0);
761
15
            return;
762
15
        }
763
764
97
        if ((this->data(place).conditions_in_pattern & this->data(place).conditions_met) !=
765
97
            this->data(place).conditions_in_pattern) {
766
59
            output.push_back(0);
767
59
            return;
768
59
        }
769
        // place is essentially an AggregateDataPtr, passed as a ConstAggregateDataPtr.
770
38
        this->data(const_cast<AggregateDataPtr>(place)).sort();
771
38
        output.push_back(count(place));
772
38
    }
_ZNK5doris30AggregateFunctionSequenceCountILNS_13PrimitiveTypeE26EE18insert_result_intoEPKcRNS_7IColumnE
Line
Count
Source
757
112
    void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override {
758
112
        auto& output = assert_cast<ColumnInt64&, TypeCheckOnRelease::DISABLE>(to).get_data();
759
112
        if (!this->data(place).conditions_in_pattern.any()) {
760
15
            output.push_back(0);
761
15
            return;
762
15
        }
763
764
97
        if ((this->data(place).conditions_in_pattern & this->data(place).conditions_met) !=
765
97
            this->data(place).conditions_in_pattern) {
766
59
            output.push_back(0);
767
59
            return;
768
59
        }
769
        // place is essentially an AggregateDataPtr, passed as a ConstAggregateDataPtr.
770
38
        this->data(const_cast<AggregateDataPtr>(place)).sort();
771
38
        output.push_back(count(place));
772
38
    }
Unexecuted instantiation: _ZNK5doris30AggregateFunctionSequenceCountILNS_13PrimitiveTypeE43EE18insert_result_intoEPKcRNS_7IColumnE
Unexecuted instantiation: _ZNK5doris30AggregateFunctionSequenceCountILNS_13PrimitiveTypeE25EE18insert_result_intoEPKcRNS_7IColumnE
Unexecuted instantiation: _ZNK5doris30AggregateFunctionSequenceCountILNS_13PrimitiveTypeE42EE18insert_result_intoEPKcRNS_7IColumnE
773
774
private:
775
38
    UInt64 count(ConstAggregateDataPtr __restrict place) const {
776
38
        const auto& data_ref = this->data(place);
777
778
38
        const auto events_begin = std::begin(data_ref.events_list);
779
38
        const auto events_end = std::end(data_ref.events_list);
780
38
        auto events_it = events_begin;
781
782
38
        size_t count = 0;
783
        // check if there is a chance of matching the sequence at least once
784
38
        if (this->data(place).could_match_deterministic_parts(events_begin, events_end)) {
785
85
            while (events_it != events_end &&
786
85
                   this->data(place).backtracking_match(events_it, events_end))
787
47
                ++count;
788
38
        }
789
790
38
        return count;
791
38
    }
_ZNK5doris30AggregateFunctionSequenceCountILNS_13PrimitiveTypeE26EE5countEPKc
Line
Count
Source
775
38
    UInt64 count(ConstAggregateDataPtr __restrict place) const {
776
38
        const auto& data_ref = this->data(place);
777
778
38
        const auto events_begin = std::begin(data_ref.events_list);
779
38
        const auto events_end = std::end(data_ref.events_list);
780
38
        auto events_it = events_begin;
781
782
38
        size_t count = 0;
783
        // check if there is a chance of matching the sequence at least once
784
38
        if (this->data(place).could_match_deterministic_parts(events_begin, events_end)) {
785
85
            while (events_it != events_end &&
786
85
                   this->data(place).backtracking_match(events_it, events_end))
787
47
                ++count;
788
38
        }
789
790
38
        return count;
791
38
    }
Unexecuted instantiation: _ZNK5doris30AggregateFunctionSequenceCountILNS_13PrimitiveTypeE43EE5countEPKc
Unexecuted instantiation: _ZNK5doris30AggregateFunctionSequenceCountILNS_13PrimitiveTypeE25EE5countEPKc
Unexecuted instantiation: _ZNK5doris30AggregateFunctionSequenceCountILNS_13PrimitiveTypeE42EE5countEPKc
792
};
793
794
} // namespace doris