BiteTheDDDDt commented on code in PR #13408: URL: https://github.com/apache/doris/pull/13408#discussion_r996643820
########## be/src/vec/functions/function_string.h: ########## @@ -758,51 +758,100 @@ class FunctionStringRepeat : public IFunction { size_t get_number_of_arguments() const override { return 2; } DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { - return std::make_shared<DataTypeString>(); + return make_nullable(std::make_shared<DataTypeString>()); } bool use_default_implementation_for_constants() const override { return true; } Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, size_t result, size_t input_rows_count) override { DCHECK_EQ(arguments.size(), 2); auto res = ColumnString::create(); + auto null_map = ColumnUInt8::create(); ColumnPtr argument_ptr[2]; argument_ptr[0] = block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); - argument_ptr[1] = - block.get_by_position(arguments[1]).column->convert_to_full_column_if_const(); + argument_ptr[1] = block.get_by_position(arguments[1]).column; if (auto* col1 = check_and_get_column<ColumnString>(*argument_ptr[0])) { if (auto* col2 = check_and_get_column<ColumnInt32>(*argument_ptr[1])) { vector_vector(col1->get_chars(), col1->get_offsets(), col2->get_data(), - res->get_chars(), res->get_offsets()); - block.replace_by_position(result, std::move(res)); + res->get_chars(), res->get_offsets(), null_map->get_data()); + block.replace_by_position( + result, ColumnNullable::create(std::move(res), std::move(null_map))); + return Status::OK(); + } else if (auto* col2_const = check_and_get_column<ColumnConst>(*argument_ptr[1])) { + DCHECK(check_and_get_column<ColumnInt32>(col2_const->get_data_column())); + int repeat = col2_const->get_int(0); + if (repeat <= 0) { + null_map->get_data().resize_fill(input_rows_count, 0); + res->insert_many_defaults(input_rows_count); + } else { + vector_const(col1->get_chars(), col1->get_offsets(), repeat, res->get_chars(), + res->get_offsets(), null_map->get_data()); + } + block.replace_by_position( + result, ColumnNullable::create(std::move(res), std::move(null_map))); return Status::OK(); } } - return Status::RuntimeError("not support {}", get_name()); + return Status::RuntimeError("repeat function get error param: {}, {}", + argument_ptr[0]->get_name(), argument_ptr[1]->get_name()); } void vector_vector(const ColumnString::Chars& data, const ColumnString::Offsets& offsets, const ColumnInt32::Container& repeats, ColumnString::Chars& res_data, - ColumnString::Offsets& res_offsets) { + ColumnString::Offsets& res_offsets, ColumnUInt8::Container& null_map) { size_t input_row_size = offsets.size(); - // + fmt::memory_buffer buffer; res_offsets.resize(input_row_size); + null_map.resize_fill(input_row_size, 0); for (ssize_t i = 0; i < input_row_size; ++i) { buffer.clear(); const char* raw_str = reinterpret_cast<const char*>(&data[offsets[i - 1]]); int size = offsets[i] - offsets[i - 1]; int repeat = repeats[i]; - // assert size * repeat won't exceed - DCHECK_LE(static_cast<int64_t>(size) * repeat, std::numeric_limits<int32_t>::max()); - for (int i = 0; i < repeat; ++i) { - buffer.append(raw_str, raw_str + size); + + if (repeat <= 0) { + StringOP::push_empty_string(i, res_data, res_offsets); + } else if (repeat * size > DEFAULT_MAX_STRING_SIZE) { Review Comment: Maybe we need to handle the case of overflowing INT_MAX -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org