HappenLee commented on code in PR #34258: URL: https://github.com/apache/doris/pull/34258#discussion_r1701361681
########## be/src/vec/functions/function_string.h: ########## @@ -386,6 +389,204 @@ class FunctionStrcmp : public IFunction { } }; +class FunctionAutoPartitionName : public IFunction { +public: + static constexpr auto name = "auto_partition_name"; + static FunctionPtr create() { return std::make_shared<FunctionAutoPartitionName>(); } + String get_name() const override { return name; } + size_t get_number_of_arguments() const override { return 0; } + bool is_variadic() const override { return true; } + + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { + return std::make_shared<DataTypeString>(); + } + + Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, + size_t result, size_t input_rows_count) const override { + int argument_size = arguments.size(); + if (argument_size < 2) { + return Status::InvalidArgument( + "auto_partition_name must contains at least two arguments"); + } + std::vector<const ColumnString::Chars*> chars_list(argument_size); + std::vector<const ColumnString::Offsets*> offsets_list(argument_size); + std::vector<bool> is_const_args(argument_size); + + for (int i = 0; i < argument_size; ++i) { + const auto& [col, is_const] = + unpack_if_const(block.get_by_position(arguments[i]).column); + + const auto* col_str = assert_cast<const ColumnString*>(col.get()); + chars_list[i] = &col_str->get_chars(); + offsets_list[i] = &col_str->get_offsets(); + is_const_args[i] = is_const; + } + auto res = ColumnString::create(); + auto& res_data = res->get_chars(); + auto& res_offset = res->get_offsets(); + res_offset.resize(input_rows_count); + + const char* partition_type = chars_list[0]->raw_data(); + // partition type is list|range + if (std::strncmp(partition_type, "list", 4) == 0) { + int curr_len = 0; + for (int row = 0; row < input_rows_count; row++) { + std::string res_p = "p"; + for (int col = 1; col < argument_size; col++) { + const auto& current_offsets = *offsets_list[col]; + const auto& current_chars = *chars_list[col]; + + auto idx = index_check_const(row, is_const_args[col]); + int size = current_offsets[idx] - current_offsets[idx - 1]; + const char* raw_chars = + reinterpret_cast<const char*>(¤t_chars[current_offsets[idx - 1]]); + + // convert string to u16string in order to convert to unicode strings + const std::string raw_str(raw_chars, size); + auto u16string = _string_to_u16string(raw_str); + res_p += _string_to_unicode(u16string) + std::to_string(u16string.size()); + } + + // check the name of length + int len = res_p.size(); + if (len > 50) [[unlikely]] { + return Status::InvalidArgument( + "The list partition name cannot exceed 50 characters"); + } + curr_len += len; + res_data.resize(curr_len); + memcpy(&res_data[res_offset[row - 1]], res_p.c_str(), len); + res_offset[row] = res_offset[row - 1] + len; + } + } else { + const char* range_type = chars_list[1]->raw_data(); + + res_data.resize(15 * input_rows_count); + for (int i = 0; i < input_rows_count; i++) { + const auto& current_offsets = *offsets_list[2]; + const auto& current_chars = *chars_list[2]; + + auto idx = index_check_const(i, is_const_args[2]); + int size = current_offsets[idx] - current_offsets[idx - 1]; + const char* tmp = + reinterpret_cast<const char*>(¤t_chars[current_offsets[idx - 1]]); + std::string to_split_s(tmp, size); + + // check the str if it is date|datetime + std::regex dateRegex(R"(^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}:\d{2})?$)"); Review Comment: `date_regex` why use re2 -- 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