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