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