be/src/exprs/function/function_string_concat.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 | | #pragma once |
19 | | |
20 | | #include <fmt/format.h> |
21 | | |
22 | | #include <cstddef> |
23 | | #include <cstring> |
24 | | #include <string> |
25 | | #include <string_view> |
26 | | #include <vector> |
27 | | |
28 | | #include "common/status.h" |
29 | | #include "core/assert_cast.h" |
30 | | #include "core/block/block.h" |
31 | | #include "core/block/column_numbers.h" |
32 | | #include "core/column/column.h" |
33 | | #include "core/column/column_array.h" |
34 | | #include "core/column/column_const.h" |
35 | | #include "core/column/column_nullable.h" |
36 | | #include "core/column/column_string.h" |
37 | | #include "core/column/column_vector.h" |
38 | | #include "core/data_type/data_type_array.h" |
39 | | #include "core/data_type/data_type_nullable.h" |
40 | | #include "core/data_type/data_type_number.h" |
41 | | #include "core/data_type/data_type_string.h" |
42 | | #include "core/memcpy_small.h" |
43 | | #include "core/string_ref.h" |
44 | | #include "exec/common/stringop_substring.h" |
45 | | #include "exec/common/template_helpers.hpp" |
46 | | #include "exec/common/util.hpp" |
47 | | #include "exprs/function/function.h" |
48 | | #include "exprs/function/function_helpers.h" |
49 | | #include "exprs/function_context.h" |
50 | | #include "util/simd/vstring_function.h" |
51 | | |
52 | | namespace doris { |
53 | | #include "common/compile_check_avoid_begin.h" |
54 | | |
55 | | class FunctionStringConcat : public IFunction { |
56 | | public: |
57 | | struct ConcatState { |
58 | | bool use_state = false; |
59 | | std::string tail; |
60 | | }; |
61 | | |
62 | | static constexpr auto name = "concat"; |
63 | 2.50k | static FunctionPtr create() { return std::make_shared<FunctionStringConcat>(); } |
64 | 0 | String get_name() const override { return name; } |
65 | 0 | size_t get_number_of_arguments() const override { return 0; } |
66 | 2.49k | bool is_variadic() const override { return true; } |
67 | | |
68 | 2.49k | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
69 | 2.49k | return std::make_shared<DataTypeString>(); |
70 | 2.49k | } |
71 | | |
72 | 9.36k | Status open(FunctionContext* context, FunctionContext::FunctionStateScope scope) override { |
73 | 9.36k | if (scope == FunctionContext::THREAD_LOCAL) { |
74 | 6.88k | return Status::OK(); |
75 | 6.88k | } |
76 | 2.48k | std::shared_ptr<ConcatState> state = std::make_shared<ConcatState>(); |
77 | | |
78 | 2.48k | context->set_function_state(scope, state); |
79 | | |
80 | 2.48k | state->use_state = true; |
81 | | |
82 | | // Optimize function calls like this: |
83 | | // concat(col, "123", "abc", "456") -> tail = "123abc456" |
84 | 4.59k | for (size_t i = 1; i < context->get_num_args(); i++) { |
85 | 4.29k | const auto* column_string = context->get_constant_col(i); |
86 | 4.29k | if (column_string == nullptr) { |
87 | 2.15k | state->use_state = false; |
88 | 2.15k | return IFunction::open(context, scope); |
89 | 2.15k | } |
90 | 2.13k | auto string_vale = column_string->column_ptr->get_data_at(0); |
91 | 2.13k | if (string_vale.data == nullptr) { |
92 | | // For concat(col, null), it is handled by default_implementation_for_nulls |
93 | 33 | state->use_state = false; |
94 | 33 | return IFunction::open(context, scope); |
95 | 33 | } |
96 | | |
97 | 2.10k | state->tail.append(string_vale.begin(), string_vale.size); |
98 | 2.10k | } |
99 | | |
100 | | // The reserve is used here to allow the usage of memcpy_small_allow_read_write_overflow15 below. |
101 | 299 | state->tail.reserve(state->tail.size() + 16); |
102 | | |
103 | 299 | return IFunction::open(context, scope); |
104 | 2.48k | } |
105 | | |
106 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
107 | 2.55k | uint32_t result, size_t input_rows_count) const override { |
108 | 2.55k | DCHECK_GE(arguments.size(), 1); |
109 | | |
110 | 2.55k | if (arguments.size() == 1) { |
111 | 29 | block.get_by_position(result).column = block.get_by_position(arguments[0]).column; |
112 | 29 | return Status::OK(); |
113 | 29 | } |
114 | 2.52k | auto* concat_state = reinterpret_cast<ConcatState*>( |
115 | 2.52k | context->get_function_state(FunctionContext::FRAGMENT_LOCAL)); |
116 | 2.52k | if (!concat_state) { |
117 | 0 | return Status::RuntimeError("funciton context for function '{}' must have ConcatState;", |
118 | 0 | get_name()); |
119 | 0 | } |
120 | 2.52k | if (concat_state->use_state) { |
121 | 287 | const auto& [col, is_const] = |
122 | 287 | unpack_if_const(block.get_by_position(arguments[0]).column); |
123 | 287 | const auto* col_str = assert_cast<const ColumnString*>(col.get()); |
124 | 287 | if (is_const) { |
125 | 0 | return execute_const<true>(concat_state, block, col_str, result, input_rows_count); |
126 | 287 | } else { |
127 | 287 | return execute_const<false>(concat_state, block, col_str, result, input_rows_count); |
128 | 287 | } |
129 | | |
130 | 2.23k | } else { |
131 | 2.23k | return execute_vecotr(block, arguments, result, input_rows_count); |
132 | 2.23k | } |
133 | 2.52k | } |
134 | | |
135 | | Status execute_vecotr(Block& block, const ColumnNumbers& arguments, uint32_t result, |
136 | 2.23k | size_t input_rows_count) const { |
137 | 2.23k | int argument_size = arguments.size(); |
138 | 2.23k | std::vector<ColumnPtr> argument_columns(argument_size); |
139 | | |
140 | 2.23k | std::vector<const ColumnString::Offsets*> offsets_list(argument_size); |
141 | 2.23k | std::vector<const ColumnString::Chars*> chars_list(argument_size); |
142 | 2.23k | std::vector<bool> is_const_args(argument_size); |
143 | | |
144 | 8.72k | for (int i = 0; i < argument_size; ++i) { |
145 | 6.48k | const auto& [col, is_const] = |
146 | 6.48k | unpack_if_const(block.get_by_position(arguments[i]).column); |
147 | | |
148 | 6.48k | const auto* col_str = assert_cast<const ColumnString*>(col.get()); |
149 | 6.48k | offsets_list[i] = &col_str->get_offsets(); |
150 | 6.48k | chars_list[i] = &col_str->get_chars(); |
151 | 6.48k | is_const_args[i] = is_const; |
152 | 6.48k | } |
153 | | |
154 | 2.23k | auto res = ColumnString::create(); |
155 | 2.23k | auto& res_data = res->get_chars(); |
156 | 2.23k | auto& res_offset = res->get_offsets(); |
157 | | |
158 | 2.23k | res_offset.resize(input_rows_count); |
159 | 2.23k | size_t res_reserve_size = 0; |
160 | 8.72k | for (size_t i = 0; i < argument_size; ++i) { |
161 | 6.48k | if (is_const_args[i]) { |
162 | 2.16k | res_reserve_size += (*offsets_list[i])[0] * input_rows_count; |
163 | 4.32k | } else { |
164 | 4.32k | res_reserve_size += (*offsets_list[i])[input_rows_count - 1]; |
165 | 4.32k | } |
166 | 6.48k | } |
167 | | |
168 | 2.23k | ColumnString::check_chars_length(res_reserve_size, 0); |
169 | | |
170 | 2.23k | res_data.resize(res_reserve_size); |
171 | | |
172 | 2.23k | auto* data = res_data.data(); |
173 | 2.23k | size_t dst_offset = 0; |
174 | | |
175 | 71.9k | for (size_t i = 0; i < input_rows_count; ++i) { |
176 | 214k | for (size_t j = 0; j < argument_size; ++j) { |
177 | 144k | const auto& current_offsets = *offsets_list[j]; |
178 | 144k | const auto& current_chars = *chars_list[j]; |
179 | 144k | auto idx = index_check_const(i, is_const_args[j]); |
180 | 144k | const auto size = current_offsets[idx] - current_offsets[idx - 1]; |
181 | 144k | if (size > 0) { |
182 | 144k | memcpy_small_allow_read_write_overflow15( |
183 | 144k | data + dst_offset, current_chars.data() + current_offsets[idx - 1], |
184 | 144k | size); |
185 | 144k | dst_offset += size; |
186 | 144k | } |
187 | 144k | } |
188 | 69.6k | res_offset[i] = dst_offset; |
189 | 69.6k | } |
190 | | |
191 | 2.23k | block.get_by_position(result).column = std::move(res); |
192 | 2.23k | return Status::OK(); |
193 | 2.23k | } |
194 | | |
195 | | template <bool is_const> |
196 | | Status execute_const(ConcatState* concat_state, Block& block, const ColumnString* col_str, |
197 | 287 | uint32_t result, size_t input_rows_count) const { |
198 | | // using tail optimize |
199 | | |
200 | 287 | auto res = ColumnString::create(); |
201 | 287 | auto& res_data = res->get_chars(); |
202 | 287 | auto& res_offset = res->get_offsets(); |
203 | 287 | res_offset.resize(input_rows_count); |
204 | | |
205 | 287 | size_t res_reserve_size = 0; |
206 | 287 | if constexpr (is_const) { |
207 | 0 | res_reserve_size = col_str->get_offsets()[0] * input_rows_count; |
208 | 287 | } else { |
209 | 287 | res_reserve_size = col_str->get_offsets()[input_rows_count - 1]; |
210 | 287 | } |
211 | 287 | res_reserve_size += concat_state->tail.size() * input_rows_count; |
212 | | |
213 | 287 | ColumnString::check_chars_length(res_reserve_size, 0); |
214 | 287 | res_data.resize(res_reserve_size); |
215 | | |
216 | 287 | const auto& tail = concat_state->tail; |
217 | 287 | auto* data = res_data.data(); |
218 | 287 | size_t dst_offset = 0; |
219 | | |
220 | 926 | for (size_t i = 0; i < input_rows_count; ++i) { |
221 | 639 | const auto idx = index_check_const<is_const>(i); |
222 | 639 | StringRef str_val = col_str->get_data_at(idx); |
223 | | // copy column |
224 | 639 | memcpy_small_allow_read_write_overflow15(data + dst_offset, str_val.data, str_val.size); |
225 | 639 | dst_offset += str_val.size; |
226 | | // copy tail |
227 | 639 | memcpy_small_allow_read_write_overflow15(data + dst_offset, tail.data(), tail.size()); |
228 | 639 | dst_offset += tail.size(); |
229 | 639 | res_offset[i] = dst_offset; |
230 | 639 | } |
231 | 287 | block.get_by_position(result).column = std::move(res); |
232 | 287 | return Status::OK(); |
233 | 287 | } Unexecuted instantiation: _ZNK5doris20FunctionStringConcat13execute_constILb1EEENS_6StatusEPNS0_11ConcatStateERNS_5BlockEPKNS_9ColumnStrIjEEjm _ZNK5doris20FunctionStringConcat13execute_constILb0EEENS_6StatusEPNS0_11ConcatStateERNS_5BlockEPKNS_9ColumnStrIjEEjm Line | Count | Source | 197 | 287 | uint32_t result, size_t input_rows_count) const { | 198 | | // using tail optimize | 199 | | | 200 | 287 | auto res = ColumnString::create(); | 201 | 287 | auto& res_data = res->get_chars(); | 202 | 287 | auto& res_offset = res->get_offsets(); | 203 | 287 | res_offset.resize(input_rows_count); | 204 | | | 205 | 287 | size_t res_reserve_size = 0; | 206 | | if constexpr (is_const) { | 207 | | res_reserve_size = col_str->get_offsets()[0] * input_rows_count; | 208 | 287 | } else { | 209 | 287 | res_reserve_size = col_str->get_offsets()[input_rows_count - 1]; | 210 | 287 | } | 211 | 287 | res_reserve_size += concat_state->tail.size() * input_rows_count; | 212 | | | 213 | 287 | ColumnString::check_chars_length(res_reserve_size, 0); | 214 | 287 | res_data.resize(res_reserve_size); | 215 | | | 216 | 287 | const auto& tail = concat_state->tail; | 217 | 287 | auto* data = res_data.data(); | 218 | 287 | size_t dst_offset = 0; | 219 | | | 220 | 926 | for (size_t i = 0; i < input_rows_count; ++i) { | 221 | 639 | const auto idx = index_check_const<is_const>(i); | 222 | 639 | StringRef str_val = col_str->get_data_at(idx); | 223 | | // copy column | 224 | 639 | memcpy_small_allow_read_write_overflow15(data + dst_offset, str_val.data, str_val.size); | 225 | 639 | dst_offset += str_val.size; | 226 | | // copy tail | 227 | 639 | memcpy_small_allow_read_write_overflow15(data + dst_offset, tail.data(), tail.size()); | 228 | 639 | dst_offset += tail.size(); | 229 | 639 | res_offset[i] = dst_offset; | 230 | 639 | } | 231 | 287 | block.get_by_position(result).column = std::move(res); | 232 | 287 | return Status::OK(); | 233 | 287 | } |
|
234 | | }; |
235 | | |
236 | | class FunctionStringElt : public IFunction { |
237 | | public: |
238 | | static constexpr auto name = "elt"; |
239 | 423 | static FunctionPtr create() { return std::make_shared<FunctionStringElt>(); } |
240 | 0 | String get_name() const override { return name; } |
241 | 0 | size_t get_number_of_arguments() const override { return 0; } |
242 | 415 | bool is_variadic() const override { return true; } |
243 | | |
244 | 414 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
245 | 414 | return make_nullable(std::make_shared<DataTypeString>()); |
246 | 414 | } |
247 | 840 | bool use_default_implementation_for_nulls() const override { return false; } |
248 | | |
249 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
250 | 426 | uint32_t result, size_t input_rows_count) const override { |
251 | 426 | int arguent_size = arguments.size(); |
252 | 426 | int num_children = arguent_size - 1; |
253 | 426 | auto res = ColumnString::create(); |
254 | | |
255 | 426 | if (auto const_column = check_and_get_column<ColumnConst>( |
256 | 426 | *block.get_by_position(arguments[0]).column)) { |
257 | 154 | auto data = const_column->get_data_at(0); |
258 | | // return NULL, pos is null or pos < 0 or pos > num_children |
259 | 154 | auto is_null = data.data == nullptr; |
260 | 154 | auto pos = is_null ? 0 : *(Int32*)data.data; |
261 | 154 | is_null = pos <= 0 || pos > num_children; |
262 | | |
263 | 154 | auto null_map = ColumnUInt8::create(input_rows_count, is_null); |
264 | 154 | if (is_null) { |
265 | 135 | res->insert_many_defaults(input_rows_count); |
266 | 135 | } else { |
267 | 19 | auto& target_column = block.get_by_position(arguments[pos]).column; |
268 | 19 | if (auto target_const_column = check_and_get_column<ColumnConst>(*target_column)) { |
269 | 7 | auto target_data = target_const_column->get_data_at(0); |
270 | | // return NULL, no target data |
271 | 7 | if (target_data.data == nullptr) { |
272 | 1 | null_map = ColumnUInt8::create(input_rows_count, true); |
273 | 1 | res->insert_many_defaults(input_rows_count); |
274 | 6 | } else { |
275 | 6 | res->insert_data_repeatedly(target_data.data, target_data.size, |
276 | 6 | input_rows_count); |
277 | 6 | } |
278 | 12 | } else if (auto target_nullable_column = |
279 | 12 | check_and_get_column<ColumnNullable>(*target_column)) { |
280 | 12 | auto& target_null_map = target_nullable_column->get_null_map_data(); |
281 | 12 | VectorizedUtils::update_null_map( |
282 | 12 | assert_cast<ColumnUInt8&>(*null_map).get_data(), target_null_map); |
283 | | |
284 | 12 | auto& target_str_column = assert_cast<const ColumnString&>( |
285 | 12 | target_nullable_column->get_nested_column()); |
286 | 12 | res->get_chars().assign(target_str_column.get_chars().begin(), |
287 | 12 | target_str_column.get_chars().end()); |
288 | 12 | res->get_offsets().assign(target_str_column.get_offsets().begin(), |
289 | 12 | target_str_column.get_offsets().end()); |
290 | 12 | } else { |
291 | 0 | auto& target_str_column = assert_cast<const ColumnString&>(*target_column); |
292 | 0 | res->get_chars().assign(target_str_column.get_chars().begin(), |
293 | 0 | target_str_column.get_chars().end()); |
294 | 0 | res->get_offsets().assign(target_str_column.get_offsets().begin(), |
295 | 0 | target_str_column.get_offsets().end()); |
296 | 0 | } |
297 | 19 | } |
298 | 154 | block.get_by_position(result).column = |
299 | 154 | ColumnNullable::create(std::move(res), std::move(null_map)); |
300 | 272 | } else if (auto pos_null_column = check_and_get_column<ColumnNullable>( |
301 | 272 | *block.get_by_position(arguments[0]).column)) { |
302 | 219 | auto& pos_column = |
303 | 219 | assert_cast<const ColumnInt32&>(pos_null_column->get_nested_column()); |
304 | 219 | auto& pos_null_map = pos_null_column->get_null_map_data(); |
305 | 219 | auto null_map = ColumnUInt8::create(input_rows_count, false); |
306 | 219 | auto& res_null_map = assert_cast<ColumnUInt8&>(*null_map).get_data(); |
307 | | |
308 | 515 | for (size_t i = 0; i < input_rows_count; ++i) { |
309 | 296 | auto pos = pos_column.get_element(i); |
310 | 296 | res_null_map[i] = |
311 | 296 | pos_null_map[i] || pos <= 0 || pos > num_children || |
312 | 296 | block.get_by_position(arguments[pos]).column->get_data_at(i).data == |
313 | 35 | nullptr; |
314 | 296 | if (res_null_map[i]) { |
315 | 261 | res->insert_default(); |
316 | 261 | } else { |
317 | 35 | auto insert_data = block.get_by_position(arguments[pos]).column->get_data_at(i); |
318 | 35 | res->insert_data(insert_data.data, insert_data.size); |
319 | 35 | } |
320 | 296 | } |
321 | 219 | block.get_by_position(result).column = |
322 | 219 | ColumnNullable::create(std::move(res), std::move(null_map)); |
323 | 219 | } else { |
324 | 53 | auto& pos_column = |
325 | 53 | assert_cast<const ColumnInt32&>(*block.get_by_position(arguments[0]).column); |
326 | 53 | auto null_map = ColumnUInt8::create(input_rows_count, false); |
327 | 53 | auto& res_null_map = assert_cast<ColumnUInt8&>(*null_map).get_data(); |
328 | | |
329 | 122 | for (size_t i = 0; i < input_rows_count; ++i) { |
330 | 69 | auto pos = pos_column.get_element(i); |
331 | 69 | res_null_map[i] = |
332 | 69 | pos <= 0 || pos > num_children || |
333 | 69 | block.get_by_position(arguments[pos]).column->get_data_at(i).data == |
334 | 23 | nullptr; |
335 | 69 | if (res_null_map[i]) { |
336 | 46 | res->insert_default(); |
337 | 46 | } else { |
338 | 23 | auto insert_data = block.get_by_position(arguments[pos]).column->get_data_at(i); |
339 | 23 | res->insert_data(insert_data.data, insert_data.size); |
340 | 23 | } |
341 | 69 | } |
342 | 53 | block.get_by_position(result).column = |
343 | 53 | ColumnNullable::create(std::move(res), std::move(null_map)); |
344 | 53 | } |
345 | 426 | return Status::OK(); |
346 | 426 | } |
347 | | }; |
348 | | |
349 | | // concat_ws (string,string....) or (string, Array) |
350 | | // TODO: avoid use fmtlib |
351 | | class FunctionStringConcatWs : public IFunction { |
352 | | public: |
353 | | using Chars = ColumnString::Chars; |
354 | | using Offsets = ColumnString::Offsets; |
355 | | |
356 | | static constexpr auto name = "concat_ws"; |
357 | 553 | static FunctionPtr create() { return std::make_shared<FunctionStringConcatWs>(); } |
358 | 0 | String get_name() const override { return name; } |
359 | 0 | size_t get_number_of_arguments() const override { return 0; } |
360 | 545 | bool is_variadic() const override { return true; } |
361 | | |
362 | 544 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
363 | 544 | const IDataType* first_type = arguments[0].get(); |
364 | 544 | if (first_type->is_nullable()) { |
365 | 458 | return make_nullable(std::make_shared<DataTypeString>()); |
366 | 458 | } else { |
367 | 86 | return std::make_shared<DataTypeString>(); |
368 | 86 | } |
369 | 544 | } |
370 | 1.11k | bool use_default_implementation_for_nulls() const override { return false; } |
371 | | |
372 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
373 | 570 | uint32_t result, size_t input_rows_count) const override { |
374 | 570 | DCHECK_GE(arguments.size(), 2); |
375 | 570 | auto null_map = ColumnUInt8::create(input_rows_count, 0); |
376 | | // we create a zero column to simply implement |
377 | 570 | auto const_null_map = ColumnUInt8::create(input_rows_count, 0); |
378 | 570 | auto res = ColumnString::create(); |
379 | 570 | bool is_null_type = block.get_by_position(arguments[0]).type.get()->is_nullable(); |
380 | 570 | size_t argument_size = arguments.size(); |
381 | 570 | std::vector<const Offsets*> offsets_list(argument_size); |
382 | 570 | std::vector<const Chars*> chars_list(argument_size); |
383 | 570 | std::vector<const ColumnUInt8::Container*> null_list(argument_size); |
384 | | |
385 | 570 | std::vector<ColumnPtr> argument_columns(argument_size); |
386 | 570 | std::vector<ColumnPtr> argument_null_columns(argument_size); |
387 | | |
388 | 1.96k | for (size_t i = 0; i < argument_size; ++i) { |
389 | 1.39k | argument_columns[i] = |
390 | 1.39k | block.get_by_position(arguments[i]).column->convert_to_full_column_if_const(); |
391 | 1.39k | if (const auto* nullable = |
392 | 1.39k | check_and_get_column<const ColumnNullable>(*argument_columns[i])) { |
393 | | // Danger: Here must dispose the null map data first! Because |
394 | | // argument_columns[i]=nullable->get_nested_column_ptr(); will release the mem |
395 | | // of column nullable mem of null map |
396 | 1.13k | null_list[i] = &nullable->get_null_map_data(); |
397 | 1.13k | argument_null_columns[i] = nullable->get_null_map_column_ptr(); |
398 | 1.13k | argument_columns[i] = nullable->get_nested_column_ptr(); |
399 | 1.13k | } else { |
400 | 252 | null_list[i] = &const_null_map->get_data(); |
401 | 252 | } |
402 | | |
403 | 1.39k | if (is_column<ColumnArray>(argument_columns[i].get())) { |
404 | 105 | continue; |
405 | 105 | } |
406 | | |
407 | 1.28k | const auto* col_str = assert_cast<const ColumnString*>(argument_columns[i].get()); |
408 | 1.28k | offsets_list[i] = &col_str->get_offsets(); |
409 | 1.28k | chars_list[i] = &col_str->get_chars(); |
410 | 1.28k | } |
411 | | |
412 | 570 | auto& res_data = res->get_chars(); |
413 | 570 | auto& res_offset = res->get_offsets(); |
414 | 570 | res_offset.resize(input_rows_count); |
415 | | |
416 | 570 | VectorizedUtils::update_null_map(null_map->get_data(), *null_list[0]); |
417 | 570 | fmt::memory_buffer buffer; |
418 | 570 | std::vector<std::string_view> views; |
419 | | |
420 | 570 | if (is_column<ColumnArray>(argument_columns[1].get())) { |
421 | | // Determine if the nested type of the array is String |
422 | 105 | const auto& array_column = reinterpret_cast<const ColumnArray&>(*argument_columns[1]); |
423 | 105 | if (!array_column.get_data().is_column_string()) { |
424 | 0 | return Status::NotSupported( |
425 | 0 | fmt::format("unsupported nested array of type {} for function {}", |
426 | 0 | is_column_nullable(array_column.get_data()) |
427 | 0 | ? array_column.get_data().get_name() |
428 | 0 | : array_column.get_data().get_name(), |
429 | 0 | get_name())); |
430 | 0 | } |
431 | | // Concat string in array |
432 | 105 | _execute_array(input_rows_count, array_column, buffer, views, offsets_list, chars_list, |
433 | 105 | null_list, res_data, res_offset); |
434 | | |
435 | 465 | } else { |
436 | | // Concat string |
437 | 465 | _execute_string(input_rows_count, argument_size, buffer, views, offsets_list, |
438 | 465 | chars_list, null_list, res_data, res_offset); |
439 | 465 | } |
440 | 570 | if (is_null_type) { |
441 | 458 | block.get_by_position(result).column = |
442 | 458 | ColumnNullable::create(std::move(res), std::move(null_map)); |
443 | 458 | } else { |
444 | 112 | block.get_by_position(result).column = std::move(res); |
445 | 112 | } |
446 | 570 | return Status::OK(); |
447 | 570 | } |
448 | | |
449 | | private: |
450 | | void _execute_array(const size_t& input_rows_count, const ColumnArray& array_column, |
451 | | fmt::memory_buffer& buffer, std::vector<std::string_view>& views, |
452 | | const std::vector<const Offsets*>& offsets_list, |
453 | | const std::vector<const Chars*>& chars_list, |
454 | | const std::vector<const ColumnUInt8::Container*>& null_list, |
455 | 105 | Chars& res_data, Offsets& res_offset) const { |
456 | | // Get array nested column |
457 | 105 | const UInt8* array_nested_null_map = nullptr; |
458 | 105 | ColumnPtr array_nested_column = nullptr; |
459 | | |
460 | 105 | if (is_column_nullable(array_column.get_data())) { |
461 | 105 | const auto& array_nested_null_column = |
462 | 105 | reinterpret_cast<const ColumnNullable&>(array_column.get_data()); |
463 | | // String's null map in array |
464 | 105 | array_nested_null_map = |
465 | 105 | array_nested_null_column.get_null_map_column().get_data().data(); |
466 | 105 | array_nested_column = array_nested_null_column.get_nested_column_ptr(); |
467 | 105 | } else { |
468 | 0 | array_nested_column = array_column.get_data_ptr(); |
469 | 0 | } |
470 | | |
471 | 105 | const auto& string_column = reinterpret_cast<const ColumnString&>(*array_nested_column); |
472 | 105 | const Chars& string_src_chars = string_column.get_chars(); |
473 | 105 | const auto& src_string_offsets = string_column.get_offsets(); |
474 | 105 | const auto& src_array_offsets = array_column.get_offsets(); |
475 | 105 | size_t current_src_array_offset = 0; |
476 | | |
477 | | // Concat string in array |
478 | 605 | for (size_t i = 0; i < input_rows_count; ++i) { |
479 | 500 | auto& sep_offsets = *offsets_list[0]; |
480 | 500 | auto& sep_chars = *chars_list[0]; |
481 | 500 | auto& sep_nullmap = *null_list[0]; |
482 | | |
483 | 500 | if (sep_nullmap[i]) { |
484 | 11 | res_offset[i] = res_data.size(); |
485 | 11 | current_src_array_offset += src_array_offsets[i] - src_array_offsets[i - 1]; |
486 | 11 | continue; |
487 | 11 | } |
488 | | |
489 | 489 | int sep_size = sep_offsets[i] - sep_offsets[i - 1]; |
490 | 489 | const char* sep_data = reinterpret_cast<const char*>(&sep_chars[sep_offsets[i - 1]]); |
491 | | |
492 | 489 | std::string_view sep(sep_data, sep_size); |
493 | 489 | buffer.clear(); |
494 | 489 | views.clear(); |
495 | | |
496 | 489 | for (auto next_src_array_offset = src_array_offsets[i]; |
497 | 1.28k | current_src_array_offset < next_src_array_offset; ++current_src_array_offset) { |
498 | 800 | const auto current_src_string_offset = |
499 | 800 | current_src_array_offset ? src_string_offsets[current_src_array_offset - 1] |
500 | 800 | : 0; |
501 | 800 | size_t bytes_to_copy = |
502 | 800 | src_string_offsets[current_src_array_offset] - current_src_string_offset; |
503 | 800 | const char* ptr = |
504 | 800 | reinterpret_cast<const char*>(&string_src_chars[current_src_string_offset]); |
505 | | |
506 | 800 | if (array_nested_null_map == nullptr || |
507 | 800 | !array_nested_null_map[current_src_array_offset]) { |
508 | 771 | views.emplace_back(ptr, bytes_to_copy); |
509 | 771 | } |
510 | 800 | } |
511 | | |
512 | 489 | fmt::format_to(buffer, "{}", fmt::join(views, sep)); |
513 | | |
514 | 489 | StringOP::push_value_string(std::string_view(buffer.data(), buffer.size()), i, res_data, |
515 | 489 | res_offset); |
516 | 489 | } |
517 | 105 | } |
518 | | |
519 | | void _execute_string(const size_t& input_rows_count, const size_t& argument_size, |
520 | | fmt::memory_buffer& buffer, std::vector<std::string_view>& views, |
521 | | const std::vector<const Offsets*>& offsets_list, |
522 | | const std::vector<const Chars*>& chars_list, |
523 | | const std::vector<const ColumnUInt8::Container*>& null_list, |
524 | 465 | Chars& res_data, Offsets& res_offset) const { |
525 | | // Concat string |
526 | 1.08k | for (size_t i = 0; i < input_rows_count; ++i) { |
527 | 620 | auto& sep_offsets = *offsets_list[0]; |
528 | 620 | auto& sep_chars = *chars_list[0]; |
529 | 620 | auto& sep_nullmap = *null_list[0]; |
530 | 620 | if (sep_nullmap[i]) { |
531 | 78 | res_offset[i] = res_data.size(); |
532 | 78 | continue; |
533 | 78 | } |
534 | | |
535 | 542 | int sep_size = sep_offsets[i] - sep_offsets[i - 1]; |
536 | 542 | const char* sep_data = reinterpret_cast<const char*>(&sep_chars[sep_offsets[i - 1]]); |
537 | | |
538 | 542 | std::string_view sep(sep_data, sep_size); |
539 | 542 | buffer.clear(); |
540 | 542 | views.clear(); |
541 | 1.30k | for (size_t j = 1; j < argument_size; ++j) { |
542 | 764 | auto& current_offsets = *offsets_list[j]; |
543 | 764 | auto& current_chars = *chars_list[j]; |
544 | 764 | auto& current_nullmap = *null_list[j]; |
545 | 764 | int size = current_offsets[i] - current_offsets[i - 1]; |
546 | 764 | const char* ptr = |
547 | 764 | reinterpret_cast<const char*>(¤t_chars[current_offsets[i - 1]]); |
548 | 764 | if (!current_nullmap[i]) { |
549 | 688 | views.emplace_back(ptr, size); |
550 | 688 | } |
551 | 764 | } |
552 | 542 | fmt::format_to(buffer, "{}", fmt::join(views, sep)); |
553 | 542 | StringOP::push_value_string(std::string_view(buffer.data(), buffer.size()), i, res_data, |
554 | 542 | res_offset); |
555 | 542 | } |
556 | 465 | } |
557 | | }; |
558 | | |
559 | | class FunctionStringRepeat : public IFunction { |
560 | | public: |
561 | | static constexpr auto name = "repeat"; |
562 | 237 | static FunctionPtr create() { return std::make_shared<FunctionStringRepeat>(); } |
563 | 1 | String get_name() const override { return name; } |
564 | 228 | size_t get_number_of_arguments() const override { return 2; } |
565 | | // should set NULL value of nested data to default, |
566 | | // as iff it's not inited and invalid, the repeat result of length is so large cause overflow |
567 | 235 | bool need_replace_null_data_to_default() const override { return true; } |
568 | | |
569 | 228 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
570 | 228 | return make_nullable(std::make_shared<DataTypeString>()); |
571 | 228 | } |
572 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
573 | 271 | uint32_t result, size_t input_rows_count) const override { |
574 | 271 | DCHECK_EQ(arguments.size(), 2); |
575 | 271 | auto res = ColumnString::create(); |
576 | 271 | auto null_map = ColumnUInt8::create(); |
577 | | |
578 | 271 | ColumnPtr argument_ptr[2]; |
579 | 271 | argument_ptr[0] = |
580 | 271 | block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); |
581 | 271 | argument_ptr[1] = block.get_by_position(arguments[1]).column; |
582 | | |
583 | 271 | if (const auto* col1 = check_and_get_column<ColumnString>(*argument_ptr[0])) { |
584 | 271 | if (const auto* col2 = check_and_get_column<ColumnInt32>(*argument_ptr[1])) { |
585 | 151 | RETURN_IF_ERROR(vector_vector(col1->get_chars(), col1->get_offsets(), |
586 | 151 | col2->get_data(), res->get_chars(), |
587 | 151 | res->get_offsets(), null_map->get_data())); |
588 | 151 | block.replace_by_position( |
589 | 151 | result, ColumnNullable::create(std::move(res), std::move(null_map))); |
590 | 151 | return Status::OK(); |
591 | 151 | } else if (const auto* col2_const = |
592 | 120 | check_and_get_column<ColumnConst>(*argument_ptr[1])) { |
593 | 120 | DCHECK(check_and_get_column<ColumnInt32>(col2_const->get_data_column())); |
594 | 120 | int repeat = col2_const->get_int(0); |
595 | 120 | if (repeat <= 0) { |
596 | 18 | null_map->get_data().resize_fill(input_rows_count, 0); |
597 | 18 | res->insert_many_defaults(input_rows_count); |
598 | 102 | } else { |
599 | 102 | vector_const(col1->get_chars(), col1->get_offsets(), repeat, res->get_chars(), |
600 | 102 | res->get_offsets(), null_map->get_data()); |
601 | 102 | } |
602 | 120 | block.replace_by_position( |
603 | 120 | result, ColumnNullable::create(std::move(res), std::move(null_map))); |
604 | 120 | return Status::OK(); |
605 | 120 | } |
606 | 271 | } |
607 | | |
608 | 0 | return Status::RuntimeError("repeat function get error param: {}, {}", |
609 | 0 | argument_ptr[0]->get_name(), argument_ptr[1]->get_name()); |
610 | 271 | } |
611 | | |
612 | | Status vector_vector(const ColumnString::Chars& data, const ColumnString::Offsets& offsets, |
613 | | const ColumnInt32::Container& repeats, ColumnString::Chars& res_data, |
614 | | ColumnString::Offsets& res_offsets, |
615 | 151 | ColumnUInt8::Container& null_map) const { |
616 | 151 | size_t input_row_size = offsets.size(); |
617 | | |
618 | 151 | fmt::memory_buffer buffer; |
619 | 151 | res_offsets.resize(input_row_size); |
620 | 151 | null_map.resize_fill(input_row_size, 0); |
621 | 395 | for (ssize_t i = 0; i < input_row_size; ++i) { |
622 | 244 | buffer.clear(); |
623 | 244 | const char* raw_str = reinterpret_cast<const char*>(&data[offsets[i - 1]]); |
624 | 244 | size_t size = offsets[i] - offsets[i - 1]; |
625 | 244 | int repeat = repeats[i]; |
626 | 244 | if (repeat <= 0) { |
627 | 66 | StringOP::push_empty_string(i, res_data, res_offsets); |
628 | 178 | } else { |
629 | 178 | ColumnString::check_chars_length(repeat * size + res_data.size(), 0); |
630 | 132k | for (int j = 0; j < repeat; ++j) { |
631 | 131k | buffer.append(raw_str, raw_str + size); |
632 | 131k | } |
633 | 178 | StringOP::push_value_string(std::string_view(buffer.data(), buffer.size()), i, |
634 | 178 | res_data, res_offsets); |
635 | 178 | } |
636 | 244 | } |
637 | 151 | return Status::OK(); |
638 | 151 | } |
639 | | |
640 | | // TODO: 1. use pmr::vector<char> replace fmt_buffer may speed up the code |
641 | | // 2. abstract the `vector_vector` and `vector_const` |
642 | | // 3. rethink we should use `DEFAULT_MAX_STRING_SIZE` to bigger here |
643 | | void vector_const(const ColumnString::Chars& data, const ColumnString::Offsets& offsets, |
644 | | int repeat, ColumnString::Chars& res_data, ColumnString::Offsets& res_offsets, |
645 | 102 | ColumnUInt8::Container& null_map) const { |
646 | 102 | size_t input_row_size = offsets.size(); |
647 | | |
648 | 102 | fmt::memory_buffer buffer; |
649 | 102 | res_offsets.resize(input_row_size); |
650 | 102 | null_map.resize_fill(input_row_size, 0); |
651 | 4.31k | for (ssize_t i = 0; i < input_row_size; ++i) { |
652 | 4.21k | buffer.clear(); |
653 | 4.21k | const char* raw_str = reinterpret_cast<const char*>(&data[offsets[i - 1]]); |
654 | 4.21k | size_t size = offsets[i] - offsets[i - 1]; |
655 | 4.21k | ColumnString::check_chars_length(repeat * size + res_data.size(), 0); |
656 | | |
657 | 44.7k | for (int j = 0; j < repeat; ++j) { |
658 | 40.5k | buffer.append(raw_str, raw_str + size); |
659 | 40.5k | } |
660 | 4.21k | StringOP::push_value_string(std::string_view(buffer.data(), buffer.size()), i, res_data, |
661 | 4.21k | res_offsets); |
662 | 4.21k | } |
663 | 102 | } |
664 | | }; |
665 | | |
666 | | /// PaddingChars pre-processes the pad string for efficient padding. |
667 | | /// When is_utf8=false, character count equals byte count — no UTF-8 decoding needed. |
668 | | /// When is_utf8=true, we build a byte-offset table for code points. |
669 | | /// In both cases, the pad string is pre-expanded (doubled) until it has >= 16 characters, |
670 | | /// so that each memcpy in append_to copies at least 16 bytes at a time. |
671 | | template <bool is_utf8> |
672 | | struct PaddingChars { |
673 | | std::string pad_string; |
674 | | /// utf8_byte_offsets[i] = byte offset of i-th code point in pad_string. |
675 | | /// utf8_byte_offsets has (num_chars + 1) entries, with [0]=0 and [num_chars]=pad_string.size(). |
676 | | std::vector<size_t> utf8_byte_offsets; |
677 | | |
678 | | explicit PaddingChars(const uint8_t* data, size_t len) |
679 | 1.31k | : pad_string(reinterpret_cast<const char*>(data), len) { |
680 | 1.31k | init(); |
681 | 1.31k | } _ZN5doris12PaddingCharsILb0EEC2EPKhm Line | Count | Source | 679 | 63 | : pad_string(reinterpret_cast<const char*>(data), len) { | 680 | 63 | init(); | 681 | 63 | } |
_ZN5doris12PaddingCharsILb1EEC2EPKhm Line | Count | Source | 679 | 1.25k | : pad_string(reinterpret_cast<const char*>(data), len) { | 680 | 1.25k | init(); | 681 | 1.25k | } |
|
682 | | |
683 | 14.5k | size_t num_chars() const { |
684 | 14.5k | if constexpr (is_utf8) { |
685 | 6.10k | return utf8_byte_offsets.size() - 1; |
686 | 8.47k | } else { |
687 | 8.47k | return pad_string.size(); |
688 | 8.47k | } |
689 | 14.5k | } _ZNK5doris12PaddingCharsILb0EE9num_charsEv Line | Count | Source | 683 | 8.47k | size_t num_chars() const { | 684 | | if constexpr (is_utf8) { | 685 | | return utf8_byte_offsets.size() - 1; | 686 | 8.47k | } else { | 687 | 8.47k | return pad_string.size(); | 688 | 8.47k | } | 689 | 8.47k | } |
_ZNK5doris12PaddingCharsILb1EE9num_charsEv Line | Count | Source | 683 | 6.10k | size_t num_chars() const { | 684 | 6.10k | if constexpr (is_utf8) { | 685 | 6.10k | return utf8_byte_offsets.size() - 1; | 686 | | } else { | 687 | | return pad_string.size(); | 688 | | } | 689 | 6.10k | } |
|
690 | | |
691 | 23.9k | size_t chars_to_bytes(size_t n) const { |
692 | 23.9k | if constexpr (is_utf8) { |
693 | 19.7k | return utf8_byte_offsets[n]; |
694 | 19.7k | } else { |
695 | 4.15k | return n; |
696 | 4.15k | } |
697 | 23.9k | } _ZNK5doris12PaddingCharsILb0EE14chars_to_bytesEm Line | Count | Source | 691 | 4.15k | size_t chars_to_bytes(size_t n) const { | 692 | | if constexpr (is_utf8) { | 693 | | return utf8_byte_offsets[n]; | 694 | 4.15k | } else { | 695 | 4.15k | return n; | 696 | 4.15k | } | 697 | 4.15k | } |
_ZNK5doris12PaddingCharsILb1EE14chars_to_bytesEm Line | Count | Source | 691 | 19.7k | size_t chars_to_bytes(size_t n) const { | 692 | 19.7k | if constexpr (is_utf8) { | 693 | 19.7k | return utf8_byte_offsets[n]; | 694 | | } else { | 695 | | return n; | 696 | | } | 697 | 19.7k | } |
|
698 | | |
699 | | /// Append `num_chars_to_pad` padding characters to dst, return bytes written. |
700 | 2.52k | size_t append_to(uint8_t* dst, size_t num_chars_to_pad) const { |
701 | 2.52k | if (num_chars_to_pad == 0) { |
702 | 0 | return 0; |
703 | 0 | } |
704 | 2.52k | const auto* src = reinterpret_cast<const uint8_t*>(pad_string.data()); |
705 | 2.52k | const size_t step = num_chars(); |
706 | 2.52k | uint8_t* dst_start = dst; |
707 | 21.4k | while (num_chars_to_pad > step) { |
708 | 18.9k | size_t bytes = chars_to_bytes(step); |
709 | 18.9k | memcpy(dst, src, bytes); |
710 | 18.9k | dst += bytes; |
711 | 18.9k | num_chars_to_pad -= step; |
712 | 18.9k | } |
713 | 2.52k | size_t bytes = chars_to_bytes(num_chars_to_pad); |
714 | 2.52k | memcpy(dst, src, bytes); |
715 | 2.52k | dst += bytes; |
716 | 2.52k | return dst - dst_start; |
717 | 2.52k | } _ZNK5doris12PaddingCharsILb0EE9append_toEPhm Line | Count | Source | 700 | 2.07k | size_t append_to(uint8_t* dst, size_t num_chars_to_pad) const { | 701 | 2.07k | if (num_chars_to_pad == 0) { | 702 | 0 | return 0; | 703 | 0 | } | 704 | 2.07k | const auto* src = reinterpret_cast<const uint8_t*>(pad_string.data()); | 705 | 2.07k | const size_t step = num_chars(); | 706 | 2.07k | uint8_t* dst_start = dst; | 707 | 2.07k | while (num_chars_to_pad > step) { | 708 | 0 | size_t bytes = chars_to_bytes(step); | 709 | 0 | memcpy(dst, src, bytes); | 710 | 0 | dst += bytes; | 711 | 0 | num_chars_to_pad -= step; | 712 | 0 | } | 713 | 2.07k | size_t bytes = chars_to_bytes(num_chars_to_pad); | 714 | 2.07k | memcpy(dst, src, bytes); | 715 | 2.07k | dst += bytes; | 716 | 2.07k | return dst - dst_start; | 717 | 2.07k | } |
_ZNK5doris12PaddingCharsILb1EE9append_toEPhm Line | Count | Source | 700 | 443 | size_t append_to(uint8_t* dst, size_t num_chars_to_pad) const { | 701 | 443 | if (num_chars_to_pad == 0) { | 702 | 0 | return 0; | 703 | 0 | } | 704 | 443 | const auto* src = reinterpret_cast<const uint8_t*>(pad_string.data()); | 705 | 443 | const size_t step = num_chars(); | 706 | 443 | uint8_t* dst_start = dst; | 707 | 19.3k | while (num_chars_to_pad > step) { | 708 | 18.9k | size_t bytes = chars_to_bytes(step); | 709 | 18.9k | memcpy(dst, src, bytes); | 710 | 18.9k | dst += bytes; | 711 | 18.9k | num_chars_to_pad -= step; | 712 | 18.9k | } | 713 | 443 | size_t bytes = chars_to_bytes(num_chars_to_pad); | 714 | 443 | memcpy(dst, src, bytes); | 715 | 443 | dst += bytes; | 716 | 443 | return dst - dst_start; | 717 | 443 | } |
|
718 | | |
719 | | private: |
720 | 1.31k | void init() { |
721 | 1.31k | if (pad_string.empty()) { |
722 | 0 | return; |
723 | 0 | } |
724 | | |
725 | 1.31k | if constexpr (is_utf8) { |
726 | | // Build byte-offset table for each code point. |
727 | 1.25k | size_t offset = 0; |
728 | 1.25k | utf8_byte_offsets.reserve(pad_string.size() + 1); |
729 | 8.53k | while (offset < pad_string.size()) { |
730 | 7.27k | utf8_byte_offsets.push_back(offset); |
731 | 7.27k | offset += get_utf8_byte_length(static_cast<uint8_t>(pad_string[offset])); |
732 | 7.27k | offset = std::min(offset, pad_string.size()); |
733 | 7.27k | } |
734 | 1.25k | utf8_byte_offsets.push_back(pad_string.size()); |
735 | 1.25k | } |
736 | | |
737 | | // Pre-expand pad_string until it has >= 16 characters. |
738 | | // This ensures append_to() copies at least 16 bytes per iteration. |
739 | 4.46k | while (num_chars() < 16) { |
740 | 3.14k | if constexpr (is_utf8) { |
741 | 3.04k | size_t old_count = utf8_byte_offsets.size(); |
742 | 3.04k | size_t base = utf8_byte_offsets.back(); |
743 | 21.5k | for (size_t i = 1; i < old_count; ++i) { |
744 | 18.5k | utf8_byte_offsets.push_back(utf8_byte_offsets[i] + base); |
745 | 18.5k | } |
746 | 3.04k | } |
747 | 3.14k | pad_string += pad_string; |
748 | 3.14k | } |
749 | 1.31k | } _ZN5doris12PaddingCharsILb0EE4initEv Line | Count | Source | 720 | 63 | void init() { | 721 | 63 | if (pad_string.empty()) { | 722 | 0 | return; | 723 | 0 | } | 724 | | | 725 | | if constexpr (is_utf8) { | 726 | | // Build byte-offset table for each code point. | 727 | | size_t offset = 0; | 728 | | utf8_byte_offsets.reserve(pad_string.size() + 1); | 729 | | while (offset < pad_string.size()) { | 730 | | utf8_byte_offsets.push_back(offset); | 731 | | offset += get_utf8_byte_length(static_cast<uint8_t>(pad_string[offset])); | 732 | | offset = std::min(offset, pad_string.size()); | 733 | | } | 734 | | utf8_byte_offsets.push_back(pad_string.size()); | 735 | | } | 736 | | | 737 | | // Pre-expand pad_string until it has >= 16 characters. | 738 | | // This ensures append_to() copies at least 16 bytes per iteration. | 739 | 168 | while (num_chars() < 16) { | 740 | | if constexpr (is_utf8) { | 741 | | size_t old_count = utf8_byte_offsets.size(); | 742 | | size_t base = utf8_byte_offsets.back(); | 743 | | for (size_t i = 1; i < old_count; ++i) { | 744 | | utf8_byte_offsets.push_back(utf8_byte_offsets[i] + base); | 745 | | } | 746 | | } | 747 | 105 | pad_string += pad_string; | 748 | 105 | } | 749 | 63 | } |
_ZN5doris12PaddingCharsILb1EE4initEv Line | Count | Source | 720 | 1.25k | void init() { | 721 | 1.25k | if (pad_string.empty()) { | 722 | 0 | return; | 723 | 0 | } | 724 | | | 725 | 1.25k | if constexpr (is_utf8) { | 726 | | // Build byte-offset table for each code point. | 727 | 1.25k | size_t offset = 0; | 728 | 1.25k | utf8_byte_offsets.reserve(pad_string.size() + 1); | 729 | 8.53k | while (offset < pad_string.size()) { | 730 | 7.27k | utf8_byte_offsets.push_back(offset); | 731 | 7.27k | offset += get_utf8_byte_length(static_cast<uint8_t>(pad_string[offset])); | 732 | 7.27k | offset = std::min(offset, pad_string.size()); | 733 | 7.27k | } | 734 | 1.25k | utf8_byte_offsets.push_back(pad_string.size()); | 735 | 1.25k | } | 736 | | | 737 | | // Pre-expand pad_string until it has >= 16 characters. | 738 | | // This ensures append_to() copies at least 16 bytes per iteration. | 739 | 4.29k | while (num_chars() < 16) { | 740 | 3.04k | if constexpr (is_utf8) { | 741 | 3.04k | size_t old_count = utf8_byte_offsets.size(); | 742 | 3.04k | size_t base = utf8_byte_offsets.back(); | 743 | 21.5k | for (size_t i = 1; i < old_count; ++i) { | 744 | 18.5k | utf8_byte_offsets.push_back(utf8_byte_offsets[i] + base); | 745 | 18.5k | } | 746 | 3.04k | } | 747 | 3.04k | pad_string += pad_string; | 748 | 3.04k | } | 749 | 1.25k | } |
|
750 | | }; |
751 | | |
752 | | template <typename Impl> |
753 | | class FunctionStringPad : public IFunction { |
754 | | public: |
755 | | static constexpr auto name = Impl::name; |
756 | 1.87k | static FunctionPtr create() { return std::make_shared<FunctionStringPad>(); }_ZN5doris17FunctionStringPadINS_10StringLPadEE6createEv Line | Count | Source | 756 | 1.09k | static FunctionPtr create() { return std::make_shared<FunctionStringPad>(); } |
_ZN5doris17FunctionStringPadINS_10StringRPadEE6createEv Line | Count | Source | 756 | 773 | static FunctionPtr create() { return std::make_shared<FunctionStringPad>(); } |
|
757 | 2 | String get_name() const override { return name; }_ZNK5doris17FunctionStringPadINS_10StringLPadEE8get_nameB5cxx11Ev Line | Count | Source | 757 | 1 | String get_name() const override { return name; } |
_ZNK5doris17FunctionStringPadINS_10StringRPadEE8get_nameB5cxx11Ev Line | Count | Source | 757 | 1 | String get_name() const override { return name; } |
|
758 | 1.85k | size_t get_number_of_arguments() const override { return 3; }_ZNK5doris17FunctionStringPadINS_10StringLPadEE23get_number_of_argumentsEv Line | Count | Source | 758 | 1.08k | size_t get_number_of_arguments() const override { return 3; } |
_ZNK5doris17FunctionStringPadINS_10StringRPadEE23get_number_of_argumentsEv Line | Count | Source | 758 | 764 | size_t get_number_of_arguments() const override { return 3; } |
|
759 | | |
760 | 1.85k | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
761 | 1.85k | return make_nullable(std::make_shared<DataTypeString>()); |
762 | 1.85k | } _ZNK5doris17FunctionStringPadINS_10StringLPadEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 760 | 1.08k | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 761 | 1.08k | return make_nullable(std::make_shared<DataTypeString>()); | 762 | 1.08k | } |
_ZNK5doris17FunctionStringPadINS_10StringRPadEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 760 | 764 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 761 | 764 | return make_nullable(std::make_shared<DataTypeString>()); | 762 | 764 | } |
|
763 | | |
764 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
765 | 1.37k | uint32_t result, size_t input_rows_count) const override { |
766 | 1.37k | DCHECK_GE(arguments.size(), 3); |
767 | 1.37k | auto null_map = ColumnUInt8::create(input_rows_count, 0); |
768 | 1.37k | auto res = ColumnString::create(); |
769 | | |
770 | 1.37k | ColumnPtr col[3]; |
771 | 1.37k | bool col_const[3]; |
772 | 5.50k | for (size_t i = 0; i < 3; ++i) { |
773 | 4.12k | std::tie(col[i], col_const[i]) = |
774 | 4.12k | unpack_if_const(block.get_by_position(arguments[i]).column); |
775 | 4.12k | } |
776 | 1.37k | auto& null_map_data = null_map->get_data(); |
777 | 1.37k | auto& res_offsets = res->get_offsets(); |
778 | 1.37k | auto& res_chars = res->get_chars(); |
779 | 1.37k | res_offsets.resize(input_rows_count); |
780 | | |
781 | 1.37k | const auto* strcol = assert_cast<const ColumnString*>(col[0].get()); |
782 | 1.37k | const auto* col_len = assert_cast<const ColumnInt32*>(col[1].get()); |
783 | 1.37k | const auto& col_len_data = col_len->get_data(); |
784 | | |
785 | 1.37k | const auto* padcol = assert_cast<const ColumnString*>(col[2].get()); |
786 | | |
787 | 1.37k | if (col_const[1] && col_const[2]) { |
788 | 140 | auto pad = padcol->get_data_at(0); |
789 | 140 | const bool pad_all_ascii = |
790 | 140 | simd::VStringFunctions::is_ascii({pad.data, static_cast<size_t>(pad.size)}); |
791 | 140 | const bool all_ascii = pad_all_ascii && strcol->is_ascii(); |
792 | 140 | std::visit( |
793 | 140 | [&](auto str_const) { |
794 | 140 | if (all_ascii) { |
795 | 85 | execute_const_len_const_pad<true, str_const>( |
796 | 85 | *strcol, col_len_data, *padcol, res_offsets, res_chars, |
797 | 85 | null_map_data, input_rows_count); |
798 | 85 | } else { |
799 | 55 | execute_const_len_const_pad<false, str_const>( |
800 | 55 | *strcol, col_len_data, *padcol, res_offsets, res_chars, |
801 | 55 | null_map_data, input_rows_count); |
802 | 55 | } |
803 | 140 | }, _ZZNK5doris17FunctionStringPadINS_10StringLPadEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_E_clISt17integral_constantIbLb0EEEEDaSC_ Line | Count | Source | 793 | 73 | [&](auto str_const) { | 794 | 73 | if (all_ascii) { | 795 | 46 | execute_const_len_const_pad<true, str_const>( | 796 | 46 | *strcol, col_len_data, *padcol, res_offsets, res_chars, | 797 | 46 | null_map_data, input_rows_count); | 798 | 46 | } else { | 799 | 27 | execute_const_len_const_pad<false, str_const>( | 800 | 27 | *strcol, col_len_data, *padcol, res_offsets, res_chars, | 801 | 27 | null_map_data, input_rows_count); | 802 | 27 | } | 803 | 73 | }, |
Unexecuted instantiation: _ZZNK5doris17FunctionStringPadINS_10StringLPadEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_E_clISt17integral_constantIbLb1EEEEDaSC_ _ZZNK5doris17FunctionStringPadINS_10StringRPadEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_E_clISt17integral_constantIbLb0EEEEDaSC_ Line | Count | Source | 793 | 67 | [&](auto str_const) { | 794 | 67 | if (all_ascii) { | 795 | 39 | execute_const_len_const_pad<true, str_const>( | 796 | 39 | *strcol, col_len_data, *padcol, res_offsets, res_chars, | 797 | 39 | null_map_data, input_rows_count); | 798 | 39 | } else { | 799 | 28 | execute_const_len_const_pad<false, str_const>( | 800 | 28 | *strcol, col_len_data, *padcol, res_offsets, res_chars, | 801 | 28 | null_map_data, input_rows_count); | 802 | 28 | } | 803 | 67 | }, |
Unexecuted instantiation: _ZZNK5doris17FunctionStringPadINS_10StringRPadEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_E_clISt17integral_constantIbLb1EEEEDaSC_ |
804 | 140 | make_bool_variant(col_const[0])); |
805 | 1.23k | } else { |
806 | 1.23k | std::visit( |
807 | 1.23k | [&](auto str_const) { |
808 | 1.23k | execute_general<str_const>(*strcol, col_len_data, col_const[1], *padcol, |
809 | 1.23k | col_const[2], res_offsets, res_chars, |
810 | 1.23k | null_map_data, input_rows_count); |
811 | 1.23k | }, _ZZNK5doris17FunctionStringPadINS_10StringLPadEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_E0_clISt17integral_constantIbLb0EEEEDaSC_ Line | Count | Source | 807 | 589 | [&](auto str_const) { | 808 | 589 | execute_general<str_const>(*strcol, col_len_data, col_const[1], *padcol, | 809 | 589 | col_const[2], res_offsets, res_chars, | 810 | 589 | null_map_data, input_rows_count); | 811 | 589 | }, |
_ZZNK5doris17FunctionStringPadINS_10StringLPadEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_E0_clISt17integral_constantIbLb1EEEEDaSC_ Line | Count | Source | 807 | 186 | [&](auto str_const) { | 808 | 186 | execute_general<str_const>(*strcol, col_len_data, col_const[1], *padcol, | 809 | 186 | col_const[2], res_offsets, res_chars, | 810 | 186 | null_map_data, input_rows_count); | 811 | 186 | }, |
_ZZNK5doris17FunctionStringPadINS_10StringRPadEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_E0_clISt17integral_constantIbLb0EEEEDaSC_ Line | Count | Source | 807 | 275 | [&](auto str_const) { | 808 | 275 | execute_general<str_const>(*strcol, col_len_data, col_const[1], *padcol, | 809 | 275 | col_const[2], res_offsets, res_chars, | 810 | 275 | null_map_data, input_rows_count); | 811 | 275 | }, |
_ZZNK5doris17FunctionStringPadINS_10StringRPadEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmENKUlT_E0_clISt17integral_constantIbLb1EEEEDaSC_ Line | Count | Source | 807 | 186 | [&](auto str_const) { | 808 | 186 | execute_general<str_const>(*strcol, col_len_data, col_const[1], *padcol, | 809 | 186 | col_const[2], res_offsets, res_chars, | 810 | 186 | null_map_data, input_rows_count); | 811 | 186 | }, |
|
812 | 1.23k | make_bool_variant(col_const[0])); |
813 | 1.23k | } |
814 | | |
815 | 1.37k | block.get_by_position(result).column = |
816 | 1.37k | ColumnNullable::create(std::move(res), std::move(null_map)); |
817 | 1.37k | return Status::OK(); |
818 | 1.37k | } _ZNK5doris17FunctionStringPadINS_10StringLPadEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 765 | 848 | uint32_t result, size_t input_rows_count) const override { | 766 | 848 | DCHECK_GE(arguments.size(), 3); | 767 | 848 | auto null_map = ColumnUInt8::create(input_rows_count, 0); | 768 | 848 | auto res = ColumnString::create(); | 769 | | | 770 | 848 | ColumnPtr col[3]; | 771 | 848 | bool col_const[3]; | 772 | 3.39k | for (size_t i = 0; i < 3; ++i) { | 773 | 2.54k | std::tie(col[i], col_const[i]) = | 774 | 2.54k | unpack_if_const(block.get_by_position(arguments[i]).column); | 775 | 2.54k | } | 776 | 848 | auto& null_map_data = null_map->get_data(); | 777 | 848 | auto& res_offsets = res->get_offsets(); | 778 | 848 | auto& res_chars = res->get_chars(); | 779 | 848 | res_offsets.resize(input_rows_count); | 780 | | | 781 | 848 | const auto* strcol = assert_cast<const ColumnString*>(col[0].get()); | 782 | 848 | const auto* col_len = assert_cast<const ColumnInt32*>(col[1].get()); | 783 | 848 | const auto& col_len_data = col_len->get_data(); | 784 | | | 785 | 848 | const auto* padcol = assert_cast<const ColumnString*>(col[2].get()); | 786 | | | 787 | 848 | if (col_const[1] && col_const[2]) { | 788 | 73 | auto pad = padcol->get_data_at(0); | 789 | 73 | const bool pad_all_ascii = | 790 | 73 | simd::VStringFunctions::is_ascii({pad.data, static_cast<size_t>(pad.size)}); | 791 | 73 | const bool all_ascii = pad_all_ascii && strcol->is_ascii(); | 792 | 73 | std::visit( | 793 | 73 | [&](auto str_const) { | 794 | 73 | if (all_ascii) { | 795 | 73 | execute_const_len_const_pad<true, str_const>( | 796 | 73 | *strcol, col_len_data, *padcol, res_offsets, res_chars, | 797 | 73 | null_map_data, input_rows_count); | 798 | 73 | } else { | 799 | 73 | execute_const_len_const_pad<false, str_const>( | 800 | 73 | *strcol, col_len_data, *padcol, res_offsets, res_chars, | 801 | 73 | null_map_data, input_rows_count); | 802 | 73 | } | 803 | 73 | }, | 804 | 73 | make_bool_variant(col_const[0])); | 805 | 775 | } else { | 806 | 775 | std::visit( | 807 | 775 | [&](auto str_const) { | 808 | 775 | execute_general<str_const>(*strcol, col_len_data, col_const[1], *padcol, | 809 | 775 | col_const[2], res_offsets, res_chars, | 810 | 775 | null_map_data, input_rows_count); | 811 | 775 | }, | 812 | 775 | make_bool_variant(col_const[0])); | 813 | 775 | } | 814 | | | 815 | 848 | block.get_by_position(result).column = | 816 | 848 | ColumnNullable::create(std::move(res), std::move(null_map)); | 817 | 848 | return Status::OK(); | 818 | 848 | } |
_ZNK5doris17FunctionStringPadINS_10StringRPadEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 765 | 528 | uint32_t result, size_t input_rows_count) const override { | 766 | 528 | DCHECK_GE(arguments.size(), 3); | 767 | 528 | auto null_map = ColumnUInt8::create(input_rows_count, 0); | 768 | 528 | auto res = ColumnString::create(); | 769 | | | 770 | 528 | ColumnPtr col[3]; | 771 | 528 | bool col_const[3]; | 772 | 2.11k | for (size_t i = 0; i < 3; ++i) { | 773 | 1.58k | std::tie(col[i], col_const[i]) = | 774 | 1.58k | unpack_if_const(block.get_by_position(arguments[i]).column); | 775 | 1.58k | } | 776 | 528 | auto& null_map_data = null_map->get_data(); | 777 | 528 | auto& res_offsets = res->get_offsets(); | 778 | 528 | auto& res_chars = res->get_chars(); | 779 | 528 | res_offsets.resize(input_rows_count); | 780 | | | 781 | 528 | const auto* strcol = assert_cast<const ColumnString*>(col[0].get()); | 782 | 528 | const auto* col_len = assert_cast<const ColumnInt32*>(col[1].get()); | 783 | 528 | const auto& col_len_data = col_len->get_data(); | 784 | | | 785 | 528 | const auto* padcol = assert_cast<const ColumnString*>(col[2].get()); | 786 | | | 787 | 528 | if (col_const[1] && col_const[2]) { | 788 | 67 | auto pad = padcol->get_data_at(0); | 789 | 67 | const bool pad_all_ascii = | 790 | 67 | simd::VStringFunctions::is_ascii({pad.data, static_cast<size_t>(pad.size)}); | 791 | 67 | const bool all_ascii = pad_all_ascii && strcol->is_ascii(); | 792 | 67 | std::visit( | 793 | 67 | [&](auto str_const) { | 794 | 67 | if (all_ascii) { | 795 | 67 | execute_const_len_const_pad<true, str_const>( | 796 | 67 | *strcol, col_len_data, *padcol, res_offsets, res_chars, | 797 | 67 | null_map_data, input_rows_count); | 798 | 67 | } else { | 799 | 67 | execute_const_len_const_pad<false, str_const>( | 800 | 67 | *strcol, col_len_data, *padcol, res_offsets, res_chars, | 801 | 67 | null_map_data, input_rows_count); | 802 | 67 | } | 803 | 67 | }, | 804 | 67 | make_bool_variant(col_const[0])); | 805 | 461 | } else { | 806 | 461 | std::visit( | 807 | 461 | [&](auto str_const) { | 808 | 461 | execute_general<str_const>(*strcol, col_len_data, col_const[1], *padcol, | 809 | 461 | col_const[2], res_offsets, res_chars, | 810 | 461 | null_map_data, input_rows_count); | 811 | 461 | }, | 812 | 461 | make_bool_variant(col_const[0])); | 813 | 461 | } | 814 | | | 815 | 528 | block.get_by_position(result).column = | 816 | 528 | ColumnNullable::create(std::move(res), std::move(null_map)); | 817 | 528 | return Status::OK(); | 818 | 528 | } |
|
819 | | |
820 | | private: |
821 | | template <bool is_utf8> |
822 | 3.17k | static size_t get_char_length(const uint8_t* str_data, size_t str_byte_len) { |
823 | 3.17k | if constexpr (is_utf8) { |
824 | 1.02k | return simd::VStringFunctions::get_char_len(reinterpret_cast<const char*>(str_data), |
825 | 1.02k | str_byte_len); |
826 | 1.02k | } |
827 | 0 | return str_byte_len; |
828 | 3.17k | } _ZN5doris17FunctionStringPadINS_10StringLPadEE15get_char_lengthILb0EEEmPKhm Line | Count | Source | 822 | 58 | static size_t get_char_length(const uint8_t* str_data, size_t str_byte_len) { | 823 | | if constexpr (is_utf8) { | 824 | | return simd::VStringFunctions::get_char_len(reinterpret_cast<const char*>(str_data), | 825 | | str_byte_len); | 826 | | } | 827 | 58 | return str_byte_len; | 828 | 58 | } |
_ZN5doris17FunctionStringPadINS_10StringLPadEE15get_char_lengthILb1EEEmPKhm Line | Count | Source | 822 | 670 | static size_t get_char_length(const uint8_t* str_data, size_t str_byte_len) { | 823 | 670 | if constexpr (is_utf8) { | 824 | 670 | return simd::VStringFunctions::get_char_len(reinterpret_cast<const char*>(str_data), | 825 | 670 | str_byte_len); | 826 | 670 | } | 827 | 0 | return str_byte_len; | 828 | 670 | } |
_ZN5doris17FunctionStringPadINS_10StringRPadEE15get_char_lengthILb0EEEmPKhm Line | Count | Source | 822 | 2.09k | static size_t get_char_length(const uint8_t* str_data, size_t str_byte_len) { | 823 | | if constexpr (is_utf8) { | 824 | | return simd::VStringFunctions::get_char_len(reinterpret_cast<const char*>(str_data), | 825 | | str_byte_len); | 826 | | } | 827 | 2.09k | return str_byte_len; | 828 | 2.09k | } |
_ZN5doris17FunctionStringPadINS_10StringRPadEE15get_char_lengthILb1EEEmPKhm Line | Count | Source | 822 | 356 | static size_t get_char_length(const uint8_t* str_data, size_t str_byte_len) { | 823 | 356 | if constexpr (is_utf8) { | 824 | 356 | return simd::VStringFunctions::get_char_len(reinterpret_cast<const char*>(str_data), | 825 | 356 | str_byte_len); | 826 | 356 | } | 827 | 0 | return str_byte_len; | 828 | 356 | } |
|
829 | | |
830 | | template <bool is_utf8> |
831 | | static size_t get_truncated_byte_length(const uint8_t* str_data, size_t str_byte_len, |
832 | 641 | size_t str_char_len, size_t target_len) { |
833 | 641 | if constexpr (!is_utf8) { |
834 | 76 | return target_len; |
835 | 76 | } |
836 | 641 | if (str_char_len == target_len) { |
837 | 94 | return str_byte_len; |
838 | 94 | } |
839 | 547 | auto [byte_len, _] = simd::VStringFunctions::iterate_utf8_with_limit_length( |
840 | 547 | reinterpret_cast<const char*>(str_data), |
841 | 547 | reinterpret_cast<const char*>(str_data) + str_byte_len, target_len); |
842 | 547 | return byte_len; |
843 | 641 | } _ZN5doris17FunctionStringPadINS_10StringLPadEE25get_truncated_byte_lengthILb0EEEmPKhmmm Line | Count | Source | 832 | 38 | size_t str_char_len, size_t target_len) { | 833 | 38 | if constexpr (!is_utf8) { | 834 | 38 | return target_len; | 835 | 38 | } | 836 | 38 | if (str_char_len == target_len) { | 837 | 0 | return str_byte_len; | 838 | 0 | } | 839 | 38 | auto [byte_len, _] = simd::VStringFunctions::iterate_utf8_with_limit_length( | 840 | 38 | reinterpret_cast<const char*>(str_data), | 841 | 38 | reinterpret_cast<const char*>(str_data) + str_byte_len, target_len); | 842 | 38 | return byte_len; | 843 | 38 | } |
_ZN5doris17FunctionStringPadINS_10StringLPadEE25get_truncated_byte_lengthILb1EEEmPKhmmm Line | Count | Source | 832 | 288 | size_t str_char_len, size_t target_len) { | 833 | | if constexpr (!is_utf8) { | 834 | | return target_len; | 835 | | } | 836 | 288 | if (str_char_len == target_len) { | 837 | 49 | return str_byte_len; | 838 | 49 | } | 839 | 239 | auto [byte_len, _] = simd::VStringFunctions::iterate_utf8_with_limit_length( | 840 | 239 | reinterpret_cast<const char*>(str_data), | 841 | 239 | reinterpret_cast<const char*>(str_data) + str_byte_len, target_len); | 842 | 239 | return byte_len; | 843 | 288 | } |
_ZN5doris17FunctionStringPadINS_10StringRPadEE25get_truncated_byte_lengthILb0EEEmPKhmmm Line | Count | Source | 832 | 38 | size_t str_char_len, size_t target_len) { | 833 | 38 | if constexpr (!is_utf8) { | 834 | 38 | return target_len; | 835 | 38 | } | 836 | 38 | if (str_char_len == target_len) { | 837 | 0 | return str_byte_len; | 838 | 0 | } | 839 | 38 | auto [byte_len, _] = simd::VStringFunctions::iterate_utf8_with_limit_length( | 840 | 38 | reinterpret_cast<const char*>(str_data), | 841 | 38 | reinterpret_cast<const char*>(str_data) + str_byte_len, target_len); | 842 | 38 | return byte_len; | 843 | 38 | } |
_ZN5doris17FunctionStringPadINS_10StringRPadEE25get_truncated_byte_lengthILb1EEEmPKhmmm Line | Count | Source | 832 | 277 | size_t str_char_len, size_t target_len) { | 833 | | if constexpr (!is_utf8) { | 834 | | return target_len; | 835 | | } | 836 | 277 | if (str_char_len == target_len) { | 837 | 45 | return str_byte_len; | 838 | 45 | } | 839 | 232 | auto [byte_len, _] = simd::VStringFunctions::iterate_utf8_with_limit_length( | 840 | 232 | reinterpret_cast<const char*>(str_data), | 841 | 232 | reinterpret_cast<const char*>(str_data) + str_byte_len, target_len); | 842 | 232 | return byte_len; | 843 | 277 | } |
|
844 | | |
845 | 3.16k | static void ensure_capacity(ColumnString::Chars& res_chars, size_t needed, size_t row) { |
846 | 3.16k | if (needed <= res_chars.size()) { |
847 | 2.75k | return; |
848 | 2.75k | } |
849 | 404 | ColumnString::check_chars_length(needed, row); |
850 | 404 | res_chars.resize(std::max(needed, res_chars.size() * 3 / 2)); |
851 | 404 | } _ZN5doris17FunctionStringPadINS_10StringLPadEE15ensure_capacityERNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmm Line | Count | Source | 845 | 720 | static void ensure_capacity(ColumnString::Chars& res_chars, size_t needed, size_t row) { | 846 | 720 | if (needed <= res_chars.size()) { | 847 | 365 | return; | 848 | 365 | } | 849 | 355 | ColumnString::check_chars_length(needed, row); | 850 | 355 | res_chars.resize(std::max(needed, res_chars.size() * 3 / 2)); | 851 | 355 | } |
_ZN5doris17FunctionStringPadINS_10StringRPadEE15ensure_capacityERNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmm Line | Count | Source | 845 | 2.44k | static void ensure_capacity(ColumnString::Chars& res_chars, size_t needed, size_t row) { | 846 | 2.44k | if (needed <= res_chars.size()) { | 847 | 2.39k | return; | 848 | 2.39k | } | 849 | 49 | ColumnString::check_chars_length(needed, row); | 850 | 49 | res_chars.resize(std::max(needed, res_chars.size() * 3 / 2)); | 851 | 49 | } |
|
852 | | |
853 | | template <bool is_utf8> |
854 | | static size_t estimate_const_output_bytes(const ColumnString::Chars& strcol_chars, |
855 | | int target_len, size_t input_rows_count, |
856 | 140 | const PaddingChars<is_utf8>* padding) { |
857 | 140 | if (target_len <= 0) { |
858 | 96 | return 0; |
859 | 96 | } |
860 | 44 | if constexpr (!is_utf8) { |
861 | 31 | return static_cast<size_t>(target_len) * input_rows_count; |
862 | 31 | } |
863 | 44 | if (padding != nullptr && padding->num_chars() > 0) { |
864 | 11 | size_t pad_bytes_per_char = |
865 | 11 | (padding->pad_string.size() + padding->num_chars() - 1) / padding->num_chars(); |
866 | 11 | return strcol_chars.size() + |
867 | 11 | static_cast<size_t>(target_len) * pad_bytes_per_char * input_rows_count; |
868 | 11 | } |
869 | 33 | return strcol_chars.size(); |
870 | 44 | } _ZN5doris17FunctionStringPadINS_10StringLPadEE27estimate_const_output_bytesILb0EEEmRKNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEimPKNS_12PaddingCharsIXT_EEE Line | Count | Source | 856 | 46 | const PaddingChars<is_utf8>* padding) { | 857 | 46 | if (target_len <= 0) { | 858 | 27 | return 0; | 859 | 27 | } | 860 | 19 | if constexpr (!is_utf8) { | 861 | 19 | return static_cast<size_t>(target_len) * input_rows_count; | 862 | 19 | } | 863 | 19 | if (padding != nullptr && padding->num_chars() > 0) { | 864 | 0 | size_t pad_bytes_per_char = | 865 | 0 | (padding->pad_string.size() + padding->num_chars() - 1) / padding->num_chars(); | 866 | 0 | return strcol_chars.size() + | 867 | 0 | static_cast<size_t>(target_len) * pad_bytes_per_char * input_rows_count; | 868 | 0 | } | 869 | 19 | return strcol_chars.size(); | 870 | 19 | } |
_ZN5doris17FunctionStringPadINS_10StringLPadEE27estimate_const_output_bytesILb1EEEmRKNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEimPKNS_12PaddingCharsIXT_EEE Line | Count | Source | 856 | 27 | const PaddingChars<is_utf8>* padding) { | 857 | 27 | if (target_len <= 0) { | 858 | 21 | return 0; | 859 | 21 | } | 860 | | if constexpr (!is_utf8) { | 861 | | return static_cast<size_t>(target_len) * input_rows_count; | 862 | | } | 863 | 6 | if (padding != nullptr && padding->num_chars() > 0) { | 864 | 5 | size_t pad_bytes_per_char = | 865 | 5 | (padding->pad_string.size() + padding->num_chars() - 1) / padding->num_chars(); | 866 | 5 | return strcol_chars.size() + | 867 | 5 | static_cast<size_t>(target_len) * pad_bytes_per_char * input_rows_count; | 868 | 5 | } | 869 | 1 | return strcol_chars.size(); | 870 | 6 | } |
_ZN5doris17FunctionStringPadINS_10StringRPadEE27estimate_const_output_bytesILb0EEEmRKNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEimPKNS_12PaddingCharsIXT_EEE Line | Count | Source | 856 | 39 | const PaddingChars<is_utf8>* padding) { | 857 | 39 | if (target_len <= 0) { | 858 | 27 | return 0; | 859 | 27 | } | 860 | 12 | if constexpr (!is_utf8) { | 861 | 12 | return static_cast<size_t>(target_len) * input_rows_count; | 862 | 12 | } | 863 | 12 | if (padding != nullptr && padding->num_chars() > 0) { | 864 | 0 | size_t pad_bytes_per_char = | 865 | 0 | (padding->pad_string.size() + padding->num_chars() - 1) / padding->num_chars(); | 866 | 0 | return strcol_chars.size() + | 867 | 0 | static_cast<size_t>(target_len) * pad_bytes_per_char * input_rows_count; | 868 | 0 | } | 869 | 12 | return strcol_chars.size(); | 870 | 12 | } |
_ZN5doris17FunctionStringPadINS_10StringRPadEE27estimate_const_output_bytesILb1EEEmRKNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEimPKNS_12PaddingCharsIXT_EEE Line | Count | Source | 856 | 28 | const PaddingChars<is_utf8>* padding) { | 857 | 28 | if (target_len <= 0) { | 858 | 21 | return 0; | 859 | 21 | } | 860 | | if constexpr (!is_utf8) { | 861 | | return static_cast<size_t>(target_len) * input_rows_count; | 862 | | } | 863 | 7 | if (padding != nullptr && padding->num_chars() > 0) { | 864 | 6 | size_t pad_bytes_per_char = | 865 | 6 | (padding->pad_string.size() + padding->num_chars() - 1) / padding->num_chars(); | 866 | 6 | return strcol_chars.size() + | 867 | 6 | static_cast<size_t>(target_len) * pad_bytes_per_char * input_rows_count; | 868 | 6 | } | 869 | 1 | return strcol_chars.size(); | 870 | 7 | } |
|
871 | | |
872 | | template <bool is_utf8> |
873 | | static void append_result_row(const uint8_t* str_data, size_t str_byte_len, int target_len, |
874 | | const PaddingChars<is_utf8>* padding, |
875 | | ColumnString::Chars& res_chars, |
876 | | ColumnString::Offsets& res_offsets, |
877 | | ColumnUInt8::Container& null_map_data, size_t row, |
878 | 3.74k | size_t& dst_offset) { |
879 | 3.74k | if (target_len < 0) { |
880 | 562 | null_map_data[row] = true; |
881 | 562 | res_offsets[row] = dst_offset; |
882 | 562 | return; |
883 | 562 | } |
884 | | |
885 | 3.17k | const size_t str_char_len = get_char_length<is_utf8>(str_data, str_byte_len); |
886 | 3.17k | const size_t target_char_len = static_cast<size_t>(target_len); |
887 | 3.17k | if (str_char_len >= target_char_len) { |
888 | 641 | const size_t truncated_byte_len = get_truncated_byte_length<is_utf8>( |
889 | 641 | str_data, str_byte_len, str_char_len, target_char_len); |
890 | 641 | const size_t needed = dst_offset + truncated_byte_len; |
891 | 641 | ensure_capacity(res_chars, needed, row); |
892 | 641 | memcpy(res_chars.data() + dst_offset, str_data, truncated_byte_len); |
893 | 641 | dst_offset += truncated_byte_len; |
894 | 641 | res_offsets[row] = dst_offset; |
895 | 641 | return; |
896 | 641 | } |
897 | | |
898 | 2.53k | if (padding == nullptr || padding->num_chars() == 0) { |
899 | 18 | res_offsets[row] = dst_offset; |
900 | 18 | return; |
901 | 18 | } |
902 | | |
903 | 2.52k | const size_t pad_char_count = target_char_len - str_char_len; |
904 | 2.52k | const size_t full_cycles = pad_char_count / padding->num_chars(); |
905 | 2.52k | const size_t remainder_chars = pad_char_count % padding->num_chars(); |
906 | 2.52k | const size_t pad_bytes = |
907 | 2.52k | full_cycles * padding->pad_string.size() + padding->chars_to_bytes(remainder_chars); |
908 | 2.52k | const size_t needed = dst_offset + str_byte_len + pad_bytes; |
909 | 2.52k | ensure_capacity(res_chars, needed, row); |
910 | | |
911 | 2.52k | if constexpr (Impl::is_lpad) { |
912 | 394 | dst_offset += padding->append_to(res_chars.data() + dst_offset, pad_char_count); |
913 | 394 | memcpy(res_chars.data() + dst_offset, str_data, str_byte_len); |
914 | 394 | dst_offset += str_byte_len; |
915 | 2.12k | } else { |
916 | 2.12k | memcpy(res_chars.data() + dst_offset, str_data, str_byte_len); |
917 | 2.12k | dst_offset += str_byte_len; |
918 | 2.12k | dst_offset += padding->append_to(res_chars.data() + dst_offset, pad_char_count); |
919 | 2.12k | } |
920 | 2.52k | res_offsets[row] = dst_offset; |
921 | 2.52k | } _ZN5doris17FunctionStringPadINS_10StringLPadEE17append_result_rowILb0EEEvPKhmiPKNS_12PaddingCharsIXT_EEERNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEERNSA_IjLm4096ESD_Lm16ELm15EEESF_mRm Line | Count | Source | 878 | 76 | size_t& dst_offset) { | 879 | 76 | if (target_len < 0) { | 880 | 18 | null_map_data[row] = true; | 881 | 18 | res_offsets[row] = dst_offset; | 882 | 18 | return; | 883 | 18 | } | 884 | | | 885 | 58 | const size_t str_char_len = get_char_length<is_utf8>(str_data, str_byte_len); | 886 | 58 | const size_t target_char_len = static_cast<size_t>(target_len); | 887 | 58 | if (str_char_len >= target_char_len) { | 888 | 38 | const size_t truncated_byte_len = get_truncated_byte_length<is_utf8>( | 889 | 38 | str_data, str_byte_len, str_char_len, target_char_len); | 890 | 38 | const size_t needed = dst_offset + truncated_byte_len; | 891 | 38 | ensure_capacity(res_chars, needed, row); | 892 | 38 | memcpy(res_chars.data() + dst_offset, str_data, truncated_byte_len); | 893 | 38 | dst_offset += truncated_byte_len; | 894 | 38 | res_offsets[row] = dst_offset; | 895 | 38 | return; | 896 | 38 | } | 897 | | | 898 | 20 | if (padding == nullptr || padding->num_chars() == 0) { | 899 | 0 | res_offsets[row] = dst_offset; | 900 | 0 | return; | 901 | 0 | } | 902 | | | 903 | 20 | const size_t pad_char_count = target_char_len - str_char_len; | 904 | 20 | const size_t full_cycles = pad_char_count / padding->num_chars(); | 905 | 20 | const size_t remainder_chars = pad_char_count % padding->num_chars(); | 906 | 20 | const size_t pad_bytes = | 907 | 20 | full_cycles * padding->pad_string.size() + padding->chars_to_bytes(remainder_chars); | 908 | 20 | const size_t needed = dst_offset + str_byte_len + pad_bytes; | 909 | 20 | ensure_capacity(res_chars, needed, row); | 910 | | | 911 | 20 | if constexpr (Impl::is_lpad) { | 912 | 20 | dst_offset += padding->append_to(res_chars.data() + dst_offset, pad_char_count); | 913 | 20 | memcpy(res_chars.data() + dst_offset, str_data, str_byte_len); | 914 | 20 | dst_offset += str_byte_len; | 915 | | } else { | 916 | | memcpy(res_chars.data() + dst_offset, str_data, str_byte_len); | 917 | | dst_offset += str_byte_len; | 918 | | dst_offset += padding->append_to(res_chars.data() + dst_offset, pad_char_count); | 919 | | } | 920 | 20 | res_offsets[row] = dst_offset; | 921 | 20 | } |
_ZN5doris17FunctionStringPadINS_10StringLPadEE17append_result_rowILb1EEEvPKhmiPKNS_12PaddingCharsIXT_EEERNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEERNSA_IjLm4096ESD_Lm16ELm15EEESF_mRm Line | Count | Source | 878 | 933 | size_t& dst_offset) { | 879 | 933 | if (target_len < 0) { | 880 | 263 | null_map_data[row] = true; | 881 | 263 | res_offsets[row] = dst_offset; | 882 | 263 | return; | 883 | 263 | } | 884 | | | 885 | 670 | const size_t str_char_len = get_char_length<is_utf8>(str_data, str_byte_len); | 886 | 670 | const size_t target_char_len = static_cast<size_t>(target_len); | 887 | 670 | if (str_char_len >= target_char_len) { | 888 | 288 | const size_t truncated_byte_len = get_truncated_byte_length<is_utf8>( | 889 | 288 | str_data, str_byte_len, str_char_len, target_char_len); | 890 | 288 | const size_t needed = dst_offset + truncated_byte_len; | 891 | 288 | ensure_capacity(res_chars, needed, row); | 892 | 288 | memcpy(res_chars.data() + dst_offset, str_data, truncated_byte_len); | 893 | 288 | dst_offset += truncated_byte_len; | 894 | 288 | res_offsets[row] = dst_offset; | 895 | 288 | return; | 896 | 288 | } | 897 | | | 898 | 382 | if (padding == nullptr || padding->num_chars() == 0) { | 899 | 8 | res_offsets[row] = dst_offset; | 900 | 8 | return; | 901 | 8 | } | 902 | | | 903 | 374 | const size_t pad_char_count = target_char_len - str_char_len; | 904 | 374 | const size_t full_cycles = pad_char_count / padding->num_chars(); | 905 | 374 | const size_t remainder_chars = pad_char_count % padding->num_chars(); | 906 | 374 | const size_t pad_bytes = | 907 | 374 | full_cycles * padding->pad_string.size() + padding->chars_to_bytes(remainder_chars); | 908 | 374 | const size_t needed = dst_offset + str_byte_len + pad_bytes; | 909 | 374 | ensure_capacity(res_chars, needed, row); | 910 | | | 911 | 374 | if constexpr (Impl::is_lpad) { | 912 | 374 | dst_offset += padding->append_to(res_chars.data() + dst_offset, pad_char_count); | 913 | 374 | memcpy(res_chars.data() + dst_offset, str_data, str_byte_len); | 914 | 374 | dst_offset += str_byte_len; | 915 | | } else { | 916 | | memcpy(res_chars.data() + dst_offset, str_data, str_byte_len); | 917 | | dst_offset += str_byte_len; | 918 | | dst_offset += padding->append_to(res_chars.data() + dst_offset, pad_char_count); | 919 | | } | 920 | 374 | res_offsets[row] = dst_offset; | 921 | 374 | } |
_ZN5doris17FunctionStringPadINS_10StringRPadEE17append_result_rowILb0EEEvPKhmiPKNS_12PaddingCharsIXT_EEERNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEERNSA_IjLm4096ESD_Lm16ELm15EEESF_mRm Line | Count | Source | 878 | 2.11k | size_t& dst_offset) { | 879 | 2.11k | if (target_len < 0) { | 880 | 18 | null_map_data[row] = true; | 881 | 18 | res_offsets[row] = dst_offset; | 882 | 18 | return; | 883 | 18 | } | 884 | | | 885 | 2.09k | const size_t str_char_len = get_char_length<is_utf8>(str_data, str_byte_len); | 886 | 2.09k | const size_t target_char_len = static_cast<size_t>(target_len); | 887 | 2.09k | if (str_char_len >= target_char_len) { | 888 | 38 | const size_t truncated_byte_len = get_truncated_byte_length<is_utf8>( | 889 | 38 | str_data, str_byte_len, str_char_len, target_char_len); | 890 | 38 | const size_t needed = dst_offset + truncated_byte_len; | 891 | 38 | ensure_capacity(res_chars, needed, row); | 892 | 38 | memcpy(res_chars.data() + dst_offset, str_data, truncated_byte_len); | 893 | 38 | dst_offset += truncated_byte_len; | 894 | 38 | res_offsets[row] = dst_offset; | 895 | 38 | return; | 896 | 38 | } | 897 | | | 898 | 2.05k | if (padding == nullptr || padding->num_chars() == 0) { | 899 | 0 | res_offsets[row] = dst_offset; | 900 | 0 | return; | 901 | 0 | } | 902 | | | 903 | 2.05k | const size_t pad_char_count = target_char_len - str_char_len; | 904 | 2.05k | const size_t full_cycles = pad_char_count / padding->num_chars(); | 905 | 2.05k | const size_t remainder_chars = pad_char_count % padding->num_chars(); | 906 | 2.05k | const size_t pad_bytes = | 907 | 2.05k | full_cycles * padding->pad_string.size() + padding->chars_to_bytes(remainder_chars); | 908 | 2.05k | const size_t needed = dst_offset + str_byte_len + pad_bytes; | 909 | 2.05k | ensure_capacity(res_chars, needed, row); | 910 | | | 911 | | if constexpr (Impl::is_lpad) { | 912 | | dst_offset += padding->append_to(res_chars.data() + dst_offset, pad_char_count); | 913 | | memcpy(res_chars.data() + dst_offset, str_data, str_byte_len); | 914 | | dst_offset += str_byte_len; | 915 | 2.05k | } else { | 916 | 2.05k | memcpy(res_chars.data() + dst_offset, str_data, str_byte_len); | 917 | 2.05k | dst_offset += str_byte_len; | 918 | 2.05k | dst_offset += padding->append_to(res_chars.data() + dst_offset, pad_char_count); | 919 | 2.05k | } | 920 | 2.05k | res_offsets[row] = dst_offset; | 921 | 2.05k | } |
_ZN5doris17FunctionStringPadINS_10StringRPadEE17append_result_rowILb1EEEvPKhmiPKNS_12PaddingCharsIXT_EEERNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEERNSA_IjLm4096ESD_Lm16ELm15EEESF_mRm Line | Count | Source | 878 | 619 | size_t& dst_offset) { | 879 | 619 | if (target_len < 0) { | 880 | 263 | null_map_data[row] = true; | 881 | 263 | res_offsets[row] = dst_offset; | 882 | 263 | return; | 883 | 263 | } | 884 | | | 885 | 356 | const size_t str_char_len = get_char_length<is_utf8>(str_data, str_byte_len); | 886 | 356 | const size_t target_char_len = static_cast<size_t>(target_len); | 887 | 356 | if (str_char_len >= target_char_len) { | 888 | 277 | const size_t truncated_byte_len = get_truncated_byte_length<is_utf8>( | 889 | 277 | str_data, str_byte_len, str_char_len, target_char_len); | 890 | 277 | const size_t needed = dst_offset + truncated_byte_len; | 891 | 277 | ensure_capacity(res_chars, needed, row); | 892 | 277 | memcpy(res_chars.data() + dst_offset, str_data, truncated_byte_len); | 893 | 277 | dst_offset += truncated_byte_len; | 894 | 277 | res_offsets[row] = dst_offset; | 895 | 277 | return; | 896 | 277 | } | 897 | | | 898 | 79 | if (padding == nullptr || padding->num_chars() == 0) { | 899 | 10 | res_offsets[row] = dst_offset; | 900 | 10 | return; | 901 | 10 | } | 902 | | | 903 | 69 | const size_t pad_char_count = target_char_len - str_char_len; | 904 | 69 | const size_t full_cycles = pad_char_count / padding->num_chars(); | 905 | 69 | const size_t remainder_chars = pad_char_count % padding->num_chars(); | 906 | 69 | const size_t pad_bytes = | 907 | 69 | full_cycles * padding->pad_string.size() + padding->chars_to_bytes(remainder_chars); | 908 | 69 | const size_t needed = dst_offset + str_byte_len + pad_bytes; | 909 | 69 | ensure_capacity(res_chars, needed, row); | 910 | | | 911 | | if constexpr (Impl::is_lpad) { | 912 | | dst_offset += padding->append_to(res_chars.data() + dst_offset, pad_char_count); | 913 | | memcpy(res_chars.data() + dst_offset, str_data, str_byte_len); | 914 | | dst_offset += str_byte_len; | 915 | 69 | } else { | 916 | 69 | memcpy(res_chars.data() + dst_offset, str_data, str_byte_len); | 917 | 69 | dst_offset += str_byte_len; | 918 | 69 | dst_offset += padding->append_to(res_chars.data() + dst_offset, pad_char_count); | 919 | 69 | } | 920 | 69 | res_offsets[row] = dst_offset; | 921 | 69 | } |
|
922 | | |
923 | | template <bool all_ascii, bool str_const> |
924 | | static void execute_const_len_const_pad(const ColumnString& strcol, |
925 | | const ColumnInt32::Container& col_len_data, |
926 | | const ColumnString& padcol, |
927 | | ColumnString::Offsets& res_offsets, |
928 | | ColumnString::Chars& res_chars, |
929 | | ColumnUInt8::Container& null_map_data, |
930 | 140 | size_t input_rows_count) { |
931 | 140 | constexpr bool is_utf8 = !all_ascii; |
932 | 140 | using PadChars = PaddingChars<is_utf8>; |
933 | | |
934 | 140 | const int target_len = col_len_data[0]; |
935 | 140 | std::optional<PadChars> padding; |
936 | 140 | const auto pad = padcol.get_data_at(0); |
937 | 140 | if (!pad.empty()) { |
938 | 110 | padding.emplace(reinterpret_cast<const uint8_t*>(pad.data), pad.size); |
939 | 110 | } |
940 | | |
941 | 140 | const PadChars* padding_ptr = padding ? &*padding : nullptr; |
942 | 140 | const size_t estimated_total = estimate_const_output_bytes<is_utf8>( |
943 | 140 | strcol.get_chars(), target_len, input_rows_count, padding_ptr); |
944 | 140 | if (estimated_total > 0) { |
945 | 44 | ColumnString::check_chars_length(estimated_total, 0, input_rows_count); |
946 | 44 | } |
947 | 140 | res_chars.resize(estimated_total); |
948 | | |
949 | 140 | size_t dst_offset = 0; |
950 | 2.38k | for (size_t i = 0; i < input_rows_count; ++i) { |
951 | 2.24k | auto str = strcol.get_data_at(index_check_const<str_const>(i)); |
952 | 2.24k | append_result_row<is_utf8>(reinterpret_cast<const uint8_t*>(str.data), str.size, |
953 | 2.24k | target_len, padding_ptr, res_chars, res_offsets, |
954 | 2.24k | null_map_data, i, dst_offset); |
955 | 2.24k | } |
956 | 140 | res_chars.resize(dst_offset); |
957 | 140 | } _ZN5doris17FunctionStringPadINS_10StringLPadEE27execute_const_len_const_padILb1ELb0EEEvRKNS_9ColumnStrIjEERKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEES7_RNS8_IjLm4096ESB_Lm16ELm15EEERNS8_IhLm4096ESB_Lm16ELm15EEESI_m Line | Count | Source | 930 | 46 | size_t input_rows_count) { | 931 | 46 | constexpr bool is_utf8 = !all_ascii; | 932 | 46 | using PadChars = PaddingChars<is_utf8>; | 933 | | | 934 | 46 | const int target_len = col_len_data[0]; | 935 | 46 | std::optional<PadChars> padding; | 936 | 46 | const auto pad = padcol.get_data_at(0); | 937 | 46 | if (!pad.empty()) { | 938 | 35 | padding.emplace(reinterpret_cast<const uint8_t*>(pad.data), pad.size); | 939 | 35 | } | 940 | | | 941 | 46 | const PadChars* padding_ptr = padding ? &*padding : nullptr; | 942 | 46 | const size_t estimated_total = estimate_const_output_bytes<is_utf8>( | 943 | 46 | strcol.get_chars(), target_len, input_rows_count, padding_ptr); | 944 | 46 | if (estimated_total > 0) { | 945 | 19 | ColumnString::check_chars_length(estimated_total, 0, input_rows_count); | 946 | 19 | } | 947 | 46 | res_chars.resize(estimated_total); | 948 | | | 949 | 46 | size_t dst_offset = 0; | 950 | 122 | for (size_t i = 0; i < input_rows_count; ++i) { | 951 | 76 | auto str = strcol.get_data_at(index_check_const<str_const>(i)); | 952 | 76 | append_result_row<is_utf8>(reinterpret_cast<const uint8_t*>(str.data), str.size, | 953 | 76 | target_len, padding_ptr, res_chars, res_offsets, | 954 | 76 | null_map_data, i, dst_offset); | 955 | 76 | } | 956 | 46 | res_chars.resize(dst_offset); | 957 | 46 | } |
_ZN5doris17FunctionStringPadINS_10StringLPadEE27execute_const_len_const_padILb0ELb0EEEvRKNS_9ColumnStrIjEERKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEES7_RNS8_IjLm4096ESB_Lm16ELm15EEERNS8_IhLm4096ESB_Lm16ELm15EEESI_m Line | Count | Source | 930 | 27 | size_t input_rows_count) { | 931 | 27 | constexpr bool is_utf8 = !all_ascii; | 932 | 27 | using PadChars = PaddingChars<is_utf8>; | 933 | | | 934 | 27 | const int target_len = col_len_data[0]; | 935 | 27 | std::optional<PadChars> padding; | 936 | 27 | const auto pad = padcol.get_data_at(0); | 937 | 27 | if (!pad.empty()) { | 938 | 23 | padding.emplace(reinterpret_cast<const uint8_t*>(pad.data), pad.size); | 939 | 23 | } | 940 | | | 941 | 27 | const PadChars* padding_ptr = padding ? &*padding : nullptr; | 942 | 27 | const size_t estimated_total = estimate_const_output_bytes<is_utf8>( | 943 | 27 | strcol.get_chars(), target_len, input_rows_count, padding_ptr); | 944 | 27 | if (estimated_total > 0) { | 945 | 6 | ColumnString::check_chars_length(estimated_total, 0, input_rows_count); | 946 | 6 | } | 947 | 27 | res_chars.resize(estimated_total); | 948 | | | 949 | 27 | size_t dst_offset = 0; | 950 | 54 | for (size_t i = 0; i < input_rows_count; ++i) { | 951 | 27 | auto str = strcol.get_data_at(index_check_const<str_const>(i)); | 952 | 27 | append_result_row<is_utf8>(reinterpret_cast<const uint8_t*>(str.data), str.size, | 953 | 27 | target_len, padding_ptr, res_chars, res_offsets, | 954 | 27 | null_map_data, i, dst_offset); | 955 | 27 | } | 956 | 27 | res_chars.resize(dst_offset); | 957 | 27 | } |
Unexecuted instantiation: _ZN5doris17FunctionStringPadINS_10StringLPadEE27execute_const_len_const_padILb1ELb1EEEvRKNS_9ColumnStrIjEERKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEES7_RNS8_IjLm4096ESB_Lm16ELm15EEERNS8_IhLm4096ESB_Lm16ELm15EEESI_m Unexecuted instantiation: _ZN5doris17FunctionStringPadINS_10StringLPadEE27execute_const_len_const_padILb0ELb1EEEvRKNS_9ColumnStrIjEERKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEES7_RNS8_IjLm4096ESB_Lm16ELm15EEERNS8_IhLm4096ESB_Lm16ELm15EEESI_m _ZN5doris17FunctionStringPadINS_10StringRPadEE27execute_const_len_const_padILb1ELb0EEEvRKNS_9ColumnStrIjEERKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEES7_RNS8_IjLm4096ESB_Lm16ELm15EEERNS8_IhLm4096ESB_Lm16ELm15EEESI_m Line | Count | Source | 930 | 39 | size_t input_rows_count) { | 931 | 39 | constexpr bool is_utf8 = !all_ascii; | 932 | 39 | using PadChars = PaddingChars<is_utf8>; | 933 | | | 934 | 39 | const int target_len = col_len_data[0]; | 935 | 39 | std::optional<PadChars> padding; | 936 | 39 | const auto pad = padcol.get_data_at(0); | 937 | 39 | if (!pad.empty()) { | 938 | 28 | padding.emplace(reinterpret_cast<const uint8_t*>(pad.data), pad.size); | 939 | 28 | } | 940 | | | 941 | 39 | const PadChars* padding_ptr = padding ? &*padding : nullptr; | 942 | 39 | const size_t estimated_total = estimate_const_output_bytes<is_utf8>( | 943 | 39 | strcol.get_chars(), target_len, input_rows_count, padding_ptr); | 944 | 39 | if (estimated_total > 0) { | 945 | 12 | ColumnString::check_chars_length(estimated_total, 0, input_rows_count); | 946 | 12 | } | 947 | 39 | res_chars.resize(estimated_total); | 948 | | | 949 | 39 | size_t dst_offset = 0; | 950 | 2.15k | for (size_t i = 0; i < input_rows_count; ++i) { | 951 | 2.11k | auto str = strcol.get_data_at(index_check_const<str_const>(i)); | 952 | 2.11k | append_result_row<is_utf8>(reinterpret_cast<const uint8_t*>(str.data), str.size, | 953 | 2.11k | target_len, padding_ptr, res_chars, res_offsets, | 954 | 2.11k | null_map_data, i, dst_offset); | 955 | 2.11k | } | 956 | 39 | res_chars.resize(dst_offset); | 957 | 39 | } |
_ZN5doris17FunctionStringPadINS_10StringRPadEE27execute_const_len_const_padILb0ELb0EEEvRKNS_9ColumnStrIjEERKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEES7_RNS8_IjLm4096ESB_Lm16ELm15EEERNS8_IhLm4096ESB_Lm16ELm15EEESI_m Line | Count | Source | 930 | 28 | size_t input_rows_count) { | 931 | 28 | constexpr bool is_utf8 = !all_ascii; | 932 | 28 | using PadChars = PaddingChars<is_utf8>; | 933 | | | 934 | 28 | const int target_len = col_len_data[0]; | 935 | 28 | std::optional<PadChars> padding; | 936 | 28 | const auto pad = padcol.get_data_at(0); | 937 | 28 | if (!pad.empty()) { | 938 | 24 | padding.emplace(reinterpret_cast<const uint8_t*>(pad.data), pad.size); | 939 | 24 | } | 940 | | | 941 | 28 | const PadChars* padding_ptr = padding ? &*padding : nullptr; | 942 | 28 | const size_t estimated_total = estimate_const_output_bytes<is_utf8>( | 943 | 28 | strcol.get_chars(), target_len, input_rows_count, padding_ptr); | 944 | 28 | if (estimated_total > 0) { | 945 | 7 | ColumnString::check_chars_length(estimated_total, 0, input_rows_count); | 946 | 7 | } | 947 | 28 | res_chars.resize(estimated_total); | 948 | | | 949 | 28 | size_t dst_offset = 0; | 950 | 56 | for (size_t i = 0; i < input_rows_count; ++i) { | 951 | 28 | auto str = strcol.get_data_at(index_check_const<str_const>(i)); | 952 | 28 | append_result_row<is_utf8>(reinterpret_cast<const uint8_t*>(str.data), str.size, | 953 | 28 | target_len, padding_ptr, res_chars, res_offsets, | 954 | 28 | null_map_data, i, dst_offset); | 955 | 28 | } | 956 | 28 | res_chars.resize(dst_offset); | 957 | 28 | } |
Unexecuted instantiation: _ZN5doris17FunctionStringPadINS_10StringRPadEE27execute_const_len_const_padILb1ELb1EEEvRKNS_9ColumnStrIjEERKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEES7_RNS8_IjLm4096ESB_Lm16ELm15EEERNS8_IhLm4096ESB_Lm16ELm15EEESI_m Unexecuted instantiation: _ZN5doris17FunctionStringPadINS_10StringRPadEE27execute_const_len_const_padILb0ELb1EEEvRKNS_9ColumnStrIjEERKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEES7_RNS8_IjLm4096ESB_Lm16ELm15EEERNS8_IhLm4096ESB_Lm16ELm15EEESI_m |
958 | | |
959 | | template <bool str_const> |
960 | | static void execute_general(const ColumnString& strcol, |
961 | | const ColumnInt32::Container& col_len_data, bool len_const, |
962 | | const ColumnString& padcol, bool pad_const, |
963 | | ColumnString::Offsets& res_offsets, ColumnString::Chars& res_chars, |
964 | 1.23k | ColumnUInt8::Container& null_map_data, size_t input_rows_count) { |
965 | 1.23k | using PadChars = PaddingChars<true>; |
966 | 1.23k | std::optional<PadChars> const_padding; |
967 | 1.23k | const PadChars* const_padding_ptr = nullptr; |
968 | 1.23k | if (pad_const) { |
969 | 248 | auto pad = padcol.get_data_at(0); |
970 | 248 | if (!pad.empty()) { |
971 | 188 | const_padding.emplace(reinterpret_cast<const uint8_t*>(pad.data), pad.size); |
972 | 188 | const_padding_ptr = &*const_padding; |
973 | 188 | } |
974 | 248 | } |
975 | | |
976 | 1.23k | res_chars.resize(strcol.get_chars().size()); |
977 | 1.23k | size_t dst_offset = 0; |
978 | 2.73k | for (size_t i = 0; i < input_rows_count; ++i) { |
979 | 1.49k | auto str = strcol.get_data_at(index_check_const<str_const>(i)); |
980 | 1.49k | const int target_len = col_len_data[len_const ? 0 : i]; |
981 | | |
982 | 1.49k | const PadChars* padding_ptr = const_padding_ptr; |
983 | 1.49k | std::optional<PadChars> row_padding; |
984 | 1.49k | if (!pad_const) { |
985 | 1.24k | auto pad = padcol.get_data_at(i); |
986 | 1.24k | if (!pad.empty()) { |
987 | 1.02k | row_padding.emplace(reinterpret_cast<const uint8_t*>(pad.data), pad.size); |
988 | 1.02k | padding_ptr = &*row_padding; |
989 | 1.02k | } else { |
990 | 228 | padding_ptr = nullptr; |
991 | 228 | } |
992 | 1.24k | } |
993 | | |
994 | 1.49k | append_result_row<true>(reinterpret_cast<const uint8_t*>(str.data), str.size, |
995 | 1.49k | target_len, padding_ptr, res_chars, res_offsets, null_map_data, |
996 | 1.49k | i, dst_offset); |
997 | 1.49k | } |
998 | 1.23k | res_chars.resize(dst_offset); |
999 | 1.23k | } _ZN5doris17FunctionStringPadINS_10StringLPadEE15execute_generalILb0EEEvRKNS_9ColumnStrIjEERKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEbS7_bRNS8_IjLm4096ESB_Lm16ELm15EEERNS8_IhLm4096ESB_Lm16ELm15EEESI_m Line | Count | Source | 964 | 589 | ColumnUInt8::Container& null_map_data, size_t input_rows_count) { | 965 | 589 | using PadChars = PaddingChars<true>; | 966 | 589 | std::optional<PadChars> const_padding; | 967 | 589 | const PadChars* const_padding_ptr = nullptr; | 968 | 589 | if (pad_const) { | 969 | 62 | auto pad = padcol.get_data_at(0); | 970 | 62 | if (!pad.empty()) { | 971 | 47 | const_padding.emplace(reinterpret_cast<const uint8_t*>(pad.data), pad.size); | 972 | 47 | const_padding_ptr = &*const_padding; | 973 | 47 | } | 974 | 62 | } | 975 | | | 976 | 589 | res_chars.resize(strcol.get_chars().size()); | 977 | 589 | size_t dst_offset = 0; | 978 | 1.30k | for (size_t i = 0; i < input_rows_count; ++i) { | 979 | 720 | auto str = strcol.get_data_at(index_check_const<str_const>(i)); | 980 | 720 | const int target_len = col_len_data[len_const ? 0 : i]; | 981 | | | 982 | 720 | const PadChars* padding_ptr = const_padding_ptr; | 983 | 720 | std::optional<PadChars> row_padding; | 984 | 720 | if (!pad_const) { | 985 | 658 | auto pad = padcol.get_data_at(i); | 986 | 658 | if (!pad.empty()) { | 987 | 575 | row_padding.emplace(reinterpret_cast<const uint8_t*>(pad.data), pad.size); | 988 | 575 | padding_ptr = &*row_padding; | 989 | 575 | } else { | 990 | 83 | padding_ptr = nullptr; | 991 | 83 | } | 992 | 658 | } | 993 | | | 994 | 720 | append_result_row<true>(reinterpret_cast<const uint8_t*>(str.data), str.size, | 995 | 720 | target_len, padding_ptr, res_chars, res_offsets, null_map_data, | 996 | 720 | i, dst_offset); | 997 | 720 | } | 998 | 589 | res_chars.resize(dst_offset); | 999 | 589 | } |
_ZN5doris17FunctionStringPadINS_10StringLPadEE15execute_generalILb1EEEvRKNS_9ColumnStrIjEERKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEbS7_bRNS8_IjLm4096ESB_Lm16ELm15EEERNS8_IhLm4096ESB_Lm16ELm15EEESI_m Line | Count | Source | 964 | 186 | ColumnUInt8::Container& null_map_data, size_t input_rows_count) { | 965 | 186 | using PadChars = PaddingChars<true>; | 966 | 186 | std::optional<PadChars> const_padding; | 967 | 186 | const PadChars* const_padding_ptr = nullptr; | 968 | 186 | if (pad_const) { | 969 | 62 | auto pad = padcol.get_data_at(0); | 970 | 62 | if (!pad.empty()) { | 971 | 47 | const_padding.emplace(reinterpret_cast<const uint8_t*>(pad.data), pad.size); | 972 | 47 | const_padding_ptr = &*const_padding; | 973 | 47 | } | 974 | 62 | } | 975 | | | 976 | 186 | res_chars.resize(strcol.get_chars().size()); | 977 | 186 | size_t dst_offset = 0; | 978 | 372 | for (size_t i = 0; i < input_rows_count; ++i) { | 979 | 186 | auto str = strcol.get_data_at(index_check_const<str_const>(i)); | 980 | 186 | const int target_len = col_len_data[len_const ? 0 : i]; | 981 | | | 982 | 186 | const PadChars* padding_ptr = const_padding_ptr; | 983 | 186 | std::optional<PadChars> row_padding; | 984 | 186 | if (!pad_const) { | 985 | 124 | auto pad = padcol.get_data_at(i); | 986 | 124 | if (!pad.empty()) { | 987 | 94 | row_padding.emplace(reinterpret_cast<const uint8_t*>(pad.data), pad.size); | 988 | 94 | padding_ptr = &*row_padding; | 989 | 94 | } else { | 990 | 30 | padding_ptr = nullptr; | 991 | 30 | } | 992 | 124 | } | 993 | | | 994 | 186 | append_result_row<true>(reinterpret_cast<const uint8_t*>(str.data), str.size, | 995 | 186 | target_len, padding_ptr, res_chars, res_offsets, null_map_data, | 996 | 186 | i, dst_offset); | 997 | 186 | } | 998 | 186 | res_chars.resize(dst_offset); | 999 | 186 | } |
_ZN5doris17FunctionStringPadINS_10StringRPadEE15execute_generalILb0EEEvRKNS_9ColumnStrIjEERKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEbS7_bRNS8_IjLm4096ESB_Lm16ELm15EEERNS8_IhLm4096ESB_Lm16ELm15EEESI_m Line | Count | Source | 964 | 275 | ColumnUInt8::Container& null_map_data, size_t input_rows_count) { | 965 | 275 | using PadChars = PaddingChars<true>; | 966 | 275 | std::optional<PadChars> const_padding; | 967 | 275 | const PadChars* const_padding_ptr = nullptr; | 968 | 275 | if (pad_const) { | 969 | 62 | auto pad = padcol.get_data_at(0); | 970 | 62 | if (!pad.empty()) { | 971 | 47 | const_padding.emplace(reinterpret_cast<const uint8_t*>(pad.data), pad.size); | 972 | 47 | const_padding_ptr = &*const_padding; | 973 | 47 | } | 974 | 62 | } | 975 | | | 976 | 275 | res_chars.resize(strcol.get_chars().size()); | 977 | 275 | size_t dst_offset = 0; | 978 | 680 | for (size_t i = 0; i < input_rows_count; ++i) { | 979 | 405 | auto str = strcol.get_data_at(index_check_const<str_const>(i)); | 980 | 405 | const int target_len = col_len_data[len_const ? 0 : i]; | 981 | | | 982 | 405 | const PadChars* padding_ptr = const_padding_ptr; | 983 | 405 | std::optional<PadChars> row_padding; | 984 | 405 | if (!pad_const) { | 985 | 343 | auto pad = padcol.get_data_at(i); | 986 | 343 | if (!pad.empty()) { | 987 | 258 | row_padding.emplace(reinterpret_cast<const uint8_t*>(pad.data), pad.size); | 988 | 258 | padding_ptr = &*row_padding; | 989 | 258 | } else { | 990 | 85 | padding_ptr = nullptr; | 991 | 85 | } | 992 | 343 | } | 993 | | | 994 | 405 | append_result_row<true>(reinterpret_cast<const uint8_t*>(str.data), str.size, | 995 | 405 | target_len, padding_ptr, res_chars, res_offsets, null_map_data, | 996 | 405 | i, dst_offset); | 997 | 405 | } | 998 | 275 | res_chars.resize(dst_offset); | 999 | 275 | } |
_ZN5doris17FunctionStringPadINS_10StringRPadEE15execute_generalILb1EEEvRKNS_9ColumnStrIjEERKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEbS7_bRNS8_IjLm4096ESB_Lm16ELm15EEERNS8_IhLm4096ESB_Lm16ELm15EEESI_m Line | Count | Source | 964 | 186 | ColumnUInt8::Container& null_map_data, size_t input_rows_count) { | 965 | 186 | using PadChars = PaddingChars<true>; | 966 | 186 | std::optional<PadChars> const_padding; | 967 | 186 | const PadChars* const_padding_ptr = nullptr; | 968 | 186 | if (pad_const) { | 969 | 62 | auto pad = padcol.get_data_at(0); | 970 | 62 | if (!pad.empty()) { | 971 | 47 | const_padding.emplace(reinterpret_cast<const uint8_t*>(pad.data), pad.size); | 972 | 47 | const_padding_ptr = &*const_padding; | 973 | 47 | } | 974 | 62 | } | 975 | | | 976 | 186 | res_chars.resize(strcol.get_chars().size()); | 977 | 186 | size_t dst_offset = 0; | 978 | 372 | for (size_t i = 0; i < input_rows_count; ++i) { | 979 | 186 | auto str = strcol.get_data_at(index_check_const<str_const>(i)); | 980 | 186 | const int target_len = col_len_data[len_const ? 0 : i]; | 981 | | | 982 | 186 | const PadChars* padding_ptr = const_padding_ptr; | 983 | 186 | std::optional<PadChars> row_padding; | 984 | 186 | if (!pad_const) { | 985 | 124 | auto pad = padcol.get_data_at(i); | 986 | 124 | if (!pad.empty()) { | 987 | 94 | row_padding.emplace(reinterpret_cast<const uint8_t*>(pad.data), pad.size); | 988 | 94 | padding_ptr = &*row_padding; | 989 | 94 | } else { | 990 | 30 | padding_ptr = nullptr; | 991 | 30 | } | 992 | 124 | } | 993 | | | 994 | 186 | append_result_row<true>(reinterpret_cast<const uint8_t*>(str.data), str.size, | 995 | 186 | target_len, padding_ptr, res_chars, res_offsets, null_map_data, | 996 | 186 | i, dst_offset); | 997 | 186 | } | 998 | 186 | res_chars.resize(dst_offset); | 999 | 186 | } |
|
1000 | | }; |
1001 | | |
1002 | | #include "common/compile_check_avoid_end.h" |
1003 | | } // namespace doris |