be/src/exprs/aggregate/aggregate_function_window_funnel.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/AggregateFunctionWindowFunnel.h |
20 | | // and modified by Doris |
21 | | |
22 | | #pragma once |
23 | | |
24 | | #include <gen_cpp/data.pb.h> |
25 | | |
26 | | #include <algorithm> |
27 | | #include <boost/iterator/iterator_facade.hpp> |
28 | | #include <iterator> |
29 | | #include <memory> |
30 | | #include <type_traits> |
31 | | #include <utility> |
32 | | |
33 | | #include "common/cast_set.h" |
34 | | #include "common/exception.h" |
35 | | #include "common/status.h" |
36 | | #include "core/assert_cast.h" |
37 | | #include "core/binary_cast.hpp" |
38 | | #include "core/column/column_string.h" |
39 | | #include "core/column/column_vector.h" |
40 | | #include "core/data_type/data_type_number.h" |
41 | | #include "core/types.h" |
42 | | #include "core/value/vdatetime_value.h" |
43 | | #include "exec/sort/sort_block.h" |
44 | | #include "exprs/aggregate/aggregate_function.h" |
45 | | #include "util/simd/bits.h" |
46 | | #include "util/var_int.h" |
47 | | |
48 | | namespace doris { |
49 | | class Arena; |
50 | | class BufferReadable; |
51 | | class BufferWritable; |
52 | | class IColumn; |
53 | | } // namespace doris |
54 | | |
55 | | namespace doris { |
56 | | |
57 | | enum class WindowFunnelMode : Int64 { INVALID, DEFAULT, DEDUPLICATION, FIXED, INCREASE }; |
58 | | |
59 | 256 | inline WindowFunnelMode string_to_window_funnel_mode(const String& string) { |
60 | 256 | if (string == "default") { |
61 | 99 | return WindowFunnelMode::DEFAULT; |
62 | 157 | } else if (string == "deduplication") { |
63 | 36 | return WindowFunnelMode::DEDUPLICATION; |
64 | 121 | } else if (string == "fixed") { |
65 | 19 | return WindowFunnelMode::FIXED; |
66 | 102 | } else if (string == "increase") { |
67 | 18 | return WindowFunnelMode::INCREASE; |
68 | 84 | } else { |
69 | 84 | return WindowFunnelMode::INVALID; |
70 | 84 | } |
71 | 256 | } |
72 | | |
73 | | template <PrimitiveType T> |
74 | | struct DataValue { |
75 | | using TimestampEvent = std::vector<ColumnUInt8::Container>; |
76 | | using DateValueType = typename PrimitiveTypeTraits<T>::CppType; |
77 | | std::vector<DateValueType> dt; |
78 | | TimestampEvent event_columns_data; |
79 | | bool operator<(const DataValue& other) const { return dt < other.dt; } |
80 | 3 | void clear() { |
81 | 3 | dt.clear(); |
82 | 9 | for (auto& data : event_columns_data) { |
83 | 9 | data.clear(); |
84 | 9 | } |
85 | 3 | } _ZN5doris9DataValueILNS_13PrimitiveTypeE43EE5clearEv Line | Count | Source | 80 | 1 | void clear() { | 81 | 1 | dt.clear(); | 82 | 1 | for (auto& data : event_columns_data) { | 83 | 1 | data.clear(); | 84 | 1 | } | 85 | 1 | } |
_ZN5doris9DataValueILNS_13PrimitiveTypeE26EE5clearEv Line | Count | Source | 80 | 2 | void clear() { | 81 | 2 | dt.clear(); | 82 | 8 | for (auto& data : event_columns_data) { | 83 | 8 | data.clear(); | 84 | 8 | } | 85 | 2 | } |
Unexecuted instantiation: _ZN5doris9DataValueILNS_13PrimitiveTypeE42EE5clearEv |
86 | 78 | auto size() const { return dt.size(); }_ZNK5doris9DataValueILNS_13PrimitiveTypeE43EE4sizeEv Line | Count | Source | 86 | 3 | auto size() const { return dt.size(); } |
_ZNK5doris9DataValueILNS_13PrimitiveTypeE26EE4sizeEv Line | Count | Source | 86 | 75 | auto size() const { return dt.size(); } |
Unexecuted instantiation: _ZNK5doris9DataValueILNS_13PrimitiveTypeE42EE4sizeEv |
87 | 11 | bool empty() const { return dt.empty(); }_ZNK5doris9DataValueILNS_13PrimitiveTypeE26EE5emptyEv Line | Count | Source | 87 | 11 | bool empty() const { return dt.empty(); } |
Unexecuted instantiation: _ZNK5doris9DataValueILNS_13PrimitiveTypeE43EE5emptyEv Unexecuted instantiation: _ZNK5doris9DataValueILNS_13PrimitiveTypeE42EE5emptyEv |
88 | | std::string debug_string() const { |
89 | | std::string result = "\n" + std::to_string(dt.size()) + " " + |
90 | | std::to_string(event_columns_data[0].size()) + "\n"; |
91 | | for (size_t i = 0; i < dt.size(); ++i) { |
92 | | result += dt[i].debug_string() + " ,"; |
93 | | for (const auto& event : event_columns_data) { |
94 | | result += std::to_string(event[i]) + ","; |
95 | | } |
96 | | result += "\n"; |
97 | | } |
98 | | return result; |
99 | | } |
100 | | }; |
101 | | |
102 | | template <PrimitiveType T> |
103 | | struct WindowFunnelState { |
104 | | static constexpr PrimitiveType PType = T; |
105 | | using NativeType = typename PrimitiveTypeTraits<T>::StorageFieldType; |
106 | | using DateValueType = typename PrimitiveTypeTraits<T>::CppType; |
107 | | int event_count = 0; |
108 | | int64_t window; |
109 | | bool enable_mode; |
110 | | WindowFunnelMode window_funnel_mode; |
111 | | DataValue<T> events_list; |
112 | | |
113 | 39 | WindowFunnelState() { |
114 | 39 | event_count = 0; |
115 | 39 | window = 0; |
116 | 39 | window_funnel_mode = WindowFunnelMode::INVALID; |
117 | 39 | } _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EEC2Ev Line | Count | Source | 113 | 3 | WindowFunnelState() { | 114 | 3 | event_count = 0; | 115 | 3 | window = 0; | 116 | 3 | window_funnel_mode = WindowFunnelMode::INVALID; | 117 | 3 | } |
_ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EEC2Ev Line | Count | Source | 113 | 36 | WindowFunnelState() { | 114 | 36 | event_count = 0; | 115 | 36 | window = 0; | 116 | 36 | window_funnel_mode = WindowFunnelMode::INVALID; | 117 | 36 | } |
Unexecuted instantiation: _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EEC2Ev |
118 | 39 | WindowFunnelState(int arg_event_count) : WindowFunnelState() { |
119 | 39 | event_count = arg_event_count; |
120 | 39 | events_list.event_columns_data.resize(event_count); |
121 | 39 | } _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EEC2Ei Line | Count | Source | 118 | 3 | WindowFunnelState(int arg_event_count) : WindowFunnelState() { | 119 | 3 | event_count = arg_event_count; | 120 | 3 | events_list.event_columns_data.resize(event_count); | 121 | 3 | } |
_ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EEC2Ei Line | Count | Source | 118 | 36 | WindowFunnelState(int arg_event_count) : WindowFunnelState() { | 119 | 36 | event_count = arg_event_count; | 120 | 36 | events_list.event_columns_data.resize(event_count); | 121 | 36 | } |
Unexecuted instantiation: _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EEC2Ei |
122 | | |
123 | 0 | void reset() { events_list.clear(); }Unexecuted instantiation: _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE5resetEv Unexecuted instantiation: _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE5resetEv Unexecuted instantiation: _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EE5resetEv |
124 | | |
125 | 86 | void add(const IColumn** arg_columns, ssize_t row_num, int64_t win, WindowFunnelMode mode) { |
126 | 86 | window = win; |
127 | 86 | window_funnel_mode = enable_mode ? mode : WindowFunnelMode::DEFAULT; |
128 | 86 | events_list.dt.emplace_back( |
129 | 86 | assert_cast<const typename PrimitiveTypeTraits<PType>::ColumnType&, |
130 | 86 | TypeCheckOnRelease::DISABLE>(*arg_columns[2]) |
131 | 86 | .get_data()[row_num]); |
132 | 426 | for (int i = 0; i < event_count; i++) { |
133 | 340 | events_list.event_columns_data[i].emplace_back( |
134 | 340 | assert_cast<const ColumnUInt8&, TypeCheckOnRelease::DISABLE>( |
135 | 340 | *arg_columns[3 + i]) |
136 | 340 | .get_data()[row_num]); |
137 | 340 | } |
138 | 86 | } _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE3addEPPKNS_7IColumnEllNS_16WindowFunnelModeE Line | Count | Source | 125 | 86 | void add(const IColumn** arg_columns, ssize_t row_num, int64_t win, WindowFunnelMode mode) { | 126 | 86 | window = win; | 127 | 86 | window_funnel_mode = enable_mode ? mode : WindowFunnelMode::DEFAULT; | 128 | 86 | events_list.dt.emplace_back( | 129 | 86 | assert_cast<const typename PrimitiveTypeTraits<PType>::ColumnType&, | 130 | 86 | TypeCheckOnRelease::DISABLE>(*arg_columns[2]) | 131 | 86 | .get_data()[row_num]); | 132 | 426 | for (int i = 0; i < event_count; i++) { | 133 | 340 | events_list.event_columns_data[i].emplace_back( | 134 | 340 | assert_cast<const ColumnUInt8&, TypeCheckOnRelease::DISABLE>( | 135 | 340 | *arg_columns[3 + i]) | 136 | 340 | .get_data()[row_num]); | 137 | 340 | } | 138 | 86 | } |
Unexecuted instantiation: _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE3addEPPKNS_7IColumnEllNS_16WindowFunnelModeE Unexecuted instantiation: _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EE3addEPPKNS_7IColumnEllNS_16WindowFunnelModeE |
139 | | |
140 | | // todo: rethink thid sort method. |
141 | 25 | void sort() { |
142 | 25 | auto num = events_list.size(); |
143 | 25 | std::vector<size_t> indices(num); |
144 | 25 | std::iota(indices.begin(), indices.end(), 0); |
145 | 25 | std::sort(indices.begin(), indices.end(), |
146 | 104 | [this](size_t i1, size_t i2) { return events_list.dt[i1] < events_list.dt[i2]; });_ZZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE4sortEvENKUlmmE_clEmm Line | Count | Source | 146 | 104 | [this](size_t i1, size_t i2) { return events_list.dt[i1] < events_list.dt[i2]; }); |
Unexecuted instantiation: _ZZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE4sortEvENKUlmmE_clEmm Unexecuted instantiation: _ZZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EE4sortEvENKUlmmE_clEmm |
147 | | |
148 | 123 | auto reorder = [&indices, &num](auto& vec) { |
149 | 123 | std::decay_t<decltype(vec)> temp; |
150 | 123 | temp.resize(num); |
151 | 569 | for (auto i = 0; i < num; i++) { |
152 | 446 | temp[i] = vec[indices[i]]; |
153 | 446 | } |
154 | 123 | std::swap(vec, temp); |
155 | 123 | }; _ZZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE4sortEvENKUlRT_E_clISt6vectorINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEESaISA_EEEEDaS4_ Line | Count | Source | 148 | 25 | auto reorder = [&indices, &num](auto& vec) { | 149 | 25 | std::decay_t<decltype(vec)> temp; | 150 | 25 | temp.resize(num); | 151 | 115 | for (auto i = 0; i < num; i++) { | 152 | 90 | temp[i] = vec[indices[i]]; | 153 | 90 | } | 154 | 25 | std::swap(vec, temp); | 155 | 25 | }; |
_ZZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE4sortEvENKUlRT_E_clINS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEEEDaS4_ Line | Count | Source | 148 | 98 | auto reorder = [&indices, &num](auto& vec) { | 149 | 98 | std::decay_t<decltype(vec)> temp; | 150 | 98 | temp.resize(num); | 151 | 454 | for (auto i = 0; i < num; i++) { | 152 | 356 | temp[i] = vec[indices[i]]; | 153 | 356 | } | 154 | 98 | std::swap(vec, temp); | 155 | 98 | }; |
Unexecuted instantiation: _ZZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE4sortEvENKUlRT_E_clISt6vectorINS_16TimeStampNsValueESaIS8_EEEEDaS4_ Unexecuted instantiation: _ZZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE4sortEvENKUlRT_E_clINS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEEEDaS4_ Unexecuted instantiation: _ZZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EE4sortEvENKUlRT_E_clISt6vectorINS_16TimestampTzValueESaIS8_EEEEDaS4_ Unexecuted instantiation: _ZZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EE4sortEvENKUlRT_E_clINS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEEEDaS4_ |
156 | | |
157 | 25 | reorder(events_list.dt); |
158 | 98 | for (auto& inner_vec : events_list.event_columns_data) { |
159 | 98 | reorder(inner_vec); |
160 | 98 | } |
161 | 25 | } _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE4sortEv Line | Count | Source | 141 | 25 | void sort() { | 142 | 25 | auto num = events_list.size(); | 143 | 25 | std::vector<size_t> indices(num); | 144 | 25 | std::iota(indices.begin(), indices.end(), 0); | 145 | 25 | std::sort(indices.begin(), indices.end(), | 146 | 25 | [this](size_t i1, size_t i2) { return events_list.dt[i1] < events_list.dt[i2]; }); | 147 | | | 148 | 25 | auto reorder = [&indices, &num](auto& vec) { | 149 | 25 | std::decay_t<decltype(vec)> temp; | 150 | 25 | temp.resize(num); | 151 | 25 | for (auto i = 0; i < num; i++) { | 152 | 25 | temp[i] = vec[indices[i]]; | 153 | 25 | } | 154 | 25 | std::swap(vec, temp); | 155 | 25 | }; | 156 | | | 157 | 25 | reorder(events_list.dt); | 158 | 98 | for (auto& inner_vec : events_list.event_columns_data) { | 159 | 98 | reorder(inner_vec); | 160 | 98 | } | 161 | 25 | } |
Unexecuted instantiation: _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE4sortEv Unexecuted instantiation: _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EE4sortEv |
162 | | |
163 | | bool _within_window(const DateValueType& base_timestamp, |
164 | 59 | const DateValueType& current_timestamp) const { |
165 | 59 | if constexpr (T == TYPE_TIMESTAMP_NS) { |
166 | 1 | const auto elapsed_nanos = static_cast<__int128>(current_timestamp.epoch_nanos()) - |
167 | 1 | base_timestamp.epoch_nanos(); |
168 | 1 | const auto window_nanos = |
169 | 1 | static_cast<__int128>(window) * TimeStampNsValue::NANOS_PER_SECOND; |
170 | 1 | return elapsed_nanos <= window_nanos; |
171 | 1 | } |
172 | 0 | return static_cast<__int128>(current_timestamp.datetime_diff_in_microseconds( |
173 | 59 | base_timestamp)) <= static_cast<__int128>(window) * 1000000; |
174 | 59 | } _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE14_within_windowERKNS_16TimeStampNsValueES5_ Line | Count | Source | 164 | 1 | const DateValueType& current_timestamp) const { | 165 | 1 | if constexpr (T == TYPE_TIMESTAMP_NS) { | 166 | 1 | const auto elapsed_nanos = static_cast<__int128>(current_timestamp.epoch_nanos()) - | 167 | 1 | base_timestamp.epoch_nanos(); | 168 | 1 | const auto window_nanos = | 169 | 1 | static_cast<__int128>(window) * TimeStampNsValue::NANOS_PER_SECOND; | 170 | 1 | return elapsed_nanos <= window_nanos; | 171 | 1 | } | 172 | 0 | return static_cast<__int128>(current_timestamp.datetime_diff_in_microseconds( | 173 | 1 | base_timestamp)) <= static_cast<__int128>(window) * 1000000; | 174 | 1 | } |
_ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE14_within_windowERKNS_11DateV2ValueINS_19DateTimeV2ValueTypeEEES7_ Line | Count | Source | 164 | 58 | const DateValueType& current_timestamp) const { | 165 | | if constexpr (T == TYPE_TIMESTAMP_NS) { | 166 | | const auto elapsed_nanos = static_cast<__int128>(current_timestamp.epoch_nanos()) - | 167 | | base_timestamp.epoch_nanos(); | 168 | | const auto window_nanos = | 169 | | static_cast<__int128>(window) * TimeStampNsValue::NANOS_PER_SECOND; | 170 | | return elapsed_nanos <= window_nanos; | 171 | | } | 172 | 58 | return static_cast<__int128>(current_timestamp.datetime_diff_in_microseconds( | 173 | 58 | base_timestamp)) <= static_cast<__int128>(window) * 1000000; | 174 | 58 | } |
Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EE14_within_windowERKNS_16TimestampTzValueES5_ |
175 | | |
176 | | template <WindowFunnelMode WINDOW_FUNNEL_MODE> |
177 | 38 | int _match_event_list(size_t& start_row, size_t row_count) const { |
178 | 38 | int matched_count = 0; |
179 | 38 | if (window < 0) { |
180 | 0 | throw Exception(ErrorCode::INVALID_ARGUMENT, |
181 | 0 | "the sliding time window must be a positive integer, but got: {}", |
182 | 0 | window); |
183 | 0 | } |
184 | 38 | int column_idx = 0; |
185 | 38 | const auto& timestamp_data = events_list.dt; |
186 | 38 | const auto& first_event_data = events_list.event_columns_data[column_idx].data(); |
187 | 38 | auto match_row = simd::find_one(first_event_data, start_row, row_count); |
188 | 38 | start_row = match_row + 1; |
189 | 38 | if (match_row < row_count) { |
190 | 24 | auto prev_timestamp = timestamp_data[match_row]; |
191 | 24 | const auto first_timestamp = prev_timestamp; |
192 | 24 | matched_count++; |
193 | 24 | column_idx++; |
194 | 24 | auto last_match_row = match_row; |
195 | 24 | ++match_row; |
196 | 66 | for (; column_idx < event_count && match_row < row_count; column_idx++, match_row++) { |
197 | 56 | const auto& event_data = events_list.event_columns_data[column_idx]; |
198 | 56 | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::FIXED) { |
199 | 0 | if (event_data[match_row] == 1) { |
200 | 0 | auto current_timestamp = timestamp_data[match_row]; |
201 | 0 | if (_within_window(first_timestamp, current_timestamp)) { |
202 | 0 | matched_count++; |
203 | 0 | continue; |
204 | 0 | } |
205 | 0 | } |
206 | 0 | break; |
207 | 0 | } |
208 | 0 | match_row = simd::find_one(event_data.data(), match_row, row_count); |
209 | 56 | if (match_row < row_count) { |
210 | 56 | auto current_timestamp = timestamp_data[match_row]; |
211 | 56 | bool is_matched = _within_window(first_timestamp, current_timestamp); |
212 | 56 | if (is_matched) { |
213 | 42 | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::INCREASE) { |
214 | 0 | is_matched = current_timestamp > prev_timestamp; |
215 | 0 | } |
216 | 42 | } |
217 | 56 | if (!is_matched) { |
218 | 14 | break; |
219 | 14 | } |
220 | 42 | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::INCREASE) { |
221 | 0 | prev_timestamp = timestamp_data[match_row]; |
222 | 0 | } |
223 | 42 | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::DEDUPLICATION) { |
224 | 0 | bool is_dup = false; |
225 | 0 | if (match_row != last_match_row + 1) { |
226 | 0 | for (int tmp_column_idx = 0; tmp_column_idx < column_idx; |
227 | 0 | tmp_column_idx++) { |
228 | 0 | const auto& tmp_event_data = |
229 | 0 | events_list.event_columns_data[tmp_column_idx].data(); |
230 | 0 | auto dup_match_row = simd::find_one(tmp_event_data, |
231 | 0 | last_match_row + 1, match_row); |
232 | 0 | if (dup_match_row < match_row) { |
233 | 0 | is_dup = true; |
234 | 0 | break; |
235 | 0 | } |
236 | 0 | } |
237 | 0 | } |
238 | 0 | if (is_dup) { |
239 | 0 | break; |
240 | 0 | } |
241 | 0 | last_match_row = match_row; |
242 | 0 | } |
243 | 0 | matched_count++; |
244 | 42 | } else { |
245 | 0 | break; |
246 | 0 | } |
247 | 56 | } |
248 | 24 | } |
249 | 0 | return matched_count; |
250 | 0 | } _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE17_match_event_listILNS_16WindowFunnelModeE1EEEiRmm Line | Count | Source | 177 | 1 | int _match_event_list(size_t& start_row, size_t row_count) const { | 178 | 1 | int matched_count = 0; | 179 | 1 | if (window < 0) { | 180 | 0 | throw Exception(ErrorCode::INVALID_ARGUMENT, | 181 | 0 | "the sliding time window must be a positive integer, but got: {}", | 182 | 0 | window); | 183 | 0 | } | 184 | 1 | int column_idx = 0; | 185 | 1 | const auto& timestamp_data = events_list.dt; | 186 | 1 | const auto& first_event_data = events_list.event_columns_data[column_idx].data(); | 187 | 1 | auto match_row = simd::find_one(first_event_data, start_row, row_count); | 188 | 1 | start_row = match_row + 1; | 189 | 1 | if (match_row < row_count) { | 190 | 1 | auto prev_timestamp = timestamp_data[match_row]; | 191 | 1 | const auto first_timestamp = prev_timestamp; | 192 | 1 | matched_count++; | 193 | 1 | column_idx++; | 194 | 1 | auto last_match_row = match_row; | 195 | 1 | ++match_row; | 196 | 2 | for (; column_idx < event_count && match_row < row_count; column_idx++, match_row++) { | 197 | 1 | const auto& event_data = events_list.event_columns_data[column_idx]; | 198 | | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::FIXED) { | 199 | | if (event_data[match_row] == 1) { | 200 | | auto current_timestamp = timestamp_data[match_row]; | 201 | | if (_within_window(first_timestamp, current_timestamp)) { | 202 | | matched_count++; | 203 | | continue; | 204 | | } | 205 | | } | 206 | | break; | 207 | | } | 208 | 1 | match_row = simd::find_one(event_data.data(), match_row, row_count); | 209 | 1 | if (match_row < row_count) { | 210 | 1 | auto current_timestamp = timestamp_data[match_row]; | 211 | 1 | bool is_matched = _within_window(first_timestamp, current_timestamp); | 212 | 1 | if (is_matched) { | 213 | | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::INCREASE) { | 214 | | is_matched = current_timestamp > prev_timestamp; | 215 | | } | 216 | 1 | } | 217 | 1 | if (!is_matched) { | 218 | 0 | break; | 219 | 0 | } | 220 | | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::INCREASE) { | 221 | | prev_timestamp = timestamp_data[match_row]; | 222 | | } | 223 | | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::DEDUPLICATION) { | 224 | | bool is_dup = false; | 225 | | if (match_row != last_match_row + 1) { | 226 | | for (int tmp_column_idx = 0; tmp_column_idx < column_idx; | 227 | | tmp_column_idx++) { | 228 | | const auto& tmp_event_data = | 229 | | events_list.event_columns_data[tmp_column_idx].data(); | 230 | | auto dup_match_row = simd::find_one(tmp_event_data, | 231 | | last_match_row + 1, match_row); | 232 | | if (dup_match_row < match_row) { | 233 | | is_dup = true; | 234 | | break; | 235 | | } | 236 | | } | 237 | | } | 238 | | if (is_dup) { | 239 | | break; | 240 | | } | 241 | | last_match_row = match_row; | 242 | | } | 243 | 1 | matched_count++; | 244 | 1 | } else { | 245 | 0 | break; | 246 | 0 | } | 247 | 1 | } | 248 | 1 | } | 249 | 1 | return matched_count; | 250 | 1 | } |
Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE17_match_event_listILNS_16WindowFunnelModeE2EEEiRmm Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE17_match_event_listILNS_16WindowFunnelModeE3EEEiRmm Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE17_match_event_listILNS_16WindowFunnelModeE4EEEiRmm _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE17_match_event_listILNS_16WindowFunnelModeE1EEEiRmm Line | Count | Source | 177 | 37 | int _match_event_list(size_t& start_row, size_t row_count) const { | 178 | 37 | int matched_count = 0; | 179 | 37 | if (window < 0) { | 180 | 0 | throw Exception(ErrorCode::INVALID_ARGUMENT, | 181 | 0 | "the sliding time window must be a positive integer, but got: {}", | 182 | 0 | window); | 183 | 0 | } | 184 | 37 | int column_idx = 0; | 185 | 37 | const auto& timestamp_data = events_list.dt; | 186 | 37 | const auto& first_event_data = events_list.event_columns_data[column_idx].data(); | 187 | 37 | auto match_row = simd::find_one(first_event_data, start_row, row_count); | 188 | 37 | start_row = match_row + 1; | 189 | 37 | if (match_row < row_count) { | 190 | 23 | auto prev_timestamp = timestamp_data[match_row]; | 191 | 23 | const auto first_timestamp = prev_timestamp; | 192 | 23 | matched_count++; | 193 | 23 | column_idx++; | 194 | 23 | auto last_match_row = match_row; | 195 | 23 | ++match_row; | 196 | 64 | for (; column_idx < event_count && match_row < row_count; column_idx++, match_row++) { | 197 | 55 | const auto& event_data = events_list.event_columns_data[column_idx]; | 198 | | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::FIXED) { | 199 | | if (event_data[match_row] == 1) { | 200 | | auto current_timestamp = timestamp_data[match_row]; | 201 | | if (_within_window(first_timestamp, current_timestamp)) { | 202 | | matched_count++; | 203 | | continue; | 204 | | } | 205 | | } | 206 | | break; | 207 | | } | 208 | 55 | match_row = simd::find_one(event_data.data(), match_row, row_count); | 209 | 55 | if (match_row < row_count) { | 210 | 55 | auto current_timestamp = timestamp_data[match_row]; | 211 | 55 | bool is_matched = _within_window(first_timestamp, current_timestamp); | 212 | 55 | if (is_matched) { | 213 | | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::INCREASE) { | 214 | | is_matched = current_timestamp > prev_timestamp; | 215 | | } | 216 | 41 | } | 217 | 55 | if (!is_matched) { | 218 | 14 | break; | 219 | 14 | } | 220 | | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::INCREASE) { | 221 | | prev_timestamp = timestamp_data[match_row]; | 222 | | } | 223 | | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::DEDUPLICATION) { | 224 | | bool is_dup = false; | 225 | | if (match_row != last_match_row + 1) { | 226 | | for (int tmp_column_idx = 0; tmp_column_idx < column_idx; | 227 | | tmp_column_idx++) { | 228 | | const auto& tmp_event_data = | 229 | | events_list.event_columns_data[tmp_column_idx].data(); | 230 | | auto dup_match_row = simd::find_one(tmp_event_data, | 231 | | last_match_row + 1, match_row); | 232 | | if (dup_match_row < match_row) { | 233 | | is_dup = true; | 234 | | break; | 235 | | } | 236 | | } | 237 | | } | 238 | | if (is_dup) { | 239 | | break; | 240 | | } | 241 | | last_match_row = match_row; | 242 | | } | 243 | 41 | matched_count++; | 244 | 41 | } else { | 245 | 0 | break; | 246 | 0 | } | 247 | 55 | } | 248 | 23 | } | 249 | 37 | return matched_count; | 250 | 37 | } |
Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE17_match_event_listILNS_16WindowFunnelModeE2EEEiRmm Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE17_match_event_listILNS_16WindowFunnelModeE3EEEiRmm Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE17_match_event_listILNS_16WindowFunnelModeE4EEEiRmm Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EE17_match_event_listILNS_16WindowFunnelModeE1EEEiRmm Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EE17_match_event_listILNS_16WindowFunnelModeE2EEEiRmm Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EE17_match_event_listILNS_16WindowFunnelModeE3EEEiRmm Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EE17_match_event_listILNS_16WindowFunnelModeE4EEEiRmm |
251 | | |
252 | | template <WindowFunnelMode WINDOW_FUNNEL_MODE> |
253 | 24 | int _get_internal() const { |
254 | 24 | size_t start_row = 0; |
255 | 24 | int max_found_event_count = 0; |
256 | 24 | auto row_count = events_list.size(); |
257 | 52 | while (start_row < row_count) { |
258 | 38 | auto found_event_count = _match_event_list<WINDOW_FUNNEL_MODE>(start_row, row_count); |
259 | 38 | if (found_event_count == event_count) { |
260 | 10 | return found_event_count; |
261 | 10 | } |
262 | 28 | max_found_event_count = std::max(max_found_event_count, found_event_count); |
263 | 28 | } |
264 | 14 | return max_found_event_count; |
265 | 24 | } _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE13_get_internalILNS_16WindowFunnelModeE1EEEiv Line | Count | Source | 253 | 1 | int _get_internal() const { | 254 | 1 | size_t start_row = 0; | 255 | 1 | int max_found_event_count = 0; | 256 | 1 | auto row_count = events_list.size(); | 257 | 1 | while (start_row < row_count) { | 258 | 1 | auto found_event_count = _match_event_list<WINDOW_FUNNEL_MODE>(start_row, row_count); | 259 | 1 | if (found_event_count == event_count) { | 260 | 1 | return found_event_count; | 261 | 1 | } | 262 | 0 | max_found_event_count = std::max(max_found_event_count, found_event_count); | 263 | 0 | } | 264 | 0 | return max_found_event_count; | 265 | 1 | } |
Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE13_get_internalILNS_16WindowFunnelModeE2EEEiv Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE13_get_internalILNS_16WindowFunnelModeE3EEEiv Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE13_get_internalILNS_16WindowFunnelModeE4EEEiv _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE13_get_internalILNS_16WindowFunnelModeE1EEEiv Line | Count | Source | 253 | 23 | int _get_internal() const { | 254 | 23 | size_t start_row = 0; | 255 | 23 | int max_found_event_count = 0; | 256 | 23 | auto row_count = events_list.size(); | 257 | 51 | while (start_row < row_count) { | 258 | 37 | auto found_event_count = _match_event_list<WINDOW_FUNNEL_MODE>(start_row, row_count); | 259 | 37 | if (found_event_count == event_count) { | 260 | 9 | return found_event_count; | 261 | 9 | } | 262 | 28 | max_found_event_count = std::max(max_found_event_count, found_event_count); | 263 | 28 | } | 264 | 14 | return max_found_event_count; | 265 | 23 | } |
Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE13_get_internalILNS_16WindowFunnelModeE2EEEiv Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE13_get_internalILNS_16WindowFunnelModeE3EEEiv Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE13_get_internalILNS_16WindowFunnelModeE4EEEiv Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EE13_get_internalILNS_16WindowFunnelModeE1EEEiv Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EE13_get_internalILNS_16WindowFunnelModeE2EEEiv Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EE13_get_internalILNS_16WindowFunnelModeE3EEEiv Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EE13_get_internalILNS_16WindowFunnelModeE4EEEiv |
266 | 26 | int get() const { |
267 | 26 | auto row_count = events_list.size(); |
268 | 26 | if (event_count == 0 || row_count == 0) { |
269 | 2 | return 0; |
270 | 2 | } |
271 | 24 | switch (window_funnel_mode) { |
272 | 24 | case WindowFunnelMode::DEFAULT: |
273 | 24 | return _get_internal<WindowFunnelMode::DEFAULT>(); |
274 | 0 | case WindowFunnelMode::DEDUPLICATION: |
275 | 0 | return _get_internal<WindowFunnelMode::DEDUPLICATION>(); |
276 | 0 | case WindowFunnelMode::FIXED: |
277 | 0 | return _get_internal<WindowFunnelMode::FIXED>(); |
278 | 0 | case WindowFunnelMode::INCREASE: |
279 | 0 | return _get_internal<WindowFunnelMode::INCREASE>(); |
280 | 0 | default: |
281 | 0 | throw doris::Exception(ErrorCode::INTERNAL_ERROR, "Invalid window_funnel mode"); |
282 | 0 | return 0; |
283 | 24 | } |
284 | 24 | } _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE3getEv Line | Count | Source | 266 | 1 | int get() const { | 267 | 1 | auto row_count = events_list.size(); | 268 | 1 | if (event_count == 0 || row_count == 0) { | 269 | 0 | return 0; | 270 | 0 | } | 271 | 1 | switch (window_funnel_mode) { | 272 | 1 | case WindowFunnelMode::DEFAULT: | 273 | 1 | return _get_internal<WindowFunnelMode::DEFAULT>(); | 274 | 0 | case WindowFunnelMode::DEDUPLICATION: | 275 | 0 | return _get_internal<WindowFunnelMode::DEDUPLICATION>(); | 276 | 0 | case WindowFunnelMode::FIXED: | 277 | 0 | return _get_internal<WindowFunnelMode::FIXED>(); | 278 | 0 | case WindowFunnelMode::INCREASE: | 279 | 0 | return _get_internal<WindowFunnelMode::INCREASE>(); | 280 | 0 | default: | 281 | 0 | throw doris::Exception(ErrorCode::INTERNAL_ERROR, "Invalid window_funnel mode"); | 282 | 0 | return 0; | 283 | 1 | } | 284 | 1 | } |
_ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE3getEv Line | Count | Source | 266 | 25 | int get() const { | 267 | 25 | auto row_count = events_list.size(); | 268 | 25 | if (event_count == 0 || row_count == 0) { | 269 | 2 | return 0; | 270 | 2 | } | 271 | 23 | switch (window_funnel_mode) { | 272 | 23 | case WindowFunnelMode::DEFAULT: | 273 | 23 | return _get_internal<WindowFunnelMode::DEFAULT>(); | 274 | 0 | case WindowFunnelMode::DEDUPLICATION: | 275 | 0 | return _get_internal<WindowFunnelMode::DEDUPLICATION>(); | 276 | 0 | case WindowFunnelMode::FIXED: | 277 | 0 | return _get_internal<WindowFunnelMode::FIXED>(); | 278 | 0 | case WindowFunnelMode::INCREASE: | 279 | 0 | return _get_internal<WindowFunnelMode::INCREASE>(); | 280 | 0 | default: | 281 | 0 | throw doris::Exception(ErrorCode::INTERNAL_ERROR, "Invalid window_funnel mode"); | 282 | 0 | return 0; | 283 | 23 | } | 284 | 23 | } |
Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EE3getEv |
285 | | |
286 | 11 | void merge(const WindowFunnelState<T>& other) { |
287 | 11 | if (other.events_list.empty()) { |
288 | 1 | return; |
289 | 1 | } |
290 | 10 | events_list.dt.insert(std::end(events_list.dt), std::begin(other.events_list.dt), |
291 | 10 | std::end(other.events_list.dt)); |
292 | 50 | for (size_t i = 0; i < event_count; i++) { |
293 | 40 | events_list.event_columns_data[i].insert( |
294 | 40 | std::end(events_list.event_columns_data[i]), |
295 | 40 | std::begin(other.events_list.event_columns_data[i]), |
296 | 40 | std::end(other.events_list.event_columns_data[i])); |
297 | 40 | } |
298 | 10 | event_count = event_count > 0 ? event_count : other.event_count; |
299 | 10 | window = window > 0 ? window : other.window; |
300 | 10 | if (enable_mode) { |
301 | 0 | window_funnel_mode = window_funnel_mode == WindowFunnelMode::INVALID |
302 | 0 | ? other.window_funnel_mode |
303 | 0 | : window_funnel_mode; |
304 | 10 | } else { |
305 | 10 | window_funnel_mode = WindowFunnelMode::DEFAULT; |
306 | 10 | } |
307 | 10 | } _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE5mergeERKS2_ Line | Count | Source | 286 | 11 | void merge(const WindowFunnelState<T>& other) { | 287 | 11 | if (other.events_list.empty()) { | 288 | 1 | return; | 289 | 1 | } | 290 | 10 | events_list.dt.insert(std::end(events_list.dt), std::begin(other.events_list.dt), | 291 | 10 | std::end(other.events_list.dt)); | 292 | 50 | for (size_t i = 0; i < event_count; i++) { | 293 | 40 | events_list.event_columns_data[i].insert( | 294 | 40 | std::end(events_list.event_columns_data[i]), | 295 | 40 | std::begin(other.events_list.event_columns_data[i]), | 296 | 40 | std::end(other.events_list.event_columns_data[i])); | 297 | 40 | } | 298 | 10 | event_count = event_count > 0 ? event_count : other.event_count; | 299 | 10 | window = window > 0 ? window : other.window; | 300 | 10 | if (enable_mode) { | 301 | 0 | window_funnel_mode = window_funnel_mode == WindowFunnelMode::INVALID | 302 | 0 | ? other.window_funnel_mode | 303 | 0 | : window_funnel_mode; | 304 | 10 | } else { | 305 | 10 | window_funnel_mode = WindowFunnelMode::DEFAULT; | 306 | 10 | } | 307 | 10 | } |
Unexecuted instantiation: _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE5mergeERKS2_ Unexecuted instantiation: _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EE5mergeERKS2_ |
308 | | |
309 | 3 | void write(BufferWritable& out) const { |
310 | 3 | write_var_int(event_count, out); |
311 | 3 | write_var_int(window, out); |
312 | 3 | if (enable_mode) { |
313 | 1 | write_var_int(static_cast<std::underlying_type_t<WindowFunnelMode>>(window_funnel_mode), |
314 | 1 | out); |
315 | 1 | } |
316 | 3 | auto size = events_list.size(); |
317 | 3 | write_var_int(size, out); |
318 | 5 | for (const auto& timestamp : events_list.dt) { |
319 | 5 | write_var_int(timestamp.to_date_int_val(), out); |
320 | 5 | } |
321 | 12 | for (int64_t i = 0; i < event_count; i++) { |
322 | 9 | const auto& event_columns_data = events_list.event_columns_data[i]; |
323 | 17 | for (auto event : event_columns_data) { |
324 | 17 | write_var_int(event, out); |
325 | 17 | } |
326 | 9 | } |
327 | 3 | } _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE5writeERNS_14BufferWritableE Line | Count | Source | 309 | 1 | void write(BufferWritable& out) const { | 310 | 1 | write_var_int(event_count, out); | 311 | 1 | write_var_int(window, out); | 312 | 1 | if (enable_mode) { | 313 | 1 | write_var_int(static_cast<std::underlying_type_t<WindowFunnelMode>>(window_funnel_mode), | 314 | 1 | out); | 315 | 1 | } | 316 | 1 | auto size = events_list.size(); | 317 | 1 | write_var_int(size, out); | 318 | 1 | for (const auto& timestamp : events_list.dt) { | 319 | 1 | write_var_int(timestamp.to_date_int_val(), out); | 320 | 1 | } | 321 | 2 | for (int64_t i = 0; i < event_count; i++) { | 322 | 1 | const auto& event_columns_data = events_list.event_columns_data[i]; | 323 | 1 | for (auto event : event_columns_data) { | 324 | 1 | write_var_int(event, out); | 325 | 1 | } | 326 | 1 | } | 327 | 1 | } |
_ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE5writeERNS_14BufferWritableE Line | Count | Source | 309 | 2 | void write(BufferWritable& out) const { | 310 | 2 | write_var_int(event_count, out); | 311 | 2 | write_var_int(window, out); | 312 | 2 | if (enable_mode) { | 313 | 0 | write_var_int(static_cast<std::underlying_type_t<WindowFunnelMode>>(window_funnel_mode), | 314 | 0 | out); | 315 | 0 | } | 316 | 2 | auto size = events_list.size(); | 317 | 2 | write_var_int(size, out); | 318 | 4 | for (const auto& timestamp : events_list.dt) { | 319 | 4 | write_var_int(timestamp.to_date_int_val(), out); | 320 | 4 | } | 321 | 10 | for (int64_t i = 0; i < event_count; i++) { | 322 | 8 | const auto& event_columns_data = events_list.event_columns_data[i]; | 323 | 16 | for (auto event : event_columns_data) { | 324 | 16 | write_var_int(event, out); | 325 | 16 | } | 326 | 8 | } | 327 | 2 | } |
Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EE5writeERNS_14BufferWritableE |
328 | | |
329 | 3 | void read(BufferReadable& in) { |
330 | 3 | int64_t event_level; |
331 | 3 | read_var_int(event_level, in); |
332 | 3 | event_count = (int)event_level; |
333 | 3 | read_var_int(window, in); |
334 | 3 | window_funnel_mode = WindowFunnelMode::DEFAULT; |
335 | 3 | if (enable_mode) { |
336 | 1 | int64_t mode; |
337 | 1 | read_var_int(mode, in); |
338 | 1 | window_funnel_mode = static_cast<WindowFunnelMode>(mode); |
339 | 1 | } |
340 | 3 | int64_t size = 0; |
341 | 3 | read_var_int(size, in); |
342 | 3 | events_list.clear(); |
343 | 3 | events_list.dt.resize(size); |
344 | 8 | for (auto i = 0; i < size; i++) { |
345 | 5 | Int64 timestamp = 0; |
346 | 5 | read_var_int(timestamp, in); |
347 | 5 | if constexpr (T == TYPE_TIMESTAMP_NS) { |
348 | 1 | events_list.dt[i] = DateValueType(timestamp); |
349 | 4 | } else { |
350 | 4 | events_list.dt[i] = DateValueType(static_cast<UInt64>(timestamp)); |
351 | 4 | } |
352 | 5 | } |
353 | 3 | events_list.event_columns_data.resize(event_count); |
354 | 12 | for (int64_t i = 0; i < event_count; i++) { |
355 | 9 | auto& event_columns_data = events_list.event_columns_data[i]; |
356 | 9 | event_columns_data.resize(size); |
357 | 26 | for (auto j = 0; j < size; j++) { |
358 | 17 | Int64 temp_value; |
359 | 17 | read_var_int(temp_value, in); |
360 | 17 | event_columns_data[j] = static_cast<UInt8>(temp_value); |
361 | 17 | } |
362 | 9 | } |
363 | 3 | } _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE4readERNS_14BufferReadableE Line | Count | Source | 329 | 1 | void read(BufferReadable& in) { | 330 | 1 | int64_t event_level; | 331 | 1 | read_var_int(event_level, in); | 332 | 1 | event_count = (int)event_level; | 333 | 1 | read_var_int(window, in); | 334 | 1 | window_funnel_mode = WindowFunnelMode::DEFAULT; | 335 | 1 | if (enable_mode) { | 336 | 1 | int64_t mode; | 337 | 1 | read_var_int(mode, in); | 338 | 1 | window_funnel_mode = static_cast<WindowFunnelMode>(mode); | 339 | 1 | } | 340 | 1 | int64_t size = 0; | 341 | 1 | read_var_int(size, in); | 342 | 1 | events_list.clear(); | 343 | 1 | events_list.dt.resize(size); | 344 | 2 | for (auto i = 0; i < size; i++) { | 345 | 1 | Int64 timestamp = 0; | 346 | 1 | read_var_int(timestamp, in); | 347 | 1 | if constexpr (T == TYPE_TIMESTAMP_NS) { | 348 | 1 | events_list.dt[i] = DateValueType(timestamp); | 349 | | } else { | 350 | | events_list.dt[i] = DateValueType(static_cast<UInt64>(timestamp)); | 351 | | } | 352 | 1 | } | 353 | 1 | events_list.event_columns_data.resize(event_count); | 354 | 2 | for (int64_t i = 0; i < event_count; i++) { | 355 | 1 | auto& event_columns_data = events_list.event_columns_data[i]; | 356 | 1 | event_columns_data.resize(size); | 357 | 2 | for (auto j = 0; j < size; j++) { | 358 | 1 | Int64 temp_value; | 359 | 1 | read_var_int(temp_value, in); | 360 | 1 | event_columns_data[j] = static_cast<UInt8>(temp_value); | 361 | 1 | } | 362 | 1 | } | 363 | 1 | } |
_ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE4readERNS_14BufferReadableE Line | Count | Source | 329 | 2 | void read(BufferReadable& in) { | 330 | 2 | int64_t event_level; | 331 | 2 | read_var_int(event_level, in); | 332 | 2 | event_count = (int)event_level; | 333 | 2 | read_var_int(window, in); | 334 | 2 | window_funnel_mode = WindowFunnelMode::DEFAULT; | 335 | 2 | if (enable_mode) { | 336 | 0 | int64_t mode; | 337 | 0 | read_var_int(mode, in); | 338 | 0 | window_funnel_mode = static_cast<WindowFunnelMode>(mode); | 339 | 0 | } | 340 | 2 | int64_t size = 0; | 341 | 2 | read_var_int(size, in); | 342 | 2 | events_list.clear(); | 343 | 2 | events_list.dt.resize(size); | 344 | 6 | for (auto i = 0; i < size; i++) { | 345 | 4 | Int64 timestamp = 0; | 346 | 4 | read_var_int(timestamp, in); | 347 | | if constexpr (T == TYPE_TIMESTAMP_NS) { | 348 | | events_list.dt[i] = DateValueType(timestamp); | 349 | 4 | } else { | 350 | 4 | events_list.dt[i] = DateValueType(static_cast<UInt64>(timestamp)); | 351 | 4 | } | 352 | 4 | } | 353 | 2 | events_list.event_columns_data.resize(event_count); | 354 | 10 | for (int64_t i = 0; i < event_count; i++) { | 355 | 8 | auto& event_columns_data = events_list.event_columns_data[i]; | 356 | 8 | event_columns_data.resize(size); | 357 | 24 | for (auto j = 0; j < size; j++) { | 358 | 16 | Int64 temp_value; | 359 | 16 | read_var_int(temp_value, in); | 360 | 16 | event_columns_data[j] = static_cast<UInt8>(temp_value); | 361 | 16 | } | 362 | 8 | } | 363 | 2 | } |
Unexecuted instantiation: _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EE4readERNS_14BufferReadableE |
364 | | }; |
365 | | |
366 | | template <PrimitiveType T> |
367 | | class AggregateFunctionWindowFunnel final |
368 | | : public IAggregateFunctionDataHelper<WindowFunnelState<T>, |
369 | | AggregateFunctionWindowFunnel<T>>, |
370 | | MultiExpression, |
371 | | NullableAggregateFunction { |
372 | | public: |
373 | | AggregateFunctionWindowFunnel(const DataTypes& argument_types_) |
374 | 9 | : IAggregateFunctionDataHelper<WindowFunnelState<T>, AggregateFunctionWindowFunnel<T>>( |
375 | 9 | argument_types_) {}_ZN5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE26EEC2ERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 374 | 8 | : IAggregateFunctionDataHelper<WindowFunnelState<T>, AggregateFunctionWindowFunnel<T>>( | 375 | 8 | argument_types_) {} |
_ZN5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE43EEC2ERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 374 | 1 | : IAggregateFunctionDataHelper<WindowFunnelState<T>, AggregateFunctionWindowFunnel<T>>( | 375 | 1 | argument_types_) {} |
Unexecuted instantiation: _ZN5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE42EEC2ERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE |
376 | | |
377 | 35 | void create(AggregateDataPtr __restrict place) const override { |
378 | 35 | auto data = new (place) WindowFunnelState<T>( |
379 | 35 | cast_set<int>(IAggregateFunction::get_argument_types().size() - 3)); |
380 | | /// support window funnel mode from 2.0. See `BeExecVersionManager::max_be_exec_version` |
381 | 35 | data->enable_mode = IAggregateFunction::version >= 3; |
382 | 35 | } _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE26EE6createEPc Line | Count | Source | 377 | 35 | void create(AggregateDataPtr __restrict place) const override { | 378 | 35 | auto data = new (place) WindowFunnelState<T>( | 379 | 35 | cast_set<int>(IAggregateFunction::get_argument_types().size() - 3)); | 380 | | /// support window funnel mode from 2.0. See `BeExecVersionManager::max_be_exec_version` | 381 | 35 | data->enable_mode = IAggregateFunction::version >= 3; | 382 | 35 | } |
Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE43EE6createEPc Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE42EE6createEPc |
383 | | |
384 | 0 | String get_name() const override { return "window_funnel"; }Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE26EE8get_nameB5cxx11Ev Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE43EE8get_nameB5cxx11Ev Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE42EE8get_nameB5cxx11Ev |
385 | | |
386 | 0 | DataTypePtr get_return_type() const override { return std::make_shared<DataTypeInt32>(); }Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE26EE15get_return_typeEv Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE43EE15get_return_typeEv Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE42EE15get_return_typeEv |
387 | | |
388 | 0 | void reset(AggregateDataPtr __restrict place) const override { this->data(place).reset(); }Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE26EE5resetEPc Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE43EE5resetEPc Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE42EE5resetEPc |
389 | | |
390 | | void add(AggregateDataPtr __restrict place, const IColumn** columns, ssize_t row_num, |
391 | 86 | Arena&) const override { |
392 | 86 | const auto& window = |
393 | 86 | assert_cast<const ColumnInt64&, TypeCheckOnRelease::DISABLE>(*columns[0]) |
394 | 86 | .get_data()[row_num]; |
395 | 86 | StringRef mode = columns[1]->get_data_at(row_num); |
396 | 86 | this->data(place).add(columns, row_num, window, |
397 | 86 | string_to_window_funnel_mode(mode.to_string())); |
398 | 86 | } _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE26EE3addEPcPPKNS_7IColumnElRNS_5ArenaE Line | Count | Source | 391 | 86 | Arena&) const override { | 392 | 86 | const auto& window = | 393 | 86 | assert_cast<const ColumnInt64&, TypeCheckOnRelease::DISABLE>(*columns[0]) | 394 | 86 | .get_data()[row_num]; | 395 | 86 | StringRef mode = columns[1]->get_data_at(row_num); | 396 | 86 | this->data(place).add(columns, row_num, window, | 397 | 86 | string_to_window_funnel_mode(mode.to_string())); | 398 | 86 | } |
Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE43EE3addEPcPPKNS_7IColumnElRNS_5ArenaE Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE42EE3addEPcPPKNS_7IColumnElRNS_5ArenaE |
399 | | |
400 | 0 | void check_input_columns_type(const IColumn** columns) const override { |
401 | 0 | this->template check_argument_column_type<ColumnInt64>(columns[0]); |
402 | 0 | this->template check_argument_column_type<ColumnString>(columns[1]); |
403 | 0 | this->template check_argument_column_type<typename PrimitiveTypeTraits<T>::ColumnType>( |
404 | 0 | columns[2]); |
405 | 0 | for (size_t i = 3; i < this->argument_types.size(); ++i) { |
406 | 0 | this->template check_argument_column_type<ColumnUInt8>(columns[i]); |
407 | 0 | } |
408 | 0 | } Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE26EE24check_input_columns_typeEPPKNS_7IColumnE Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE43EE24check_input_columns_typeEPPKNS_7IColumnE Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE42EE24check_input_columns_typeEPPKNS_7IColumnE |
409 | | |
410 | | void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, |
411 | 11 | Arena&) const override { |
412 | 11 | this->data(place).merge(this->data(rhs)); |
413 | 11 | } _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE26EE5mergeEPcPKcRNS_5ArenaE Line | Count | Source | 411 | 11 | Arena&) const override { | 412 | 11 | this->data(place).merge(this->data(rhs)); | 413 | 11 | } |
Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE43EE5mergeEPcPKcRNS_5ArenaE Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE42EE5mergeEPcPKcRNS_5ArenaE |
414 | | |
415 | 2 | void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const override { |
416 | 2 | this->data(place).write(buf); |
417 | 2 | } _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE26EE9serializeEPKcRNS_14BufferWritableE Line | Count | Source | 415 | 2 | void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const override { | 416 | 2 | this->data(place).write(buf); | 417 | 2 | } |
Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE43EE9serializeEPKcRNS_14BufferWritableE Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE42EE9serializeEPKcRNS_14BufferWritableE |
418 | | |
419 | | void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, |
420 | 2 | Arena&) const override { |
421 | 2 | this->data(place).read(buf); |
422 | 2 | } _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE26EE11deserializeEPcRNS_14BufferReadableERNS_5ArenaE Line | Count | Source | 420 | 2 | Arena&) const override { | 421 | 2 | this->data(place).read(buf); | 422 | 2 | } |
Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE43EE11deserializeEPcRNS_14BufferReadableERNS_5ArenaE Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE42EE11deserializeEPcRNS_14BufferReadableERNS_5ArenaE |
423 | | |
424 | 25 | void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override { |
425 | | // place is essentially an AggregateDataPtr, passed as a ConstAggregateDataPtr. |
426 | 25 | this->data(const_cast<AggregateDataPtr>(place)).sort(); |
427 | 25 | assert_cast<ColumnInt32&, TypeCheckOnRelease::DISABLE>(to).get_data().push_back( |
428 | 25 | IAggregateFunctionDataHelper<WindowFunnelState<T>, |
429 | 25 | AggregateFunctionWindowFunnel<T>>::data(place) |
430 | 25 | .get()); |
431 | 25 | } _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE26EE18insert_result_intoEPKcRNS_7IColumnE Line | Count | Source | 424 | 25 | void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override { | 425 | | // place is essentially an AggregateDataPtr, passed as a ConstAggregateDataPtr. | 426 | 25 | this->data(const_cast<AggregateDataPtr>(place)).sort(); | 427 | 25 | assert_cast<ColumnInt32&, TypeCheckOnRelease::DISABLE>(to).get_data().push_back( | 428 | 25 | IAggregateFunctionDataHelper<WindowFunnelState<T>, | 429 | 25 | AggregateFunctionWindowFunnel<T>>::data(place) | 430 | 25 | .get()); | 431 | 25 | } |
Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE43EE18insert_result_intoEPKcRNS_7IColumnE Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE42EE18insert_result_intoEPKcRNS_7IColumnE |
432 | | |
433 | | protected: |
434 | | using IAggregateFunction::version; |
435 | | }; |
436 | | } // namespace doris |