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 | 837 | inline WindowFunnelMode string_to_window_funnel_mode(const String& string) { |
60 | 837 | if (string == "default") { |
61 | 547 | return WindowFunnelMode::DEFAULT; |
62 | 547 | } else if (string == "deduplication") { |
63 | 36 | return WindowFunnelMode::DEDUPLICATION; |
64 | 254 | } else if (string == "fixed") { |
65 | 139 | return WindowFunnelMode::FIXED; |
66 | 139 | } else if (string == "increase") { |
67 | 18 | return WindowFunnelMode::INCREASE; |
68 | 97 | } else { |
69 | 97 | return WindowFunnelMode::INVALID; |
70 | 97 | } |
71 | 837 | } |
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 | 132 | void clear() { |
81 | 132 | dt.clear(); |
82 | 267 | for (auto& data : event_columns_data) { |
83 | 267 | data.clear(); |
84 | 267 | } |
85 | 132 | } _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 | 131 | void clear() { | 81 | 131 | dt.clear(); | 82 | 266 | for (auto& data : event_columns_data) { | 83 | 266 | data.clear(); | 84 | 266 | } | 85 | 131 | } |
Unexecuted instantiation: _ZN5doris9DataValueILNS_13PrimitiveTypeE42EE5clearEv |
86 | 779 | 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 | 776 | auto size() const { return dt.size(); } |
Unexecuted instantiation: _ZNK5doris9DataValueILNS_13PrimitiveTypeE42EE4sizeEv |
87 | 363 | bool empty() const { return dt.empty(); }_ZNK5doris9DataValueILNS_13PrimitiveTypeE26EE5emptyEv Line | Count | Source | 87 | 363 | 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 | 534 | WindowFunnelState() { |
114 | 534 | event_count = 0; |
115 | 534 | window = 0; |
116 | 534 | window_funnel_mode = WindowFunnelMode::INVALID; |
117 | 534 | } _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 | 531 | WindowFunnelState() { | 114 | 531 | event_count = 0; | 115 | 531 | window = 0; | 116 | 531 | window_funnel_mode = WindowFunnelMode::INVALID; | 117 | 531 | } |
Unexecuted instantiation: _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EEC2Ev |
118 | 534 | WindowFunnelState(int arg_event_count) : WindowFunnelState() { |
119 | 534 | event_count = arg_event_count; |
120 | 534 | events_list.event_columns_data.resize(event_count); |
121 | 534 | } _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 | 531 | WindowFunnelState(int arg_event_count) : WindowFunnelState() { | 119 | 531 | event_count = arg_event_count; | 120 | 531 | events_list.event_columns_data.resize(event_count); | 121 | 531 | } |
Unexecuted instantiation: _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EEC2Ei |
122 | | |
123 | 12 | void reset() { |
124 | 12 | events_list.clear(); |
125 | 12 | window = 0; |
126 | 12 | window_funnel_mode = WindowFunnelMode::INVALID; |
127 | 12 | } _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE5resetEv Line | Count | Source | 123 | 12 | void reset() { | 124 | 12 | events_list.clear(); | 125 | 12 | window = 0; | 126 | 12 | window_funnel_mode = WindowFunnelMode::INVALID; | 127 | 12 | } |
Unexecuted instantiation: _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE5resetEv Unexecuted instantiation: _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EE5resetEv |
128 | | |
129 | 374 | void add(const IColumn** arg_columns, ssize_t row_num, int64_t win, WindowFunnelMode mode) { |
130 | 374 | window = win; |
131 | 374 | window_funnel_mode = enable_mode ? mode : WindowFunnelMode::DEFAULT; |
132 | 374 | events_list.dt.emplace_back( |
133 | 374 | assert_cast<const typename PrimitiveTypeTraits<PType>::ColumnType&, |
134 | 374 | TypeCheckOnRelease::DISABLE>(*arg_columns[2]) |
135 | 374 | .get_data()[row_num]); |
136 | 1.29k | for (int i = 0; i < event_count; i++) { |
137 | 916 | events_list.event_columns_data[i].emplace_back( |
138 | 916 | assert_cast<const ColumnUInt8&, TypeCheckOnRelease::DISABLE>( |
139 | 916 | *arg_columns[3 + i]) |
140 | 916 | .get_data()[row_num]); |
141 | 916 | } |
142 | 374 | } _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE3addEPPKNS_7IColumnEllNS_16WindowFunnelModeE Line | Count | Source | 129 | 374 | void add(const IColumn** arg_columns, ssize_t row_num, int64_t win, WindowFunnelMode mode) { | 130 | 374 | window = win; | 131 | 374 | window_funnel_mode = enable_mode ? mode : WindowFunnelMode::DEFAULT; | 132 | 374 | events_list.dt.emplace_back( | 133 | 374 | assert_cast<const typename PrimitiveTypeTraits<PType>::ColumnType&, | 134 | 374 | TypeCheckOnRelease::DISABLE>(*arg_columns[2]) | 135 | 374 | .get_data()[row_num]); | 136 | 1.29k | for (int i = 0; i < event_count; i++) { | 137 | 916 | events_list.event_columns_data[i].emplace_back( | 138 | 916 | assert_cast<const ColumnUInt8&, TypeCheckOnRelease::DISABLE>( | 139 | 916 | *arg_columns[3 + i]) | 140 | 916 | .get_data()[row_num]); | 141 | 916 | } | 142 | 374 | } |
Unexecuted instantiation: _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE3addEPPKNS_7IColumnEllNS_16WindowFunnelModeE Unexecuted instantiation: _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EE3addEPPKNS_7IColumnEllNS_16WindowFunnelModeE |
143 | | |
144 | | // todo: rethink thid sort method. |
145 | 229 | void sort() { |
146 | 229 | auto num = events_list.size(); |
147 | 229 | std::vector<size_t> indices(num); |
148 | 229 | std::iota(indices.begin(), indices.end(), 0); |
149 | 229 | std::sort(indices.begin(), indices.end(), |
150 | 229 | [this](size_t i1, size_t i2) { return events_list.dt[i1] < events_list.dt[i2]; });_ZZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE4sortEvENKUlmmE_clEmm Line | Count | Source | 150 | 184 | [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 |
151 | | |
152 | 735 | auto reorder = [&indices, &num](auto& vec) { |
153 | 735 | std::decay_t<decltype(vec)> temp; |
154 | 735 | temp.resize(num); |
155 | 1.90k | for (auto i = 0; i < num; i++) { |
156 | 1.16k | temp[i] = vec[indices[i]]; |
157 | 1.16k | } |
158 | 735 | std::swap(vec, temp); |
159 | 735 | }; _ZZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE4sortEvENKUlRT_E_clISt6vectorINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEESaISA_EEEEDaS4_ Line | Count | Source | 152 | 229 | auto reorder = [&indices, &num](auto& vec) { | 153 | 229 | std::decay_t<decltype(vec)> temp; | 154 | 229 | temp.resize(num); | 155 | 559 | for (auto i = 0; i < num; i++) { | 156 | 330 | temp[i] = vec[indices[i]]; | 157 | 330 | } | 158 | 229 | std::swap(vec, temp); | 159 | 229 | }; |
_ZZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE4sortEvENKUlRT_E_clINS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEEEDaS4_ Line | Count | Source | 152 | 506 | auto reorder = [&indices, &num](auto& vec) { | 153 | 506 | std::decay_t<decltype(vec)> temp; | 154 | 506 | temp.resize(num); | 155 | 1.34k | for (auto i = 0; i < num; i++) { | 156 | 836 | temp[i] = vec[indices[i]]; | 157 | 836 | } | 158 | 506 | std::swap(vec, temp); | 159 | 506 | }; |
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_ |
160 | | |
161 | 229 | reorder(events_list.dt); |
162 | 506 | for (auto& inner_vec : events_list.event_columns_data) { |
163 | 506 | reorder(inner_vec); |
164 | 506 | } |
165 | 229 | } _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE4sortEv Line | Count | Source | 145 | 229 | void sort() { | 146 | 229 | auto num = events_list.size(); | 147 | 229 | std::vector<size_t> indices(num); | 148 | 229 | std::iota(indices.begin(), indices.end(), 0); | 149 | 229 | std::sort(indices.begin(), indices.end(), | 150 | 229 | [this](size_t i1, size_t i2) { return events_list.dt[i1] < events_list.dt[i2]; }); | 151 | | | 152 | 229 | auto reorder = [&indices, &num](auto& vec) { | 153 | 229 | std::decay_t<decltype(vec)> temp; | 154 | 229 | temp.resize(num); | 155 | 229 | for (auto i = 0; i < num; i++) { | 156 | 229 | temp[i] = vec[indices[i]]; | 157 | 229 | } | 158 | 229 | std::swap(vec, temp); | 159 | 229 | }; | 160 | | | 161 | 229 | reorder(events_list.dt); | 162 | 506 | for (auto& inner_vec : events_list.event_columns_data) { | 163 | 506 | reorder(inner_vec); | 164 | 506 | } | 165 | 229 | } |
Unexecuted instantiation: _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE4sortEv Unexecuted instantiation: _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EE4sortEv |
166 | | |
167 | | bool _within_window(const DateValueType& base_timestamp, |
168 | 59 | const DateValueType& current_timestamp) const { |
169 | 59 | if constexpr (T == TYPE_TIMESTAMP_NS) { |
170 | 1 | const auto elapsed_nanos = static_cast<__int128>(current_timestamp.epoch_nanos()) - |
171 | 1 | base_timestamp.epoch_nanos(); |
172 | 1 | const auto window_nanos = |
173 | 1 | static_cast<__int128>(window) * TimeStampNsValue::NANOS_PER_SECOND; |
174 | 1 | return elapsed_nanos <= window_nanos; |
175 | 1 | } |
176 | 0 | return static_cast<__int128>(current_timestamp.datetime_diff_in_microseconds( |
177 | 59 | base_timestamp)) <= static_cast<__int128>(window) * 1000000; |
178 | 59 | } _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE14_within_windowERKNS_16TimeStampNsValueES5_ Line | Count | Source | 168 | 1 | const DateValueType& current_timestamp) const { | 169 | 1 | if constexpr (T == TYPE_TIMESTAMP_NS) { | 170 | 1 | const auto elapsed_nanos = static_cast<__int128>(current_timestamp.epoch_nanos()) - | 171 | 1 | base_timestamp.epoch_nanos(); | 172 | 1 | const auto window_nanos = | 173 | 1 | static_cast<__int128>(window) * TimeStampNsValue::NANOS_PER_SECOND; | 174 | 1 | return elapsed_nanos <= window_nanos; | 175 | 1 | } | 176 | 0 | return static_cast<__int128>(current_timestamp.datetime_diff_in_microseconds( | 177 | 1 | base_timestamp)) <= static_cast<__int128>(window) * 1000000; | 178 | 1 | } |
_ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE14_within_windowERKNS_11DateV2ValueINS_19DateTimeV2ValueTypeEEES7_ Line | Count | Source | 168 | 58 | const DateValueType& current_timestamp) const { | 169 | | if constexpr (T == TYPE_TIMESTAMP_NS) { | 170 | | const auto elapsed_nanos = static_cast<__int128>(current_timestamp.epoch_nanos()) - | 171 | | base_timestamp.epoch_nanos(); | 172 | | const auto window_nanos = | 173 | | static_cast<__int128>(window) * TimeStampNsValue::NANOS_PER_SECOND; | 174 | | return elapsed_nanos <= window_nanos; | 175 | | } | 176 | 58 | return static_cast<__int128>(current_timestamp.datetime_diff_in_microseconds( | 177 | 58 | base_timestamp)) <= static_cast<__int128>(window) * 1000000; | 178 | 58 | } |
Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EE14_within_windowERKNS_16TimestampTzValueES5_ |
179 | | |
180 | | template <WindowFunnelMode WINDOW_FUNNEL_MODE> |
181 | 258 | int _match_event_list(size_t& start_row, size_t row_count) const { |
182 | 258 | int matched_count = 0; |
183 | 258 | if (window < 0) { |
184 | 0 | throw Exception(ErrorCode::INVALID_ARGUMENT, |
185 | 0 | "the sliding time window must be a positive integer, but got: {}", |
186 | 0 | window); |
187 | 0 | } |
188 | 258 | int column_idx = 0; |
189 | 212 | const auto& timestamp_data = events_list.dt; |
190 | 212 | const auto& first_event_data = events_list.event_columns_data[column_idx].data(); |
191 | 212 | auto match_row = simd::find_one(first_event_data, start_row, row_count); |
192 | 212 | start_row = match_row + 1; |
193 | 258 | if (match_row < row_count) { |
194 | 144 | auto prev_timestamp = timestamp_data[match_row]; |
195 | 144 | const auto first_timestamp = prev_timestamp; |
196 | 144 | matched_count++; |
197 | 144 | column_idx++; |
198 | 144 | auto last_match_row = match_row; |
199 | 144 | ++match_row; |
200 | 186 | for (; column_idx < event_count && match_row < row_count; column_idx++, match_row++) { |
201 | 76 | const auto& event_data = events_list.event_columns_data[column_idx]; |
202 | 76 | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::FIXED) { |
203 | 4 | if (event_data[match_row] == 1) { |
204 | 0 | auto current_timestamp = timestamp_data[match_row]; |
205 | 0 | if (_within_window(first_timestamp, current_timestamp)) { |
206 | 0 | matched_count++; |
207 | 0 | continue; |
208 | 0 | } |
209 | 0 | } |
210 | 4 | break; |
211 | 4 | } |
212 | 4 | match_row = simd::find_one(event_data.data(), match_row, row_count); |
213 | 76 | if (match_row < row_count) { |
214 | 56 | auto current_timestamp = timestamp_data[match_row]; |
215 | 56 | bool is_matched = _within_window(first_timestamp, current_timestamp); |
216 | 56 | if (is_matched) { |
217 | 42 | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::INCREASE) { |
218 | 0 | is_matched = current_timestamp > prev_timestamp; |
219 | 0 | } |
220 | 42 | } |
221 | 56 | if (!is_matched) { |
222 | 14 | break; |
223 | 14 | } |
224 | 42 | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::INCREASE) { |
225 | 0 | prev_timestamp = timestamp_data[match_row]; |
226 | 0 | } |
227 | 42 | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::DEDUPLICATION) { |
228 | 0 | bool is_dup = false; |
229 | 0 | if (match_row != last_match_row + 1) { |
230 | 0 | for (int tmp_column_idx = 0; tmp_column_idx < column_idx; |
231 | 0 | tmp_column_idx++) { |
232 | 0 | const auto& tmp_event_data = |
233 | 0 | events_list.event_columns_data[tmp_column_idx].data(); |
234 | 0 | auto dup_match_row = simd::find_one(tmp_event_data, |
235 | 0 | last_match_row + 1, match_row); |
236 | 0 | if (dup_match_row < match_row) { |
237 | 0 | is_dup = true; |
238 | 0 | break; |
239 | 0 | } |
240 | 0 | } |
241 | 0 | } |
242 | 0 | if (is_dup) { |
243 | 0 | break; |
244 | 0 | } |
245 | 0 | last_match_row = match_row; |
246 | 0 | } |
247 | 0 | matched_count++; |
248 | 42 | } else { |
249 | 20 | break; |
250 | 20 | } |
251 | 76 | } |
252 | 144 | } |
253 | 50 | return matched_count; |
254 | 46 | } _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE17_match_event_listILNS_16WindowFunnelModeE1EEEiRmm Line | Count | Source | 181 | 1 | int _match_event_list(size_t& start_row, size_t row_count) const { | 182 | 1 | int matched_count = 0; | 183 | 1 | if (window < 0) { | 184 | 0 | throw Exception(ErrorCode::INVALID_ARGUMENT, | 185 | 0 | "the sliding time window must be a positive integer, but got: {}", | 186 | 0 | window); | 187 | 0 | } | 188 | 1 | int column_idx = 0; | 189 | 1 | const auto& timestamp_data = events_list.dt; | 190 | 1 | const auto& first_event_data = events_list.event_columns_data[column_idx].data(); | 191 | 1 | auto match_row = simd::find_one(first_event_data, start_row, row_count); | 192 | 1 | start_row = match_row + 1; | 193 | 1 | if (match_row < row_count) { | 194 | 1 | auto prev_timestamp = timestamp_data[match_row]; | 195 | 1 | const auto first_timestamp = prev_timestamp; | 196 | 1 | matched_count++; | 197 | 1 | column_idx++; | 198 | 1 | auto last_match_row = match_row; | 199 | 1 | ++match_row; | 200 | 2 | for (; column_idx < event_count && match_row < row_count; column_idx++, match_row++) { | 201 | 1 | const auto& event_data = events_list.event_columns_data[column_idx]; | 202 | | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::FIXED) { | 203 | | if (event_data[match_row] == 1) { | 204 | | auto current_timestamp = timestamp_data[match_row]; | 205 | | if (_within_window(first_timestamp, current_timestamp)) { | 206 | | matched_count++; | 207 | | continue; | 208 | | } | 209 | | } | 210 | | break; | 211 | | } | 212 | 1 | match_row = simd::find_one(event_data.data(), match_row, row_count); | 213 | 1 | if (match_row < row_count) { | 214 | 1 | auto current_timestamp = timestamp_data[match_row]; | 215 | 1 | bool is_matched = _within_window(first_timestamp, current_timestamp); | 216 | 1 | if (is_matched) { | 217 | | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::INCREASE) { | 218 | | is_matched = current_timestamp > prev_timestamp; | 219 | | } | 220 | 1 | } | 221 | 1 | if (!is_matched) { | 222 | 0 | break; | 223 | 0 | } | 224 | | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::INCREASE) { | 225 | | prev_timestamp = timestamp_data[match_row]; | 226 | | } | 227 | | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::DEDUPLICATION) { | 228 | | bool is_dup = false; | 229 | | if (match_row != last_match_row + 1) { | 230 | | for (int tmp_column_idx = 0; tmp_column_idx < column_idx; | 231 | | tmp_column_idx++) { | 232 | | const auto& tmp_event_data = | 233 | | events_list.event_columns_data[tmp_column_idx].data(); | 234 | | auto dup_match_row = simd::find_one(tmp_event_data, | 235 | | last_match_row + 1, match_row); | 236 | | if (dup_match_row < match_row) { | 237 | | is_dup = true; | 238 | | break; | 239 | | } | 240 | | } | 241 | | } | 242 | | if (is_dup) { | 243 | | break; | 244 | | } | 245 | | last_match_row = match_row; | 246 | | } | 247 | 1 | matched_count++; | 248 | 1 | } else { | 249 | 0 | break; | 250 | 0 | } | 251 | 1 | } | 252 | 1 | } | 253 | 1 | return matched_count; | 254 | 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 | 181 | 211 | int _match_event_list(size_t& start_row, size_t row_count) const { | 182 | 211 | int matched_count = 0; | 183 | 211 | if (window < 0) { | 184 | 0 | throw Exception(ErrorCode::INVALID_ARGUMENT, | 185 | 0 | "the sliding time window must be a positive integer, but got: {}", | 186 | 0 | window); | 187 | 0 | } | 188 | 211 | int column_idx = 0; | 189 | 211 | const auto& timestamp_data = events_list.dt; | 190 | 211 | const auto& first_event_data = events_list.event_columns_data[column_idx].data(); | 191 | 211 | auto match_row = simd::find_one(first_event_data, start_row, row_count); | 192 | 211 | start_row = match_row + 1; | 193 | 211 | if (match_row < row_count) { | 194 | 111 | auto prev_timestamp = timestamp_data[match_row]; | 195 | 111 | const auto first_timestamp = prev_timestamp; | 196 | 111 | matched_count++; | 197 | 111 | column_idx++; | 198 | 111 | auto last_match_row = match_row; | 199 | 111 | ++match_row; | 200 | 152 | for (; column_idx < event_count && match_row < row_count; column_idx++, match_row++) { | 201 | 71 | const auto& event_data = events_list.event_columns_data[column_idx]; | 202 | | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::FIXED) { | 203 | | if (event_data[match_row] == 1) { | 204 | | auto current_timestamp = timestamp_data[match_row]; | 205 | | if (_within_window(first_timestamp, current_timestamp)) { | 206 | | matched_count++; | 207 | | continue; | 208 | | } | 209 | | } | 210 | | break; | 211 | | } | 212 | 71 | match_row = simd::find_one(event_data.data(), match_row, row_count); | 213 | 71 | if (match_row < row_count) { | 214 | 55 | auto current_timestamp = timestamp_data[match_row]; | 215 | 55 | bool is_matched = _within_window(first_timestamp, current_timestamp); | 216 | 55 | if (is_matched) { | 217 | | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::INCREASE) { | 218 | | is_matched = current_timestamp > prev_timestamp; | 219 | | } | 220 | 41 | } | 221 | 55 | if (!is_matched) { | 222 | 14 | break; | 223 | 14 | } | 224 | | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::INCREASE) { | 225 | | prev_timestamp = timestamp_data[match_row]; | 226 | | } | 227 | | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::DEDUPLICATION) { | 228 | | bool is_dup = false; | 229 | | if (match_row != last_match_row + 1) { | 230 | | for (int tmp_column_idx = 0; tmp_column_idx < column_idx; | 231 | | tmp_column_idx++) { | 232 | | const auto& tmp_event_data = | 233 | | events_list.event_columns_data[tmp_column_idx].data(); | 234 | | auto dup_match_row = simd::find_one(tmp_event_data, | 235 | | last_match_row + 1, match_row); | 236 | | if (dup_match_row < match_row) { | 237 | | is_dup = true; | 238 | | break; | 239 | | } | 240 | | } | 241 | | } | 242 | | if (is_dup) { | 243 | | break; | 244 | | } | 245 | | last_match_row = match_row; | 246 | | } | 247 | 41 | matched_count++; | 248 | 41 | } else { | 249 | 16 | break; | 250 | 16 | } | 251 | 71 | } | 252 | 111 | } | 253 | 211 | return matched_count; | 254 | 211 | } |
Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE17_match_event_listILNS_16WindowFunnelModeE2EEEiRmm _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE17_match_event_listILNS_16WindowFunnelModeE3EEEiRmm Line | Count | Source | 181 | 46 | int _match_event_list(size_t& start_row, size_t row_count) const { | 182 | 46 | int matched_count = 0; | 183 | 46 | if (window < 0) { | 184 | 0 | throw Exception(ErrorCode::INVALID_ARGUMENT, | 185 | 0 | "the sliding time window must be a positive integer, but got: {}", | 186 | 0 | window); | 187 | 0 | } | 188 | 46 | int column_idx = 0; | 189 | 46 | const auto& timestamp_data = events_list.dt; | 190 | 46 | const auto& first_event_data = events_list.event_columns_data[column_idx].data(); | 191 | 46 | auto match_row = simd::find_one(first_event_data, start_row, row_count); | 192 | 46 | start_row = match_row + 1; | 193 | 46 | if (match_row < row_count) { | 194 | 32 | auto prev_timestamp = timestamp_data[match_row]; | 195 | 32 | const auto first_timestamp = prev_timestamp; | 196 | 32 | matched_count++; | 197 | 32 | column_idx++; | 198 | 32 | auto last_match_row = match_row; | 199 | 32 | ++match_row; | 200 | 32 | for (; column_idx < event_count && match_row < row_count; column_idx++, match_row++) { | 201 | 4 | const auto& event_data = events_list.event_columns_data[column_idx]; | 202 | 4 | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::FIXED) { | 203 | 4 | if (event_data[match_row] == 1) { | 204 | 0 | auto current_timestamp = timestamp_data[match_row]; | 205 | 0 | if (_within_window(first_timestamp, current_timestamp)) { | 206 | 0 | matched_count++; | 207 | 0 | continue; | 208 | 0 | } | 209 | 0 | } | 210 | 4 | break; | 211 | 4 | } | 212 | 4 | match_row = simd::find_one(event_data.data(), match_row, row_count); | 213 | 4 | if (match_row < row_count) { | 214 | 0 | auto current_timestamp = timestamp_data[match_row]; | 215 | 0 | bool is_matched = _within_window(first_timestamp, current_timestamp); | 216 | 0 | if (is_matched) { | 217 | | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::INCREASE) { | 218 | | is_matched = current_timestamp > prev_timestamp; | 219 | | } | 220 | 0 | } | 221 | 0 | if (!is_matched) { | 222 | 0 | break; | 223 | 0 | } | 224 | | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::INCREASE) { | 225 | | prev_timestamp = timestamp_data[match_row]; | 226 | | } | 227 | | if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::DEDUPLICATION) { | 228 | | bool is_dup = false; | 229 | | if (match_row != last_match_row + 1) { | 230 | | for (int tmp_column_idx = 0; tmp_column_idx < column_idx; | 231 | | tmp_column_idx++) { | 232 | | const auto& tmp_event_data = | 233 | | events_list.event_columns_data[tmp_column_idx].data(); | 234 | | auto dup_match_row = simd::find_one(tmp_event_data, | 235 | | last_match_row + 1, match_row); | 236 | | if (dup_match_row < match_row) { | 237 | | is_dup = true; | 238 | | break; | 239 | | } | 240 | | } | 241 | | } | 242 | | if (is_dup) { | 243 | | break; | 244 | | } | 245 | | last_match_row = match_row; | 246 | | } | 247 | 0 | matched_count++; | 248 | 4 | } else { | 249 | 4 | break; | 250 | 4 | } | 251 | 4 | } | 252 | 32 | } | 253 | 50 | return matched_count; | 254 | 46 | } |
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 |
255 | | |
256 | | template <WindowFunnelMode WINDOW_FUNNEL_MODE> |
257 | 224 | int _get_internal() const { |
258 | 224 | size_t start_row = 0; |
259 | 224 | int max_found_event_count = 0; |
260 | 224 | auto row_count = events_list.size(); |
261 | 472 | while (start_row < row_count) { |
262 | 258 | auto found_event_count = _match_event_list<WINDOW_FUNNEL_MODE>(start_row, row_count); |
263 | 258 | if (found_event_count == event_count) { |
264 | 10 | return found_event_count; |
265 | 10 | } |
266 | 248 | max_found_event_count = std::max(max_found_event_count, found_event_count); |
267 | 248 | } |
268 | 214 | return max_found_event_count; |
269 | 224 | } _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE13_get_internalILNS_16WindowFunnelModeE1EEEiv Line | Count | Source | 257 | 1 | int _get_internal() const { | 258 | 1 | size_t start_row = 0; | 259 | 1 | int max_found_event_count = 0; | 260 | 1 | auto row_count = events_list.size(); | 261 | 1 | while (start_row < row_count) { | 262 | 1 | auto found_event_count = _match_event_list<WINDOW_FUNNEL_MODE>(start_row, row_count); | 263 | 1 | if (found_event_count == event_count) { | 264 | 1 | return found_event_count; | 265 | 1 | } | 266 | 0 | max_found_event_count = std::max(max_found_event_count, found_event_count); | 267 | 0 | } | 268 | 0 | return max_found_event_count; | 269 | 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 | 257 | 181 | int _get_internal() const { | 258 | 181 | size_t start_row = 0; | 259 | 181 | int max_found_event_count = 0; | 260 | 181 | auto row_count = events_list.size(); | 261 | 383 | while (start_row < row_count) { | 262 | 211 | auto found_event_count = _match_event_list<WINDOW_FUNNEL_MODE>(start_row, row_count); | 263 | 211 | if (found_event_count == event_count) { | 264 | 9 | return found_event_count; | 265 | 9 | } | 266 | 202 | max_found_event_count = std::max(max_found_event_count, found_event_count); | 267 | 202 | } | 268 | 172 | return max_found_event_count; | 269 | 181 | } |
Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE13_get_internalILNS_16WindowFunnelModeE2EEEiv _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE13_get_internalILNS_16WindowFunnelModeE3EEEiv Line | Count | Source | 257 | 42 | int _get_internal() const { | 258 | 42 | size_t start_row = 0; | 259 | 42 | int max_found_event_count = 0; | 260 | 42 | auto row_count = events_list.size(); | 261 | 88 | while (start_row < row_count) { | 262 | 46 | auto found_event_count = _match_event_list<WINDOW_FUNNEL_MODE>(start_row, row_count); | 263 | 46 | if (found_event_count == event_count) { | 264 | 0 | return found_event_count; | 265 | 0 | } | 266 | 46 | max_found_event_count = std::max(max_found_event_count, found_event_count); | 267 | 46 | } | 268 | 42 | return max_found_event_count; | 269 | 42 | } |
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 |
270 | 230 | int get() const { |
271 | 230 | auto row_count = events_list.size(); |
272 | 230 | if (event_count == 0 || row_count == 0) { |
273 | 6 | return 0; |
274 | 6 | } |
275 | 224 | switch (window_funnel_mode) { |
276 | 182 | case WindowFunnelMode::DEFAULT: |
277 | 182 | return _get_internal<WindowFunnelMode::DEFAULT>(); |
278 | 0 | case WindowFunnelMode::DEDUPLICATION: |
279 | 0 | return _get_internal<WindowFunnelMode::DEDUPLICATION>(); |
280 | 42 | case WindowFunnelMode::FIXED: |
281 | 42 | return _get_internal<WindowFunnelMode::FIXED>(); |
282 | 0 | case WindowFunnelMode::INCREASE: |
283 | 0 | return _get_internal<WindowFunnelMode::INCREASE>(); |
284 | 0 | default: |
285 | 0 | throw doris::Exception(ErrorCode::INTERNAL_ERROR, "Invalid window_funnel mode"); |
286 | 0 | return 0; |
287 | 224 | } |
288 | 224 | } _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE3getEv Line | Count | Source | 270 | 1 | int get() const { | 271 | 1 | auto row_count = events_list.size(); | 272 | 1 | if (event_count == 0 || row_count == 0) { | 273 | 0 | return 0; | 274 | 0 | } | 275 | 1 | switch (window_funnel_mode) { | 276 | 1 | case WindowFunnelMode::DEFAULT: | 277 | 1 | return _get_internal<WindowFunnelMode::DEFAULT>(); | 278 | 0 | case WindowFunnelMode::DEDUPLICATION: | 279 | 0 | return _get_internal<WindowFunnelMode::DEDUPLICATION>(); | 280 | 0 | case WindowFunnelMode::FIXED: | 281 | 0 | return _get_internal<WindowFunnelMode::FIXED>(); | 282 | 0 | case WindowFunnelMode::INCREASE: | 283 | 0 | return _get_internal<WindowFunnelMode::INCREASE>(); | 284 | 0 | default: | 285 | 0 | throw doris::Exception(ErrorCode::INTERNAL_ERROR, "Invalid window_funnel mode"); | 286 | 0 | return 0; | 287 | 1 | } | 288 | 1 | } |
_ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE3getEv Line | Count | Source | 270 | 229 | int get() const { | 271 | 229 | auto row_count = events_list.size(); | 272 | 229 | if (event_count == 0 || row_count == 0) { | 273 | 6 | return 0; | 274 | 6 | } | 275 | 223 | switch (window_funnel_mode) { | 276 | 181 | case WindowFunnelMode::DEFAULT: | 277 | 181 | return _get_internal<WindowFunnelMode::DEFAULT>(); | 278 | 0 | case WindowFunnelMode::DEDUPLICATION: | 279 | 0 | return _get_internal<WindowFunnelMode::DEDUPLICATION>(); | 280 | 42 | case WindowFunnelMode::FIXED: | 281 | 42 | return _get_internal<WindowFunnelMode::FIXED>(); | 282 | 0 | case WindowFunnelMode::INCREASE: | 283 | 0 | return _get_internal<WindowFunnelMode::INCREASE>(); | 284 | 0 | default: | 285 | 0 | throw doris::Exception(ErrorCode::INTERNAL_ERROR, "Invalid window_funnel mode"); | 286 | 0 | return 0; | 287 | 223 | } | 288 | 223 | } |
Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EE3getEv |
289 | | |
290 | 209 | void merge(const WindowFunnelState<T>& other) { |
291 | 209 | if (other.events_list.empty()) { |
292 | 55 | return; |
293 | 55 | } |
294 | | |
295 | 154 | if (events_list.empty()) { |
296 | 86 | window = other.window; |
297 | 86 | window_funnel_mode = other.window_funnel_mode; |
298 | 86 | } else if (UNLIKELY(window != other.window || |
299 | 68 | window_funnel_mode != other.window_funnel_mode)) { |
300 | 48 | throw Exception(ErrorCode::INVALID_ARGUMENT, |
301 | 48 | "window_funnel aggregate states have incompatible window or mode"); |
302 | 48 | } |
303 | 106 | events_list.dt.insert(std::end(events_list.dt), std::begin(other.events_list.dt), |
304 | 106 | std::end(other.events_list.dt)); |
305 | 338 | for (size_t i = 0; i < event_count; i++) { |
306 | 232 | events_list.event_columns_data[i].insert( |
307 | 232 | std::end(events_list.event_columns_data[i]), |
308 | 232 | std::begin(other.events_list.event_columns_data[i]), |
309 | 232 | std::end(other.events_list.event_columns_data[i])); |
310 | 232 | } |
311 | 106 | event_count = event_count > 0 ? event_count : other.event_count; |
312 | 106 | window = window > 0 ? window : other.window; |
313 | 106 | if (enable_mode) { |
314 | 96 | window_funnel_mode = window_funnel_mode == WindowFunnelMode::INVALID |
315 | 96 | ? other.window_funnel_mode |
316 | 96 | : window_funnel_mode; |
317 | 96 | } else { |
318 | 10 | window_funnel_mode = WindowFunnelMode::DEFAULT; |
319 | 10 | } |
320 | 106 | } _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE5mergeERKS2_ Line | Count | Source | 290 | 209 | void merge(const WindowFunnelState<T>& other) { | 291 | 209 | if (other.events_list.empty()) { | 292 | 55 | return; | 293 | 55 | } | 294 | | | 295 | 154 | if (events_list.empty()) { | 296 | 86 | window = other.window; | 297 | 86 | window_funnel_mode = other.window_funnel_mode; | 298 | 86 | } else if (UNLIKELY(window != other.window || | 299 | 68 | window_funnel_mode != other.window_funnel_mode)) { | 300 | 48 | throw Exception(ErrorCode::INVALID_ARGUMENT, | 301 | 48 | "window_funnel aggregate states have incompatible window or mode"); | 302 | 48 | } | 303 | 106 | events_list.dt.insert(std::end(events_list.dt), std::begin(other.events_list.dt), | 304 | 106 | std::end(other.events_list.dt)); | 305 | 338 | for (size_t i = 0; i < event_count; i++) { | 306 | 232 | events_list.event_columns_data[i].insert( | 307 | 232 | std::end(events_list.event_columns_data[i]), | 308 | 232 | std::begin(other.events_list.event_columns_data[i]), | 309 | 232 | std::end(other.events_list.event_columns_data[i])); | 310 | 232 | } | 311 | 106 | event_count = event_count > 0 ? event_count : other.event_count; | 312 | 106 | window = window > 0 ? window : other.window; | 313 | 106 | if (enable_mode) { | 314 | 96 | window_funnel_mode = window_funnel_mode == WindowFunnelMode::INVALID | 315 | 96 | ? other.window_funnel_mode | 316 | 96 | : window_funnel_mode; | 317 | 96 | } else { | 318 | 10 | window_funnel_mode = WindowFunnelMode::DEFAULT; | 319 | 10 | } | 320 | 106 | } |
Unexecuted instantiation: _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE5mergeERKS2_ Unexecuted instantiation: _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EE5mergeERKS2_ |
321 | | |
322 | 96 | void write(BufferWritable& out) const { |
323 | 96 | write_var_int(event_count, out); |
324 | 96 | write_var_int(window, out); |
325 | 96 | if (enable_mode) { |
326 | 94 | write_var_int(static_cast<std::underlying_type_t<WindowFunnelMode>>(window_funnel_mode), |
327 | 94 | out); |
328 | 94 | } |
329 | 96 | auto size = events_list.size(); |
330 | 96 | write_var_int(size, out); |
331 | 96 | for (const auto& timestamp : events_list.dt) { |
332 | 71 | write_var_int(timestamp.to_date_int_val(), out); |
333 | 71 | } |
334 | 291 | for (int64_t i = 0; i < event_count; i++) { |
335 | 195 | const auto& event_columns_data = events_list.event_columns_data[i]; |
336 | 195 | for (auto event : event_columns_data) { |
337 | 149 | write_var_int(event, out); |
338 | 149 | } |
339 | 195 | } |
340 | 96 | } _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE5writeERNS_14BufferWritableE Line | Count | Source | 322 | 1 | void write(BufferWritable& out) const { | 323 | 1 | write_var_int(event_count, out); | 324 | 1 | write_var_int(window, out); | 325 | 1 | if (enable_mode) { | 326 | 1 | write_var_int(static_cast<std::underlying_type_t<WindowFunnelMode>>(window_funnel_mode), | 327 | 1 | out); | 328 | 1 | } | 329 | 1 | auto size = events_list.size(); | 330 | 1 | write_var_int(size, out); | 331 | 1 | for (const auto& timestamp : events_list.dt) { | 332 | 1 | write_var_int(timestamp.to_date_int_val(), out); | 333 | 1 | } | 334 | 2 | for (int64_t i = 0; i < event_count; i++) { | 335 | 1 | const auto& event_columns_data = events_list.event_columns_data[i]; | 336 | 1 | for (auto event : event_columns_data) { | 337 | 1 | write_var_int(event, out); | 338 | 1 | } | 339 | 1 | } | 340 | 1 | } |
_ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE5writeERNS_14BufferWritableE Line | Count | Source | 322 | 95 | void write(BufferWritable& out) const { | 323 | 95 | write_var_int(event_count, out); | 324 | 95 | write_var_int(window, out); | 325 | 95 | if (enable_mode) { | 326 | 93 | write_var_int(static_cast<std::underlying_type_t<WindowFunnelMode>>(window_funnel_mode), | 327 | 93 | out); | 328 | 93 | } | 329 | 95 | auto size = events_list.size(); | 330 | 95 | write_var_int(size, out); | 331 | 95 | for (const auto& timestamp : events_list.dt) { | 332 | 70 | write_var_int(timestamp.to_date_int_val(), out); | 333 | 70 | } | 334 | 289 | for (int64_t i = 0; i < event_count; i++) { | 335 | 194 | const auto& event_columns_data = events_list.event_columns_data[i]; | 336 | 194 | for (auto event : event_columns_data) { | 337 | 148 | write_var_int(event, out); | 338 | 148 | } | 339 | 194 | } | 340 | 95 | } |
Unexecuted instantiation: _ZNK5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EE5writeERNS_14BufferWritableE |
341 | | |
342 | 120 | void read(BufferReadable& in) { |
343 | 120 | int64_t event_level; |
344 | 120 | read_var_int(event_level, in); |
345 | 120 | event_count = (int)event_level; |
346 | 120 | read_var_int(window, in); |
347 | 120 | window_funnel_mode = WindowFunnelMode::DEFAULT; |
348 | 120 | if (enable_mode) { |
349 | 118 | int64_t mode; |
350 | 118 | read_var_int(mode, in); |
351 | 118 | window_funnel_mode = static_cast<WindowFunnelMode>(mode); |
352 | 118 | } |
353 | 120 | int64_t size = 0; |
354 | 120 | read_var_int(size, in); |
355 | 120 | events_list.clear(); |
356 | 120 | events_list.dt.resize(size); |
357 | 215 | for (auto i = 0; i < size; i++) { |
358 | 95 | Int64 timestamp = 0; |
359 | 95 | read_var_int(timestamp, in); |
360 | 95 | if constexpr (T == TYPE_TIMESTAMP_NS) { |
361 | 1 | events_list.dt[i] = DateValueType(timestamp); |
362 | 94 | } else { |
363 | 94 | events_list.dt[i] = DateValueType(static_cast<UInt64>(timestamp)); |
364 | 94 | } |
365 | 95 | } |
366 | 120 | events_list.event_columns_data.resize(event_count); |
367 | 363 | for (int64_t i = 0; i < event_count; i++) { |
368 | 243 | auto& event_columns_data = events_list.event_columns_data[i]; |
369 | 243 | event_columns_data.resize(size); |
370 | 440 | for (auto j = 0; j < size; j++) { |
371 | 197 | Int64 temp_value; |
372 | 197 | read_var_int(temp_value, in); |
373 | 197 | event_columns_data[j] = static_cast<UInt8>(temp_value); |
374 | 197 | } |
375 | 243 | } |
376 | 120 | } _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE43EE4readERNS_14BufferReadableE Line | Count | Source | 342 | 1 | void read(BufferReadable& in) { | 343 | 1 | int64_t event_level; | 344 | 1 | read_var_int(event_level, in); | 345 | 1 | event_count = (int)event_level; | 346 | 1 | read_var_int(window, in); | 347 | 1 | window_funnel_mode = WindowFunnelMode::DEFAULT; | 348 | 1 | if (enable_mode) { | 349 | 1 | int64_t mode; | 350 | 1 | read_var_int(mode, in); | 351 | 1 | window_funnel_mode = static_cast<WindowFunnelMode>(mode); | 352 | 1 | } | 353 | 1 | int64_t size = 0; | 354 | 1 | read_var_int(size, in); | 355 | 1 | events_list.clear(); | 356 | 1 | events_list.dt.resize(size); | 357 | 2 | for (auto i = 0; i < size; i++) { | 358 | 1 | Int64 timestamp = 0; | 359 | 1 | read_var_int(timestamp, in); | 360 | 1 | if constexpr (T == TYPE_TIMESTAMP_NS) { | 361 | 1 | events_list.dt[i] = DateValueType(timestamp); | 362 | | } else { | 363 | | events_list.dt[i] = DateValueType(static_cast<UInt64>(timestamp)); | 364 | | } | 365 | 1 | } | 366 | 1 | events_list.event_columns_data.resize(event_count); | 367 | 2 | for (int64_t i = 0; i < event_count; i++) { | 368 | 1 | auto& event_columns_data = events_list.event_columns_data[i]; | 369 | 1 | event_columns_data.resize(size); | 370 | 2 | for (auto j = 0; j < size; j++) { | 371 | 1 | Int64 temp_value; | 372 | 1 | read_var_int(temp_value, in); | 373 | 1 | event_columns_data[j] = static_cast<UInt8>(temp_value); | 374 | 1 | } | 375 | 1 | } | 376 | 1 | } |
_ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE26EE4readERNS_14BufferReadableE Line | Count | Source | 342 | 119 | void read(BufferReadable& in) { | 343 | 119 | int64_t event_level; | 344 | 119 | read_var_int(event_level, in); | 345 | 119 | event_count = (int)event_level; | 346 | 119 | read_var_int(window, in); | 347 | 119 | window_funnel_mode = WindowFunnelMode::DEFAULT; | 348 | 119 | if (enable_mode) { | 349 | 117 | int64_t mode; | 350 | 117 | read_var_int(mode, in); | 351 | 117 | window_funnel_mode = static_cast<WindowFunnelMode>(mode); | 352 | 117 | } | 353 | 119 | int64_t size = 0; | 354 | 119 | read_var_int(size, in); | 355 | 119 | events_list.clear(); | 356 | 119 | events_list.dt.resize(size); | 357 | 213 | for (auto i = 0; i < size; i++) { | 358 | 94 | Int64 timestamp = 0; | 359 | 94 | read_var_int(timestamp, in); | 360 | | if constexpr (T == TYPE_TIMESTAMP_NS) { | 361 | | events_list.dt[i] = DateValueType(timestamp); | 362 | 94 | } else { | 363 | 94 | events_list.dt[i] = DateValueType(static_cast<UInt64>(timestamp)); | 364 | 94 | } | 365 | 94 | } | 366 | 119 | events_list.event_columns_data.resize(event_count); | 367 | 361 | for (int64_t i = 0; i < event_count; i++) { | 368 | 242 | auto& event_columns_data = events_list.event_columns_data[i]; | 369 | 242 | event_columns_data.resize(size); | 370 | 438 | for (auto j = 0; j < size; j++) { | 371 | 196 | Int64 temp_value; | 372 | 196 | read_var_int(temp_value, in); | 373 | 196 | event_columns_data[j] = static_cast<UInt8>(temp_value); | 374 | 196 | } | 375 | 242 | } | 376 | 119 | } |
Unexecuted instantiation: _ZN5doris17WindowFunnelStateILNS_13PrimitiveTypeE42EE4readERNS_14BufferReadableE |
377 | | }; |
378 | | |
379 | | template <PrimitiveType T> |
380 | | class AggregateFunctionWindowFunnel final |
381 | | : public IAggregateFunctionDataHelper<WindowFunnelState<T>, |
382 | | AggregateFunctionWindowFunnel<T>>, |
383 | | MultiExpression, |
384 | | NullableAggregateFunction { |
385 | | public: |
386 | | AggregateFunctionWindowFunnel(const DataTypes& argument_types_) |
387 | 16 | : IAggregateFunctionDataHelper<WindowFunnelState<T>, AggregateFunctionWindowFunnel<T>>( |
388 | 16 | argument_types_) {}_ZN5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE26EEC2ERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 387 | 15 | : IAggregateFunctionDataHelper<WindowFunnelState<T>, AggregateFunctionWindowFunnel<T>>( | 388 | 15 | argument_types_) {} |
_ZN5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE43EEC2ERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 387 | 1 | : IAggregateFunctionDataHelper<WindowFunnelState<T>, AggregateFunctionWindowFunnel<T>>( | 388 | 1 | argument_types_) {} |
Unexecuted instantiation: _ZN5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE42EEC2ERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE |
389 | | |
390 | 530 | void create(AggregateDataPtr __restrict place) const override { |
391 | 530 | auto data = new (place) WindowFunnelState<T>( |
392 | 530 | cast_set<int>(IAggregateFunction::get_argument_types().size() - 3)); |
393 | | /// support window funnel mode from 2.0. See `BeExecVersionManager::max_be_exec_version` |
394 | 530 | data->enable_mode = IAggregateFunction::version >= 3; |
395 | 530 | } _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE26EE6createEPc Line | Count | Source | 390 | 530 | void create(AggregateDataPtr __restrict place) const override { | 391 | 530 | auto data = new (place) WindowFunnelState<T>( | 392 | 530 | cast_set<int>(IAggregateFunction::get_argument_types().size() - 3)); | 393 | | /// support window funnel mode from 2.0. See `BeExecVersionManager::max_be_exec_version` | 394 | 530 | data->enable_mode = IAggregateFunction::version >= 3; | 395 | 530 | } |
Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE43EE6createEPc Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE42EE6createEPc |
396 | | |
397 | 0 | String get_name() const override { return "window_funnel"; }Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE26EE8get_nameB5cxx11Ev Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE43EE8get_nameB5cxx11Ev Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE42EE8get_nameB5cxx11Ev |
398 | | |
399 | 204 | DataTypePtr get_return_type() const override { return std::make_shared<DataTypeInt32>(); }_ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE26EE15get_return_typeEv Line | Count | Source | 399 | 204 | DataTypePtr get_return_type() const override { return std::make_shared<DataTypeInt32>(); } |
Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE43EE15get_return_typeEv Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE42EE15get_return_typeEv |
400 | | |
401 | 12 | void reset(AggregateDataPtr __restrict place) const override { this->data(place).reset(); }_ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE26EE5resetEPc Line | Count | Source | 401 | 12 | void reset(AggregateDataPtr __restrict place) const override { this->data(place).reset(); } |
Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE43EE5resetEPc Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE42EE5resetEPc |
402 | | |
403 | | void add(AggregateDataPtr __restrict place, const IColumn** columns, ssize_t row_num, |
404 | 374 | Arena&) const override { |
405 | 374 | const auto& window = |
406 | 374 | assert_cast<const ColumnInt64&, TypeCheckOnRelease::DISABLE>(*columns[0]) |
407 | 374 | .get_data()[row_num]; |
408 | 374 | StringRef mode = columns[1]->get_data_at(row_num); |
409 | 374 | this->data(place).add(columns, row_num, window, |
410 | 374 | string_to_window_funnel_mode(mode.to_string())); |
411 | 374 | } _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE26EE3addEPcPPKNS_7IColumnElRNS_5ArenaE Line | Count | Source | 404 | 374 | Arena&) const override { | 405 | 374 | const auto& window = | 406 | 374 | assert_cast<const ColumnInt64&, TypeCheckOnRelease::DISABLE>(*columns[0]) | 407 | 374 | .get_data()[row_num]; | 408 | 374 | StringRef mode = columns[1]->get_data_at(row_num); | 409 | 374 | this->data(place).add(columns, row_num, window, | 410 | 374 | string_to_window_funnel_mode(mode.to_string())); | 411 | 374 | } |
Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE43EE3addEPcPPKNS_7IColumnElRNS_5ArenaE Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE42EE3addEPcPPKNS_7IColumnElRNS_5ArenaE |
412 | | |
413 | 0 | void check_input_columns_type(const IColumn** columns) const override { |
414 | 0 | this->template check_argument_column_type<ColumnInt64>(columns[0]); |
415 | 0 | this->template check_argument_column_type<ColumnString>(columns[1]); |
416 | 0 | this->template check_argument_column_type<typename PrimitiveTypeTraits<T>::ColumnType>( |
417 | 0 | columns[2]); |
418 | 0 | for (size_t i = 3; i < this->argument_types.size(); ++i) { |
419 | 0 | this->template check_argument_column_type<ColumnUInt8>(columns[i]); |
420 | 0 | } |
421 | 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 |
422 | | |
423 | | void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, |
424 | 209 | Arena&) const override { |
425 | 209 | this->data(place).merge(this->data(rhs)); |
426 | 209 | } _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE26EE5mergeEPcPKcRNS_5ArenaE Line | Count | Source | 424 | 209 | Arena&) const override { | 425 | 209 | this->data(place).merge(this->data(rhs)); | 426 | 209 | } |
Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE43EE5mergeEPcPKcRNS_5ArenaE Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE42EE5mergeEPcPKcRNS_5ArenaE |
427 | | |
428 | 95 | void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const override { |
429 | 95 | this->data(place).write(buf); |
430 | 95 | } _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE26EE9serializeEPKcRNS_14BufferWritableE Line | Count | Source | 428 | 95 | void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const override { | 429 | 95 | this->data(place).write(buf); | 430 | 95 | } |
Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE43EE9serializeEPKcRNS_14BufferWritableE Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE42EE9serializeEPKcRNS_14BufferWritableE |
431 | | |
432 | | void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, |
433 | 119 | Arena&) const override { |
434 | 119 | this->data(place).read(buf); |
435 | 119 | } _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE26EE11deserializeEPcRNS_14BufferReadableERNS_5ArenaE Line | Count | Source | 433 | 119 | Arena&) const override { | 434 | 119 | this->data(place).read(buf); | 435 | 119 | } |
Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE43EE11deserializeEPcRNS_14BufferReadableERNS_5ArenaE Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE42EE11deserializeEPcRNS_14BufferReadableERNS_5ArenaE |
436 | | |
437 | 229 | void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override { |
438 | | // place is essentially an AggregateDataPtr, passed as a ConstAggregateDataPtr. |
439 | 229 | this->data(const_cast<AggregateDataPtr>(place)).sort(); |
440 | 229 | assert_cast<ColumnInt32&, TypeCheckOnRelease::DISABLE>(to).get_data().push_back( |
441 | 229 | IAggregateFunctionDataHelper<WindowFunnelState<T>, |
442 | 229 | AggregateFunctionWindowFunnel<T>>::data(place) |
443 | 229 | .get()); |
444 | 229 | } _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE26EE18insert_result_intoEPKcRNS_7IColumnE Line | Count | Source | 437 | 229 | void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override { | 438 | | // place is essentially an AggregateDataPtr, passed as a ConstAggregateDataPtr. | 439 | 229 | this->data(const_cast<AggregateDataPtr>(place)).sort(); | 440 | 229 | assert_cast<ColumnInt32&, TypeCheckOnRelease::DISABLE>(to).get_data().push_back( | 441 | 229 | IAggregateFunctionDataHelper<WindowFunnelState<T>, | 442 | 229 | AggregateFunctionWindowFunnel<T>>::data(place) | 443 | 229 | .get()); | 444 | 229 | } |
Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE43EE18insert_result_intoEPKcRNS_7IColumnE Unexecuted instantiation: _ZNK5doris29AggregateFunctionWindowFunnelILNS_13PrimitiveTypeE42EE18insert_result_intoEPKcRNS_7IColumnE |
445 | | |
446 | | protected: |
447 | | using IAggregateFunction::version; |
448 | | }; |
449 | | } // namespace doris |