cambyzju commented on code in PR #10749: URL: https://github.com/apache/doris/pull/10749#discussion_r917586621
########## be/src/vec/functions/function_string.h: ########## @@ -553,6 +563,122 @@ class FunctionStringConcatWs : public IFunction { fmt::memory_buffer buffer; std::vector<std::string_view> views; + DataTypePtr array_column_type = + check_column<ColumnArray>(*argument_columns[1].get()) + ? remove_nullable(block.get_by_position(arguments[1]).type) + : nullptr; + if (array_column_type) { + // Determine if the nested type of the array is String + auto array_nested_type = remove_nullable( + assert_cast<const DataTypeArray&>(*array_column_type).get_nested_type()); + if (!is_string(array_nested_type)) { + return Status::NotSupported( + fmt::format("unsupported nested array of type {} for function {}", + array_nested_type->get_name(), get_name())); + } + // Concat string in array + _execute_array(input_rows_count, argument_columns, buffer, views, offsets_list, + chars_list, null_list, res_data, res_offset); + + } else { + // Concat string + _execute_string(input_rows_count, argument_size, buffer, views, offsets_list, + chars_list, null_list, res_data, res_offset); + } + if (is_null_type) { + block.get_by_position(result).column = + ColumnNullable::create(std::move(res), std::move(null_map)); + } else { + block.get_by_position(result).column = std::move(res); + } + return Status::OK(); + } + +private: + void _execute_array(const size_t& input_rows_count, const ColumnPtr* argument_columns, + fmt::memory_buffer& buffer, std::vector<std::string_view>& views, + const std::vector<const ColumnString::Offsets*>& offsets_list, + const std::vector<const ColumnString::Chars*>& chars_list, + const std::vector<const ColumnUInt8::Container*>& null_list, + Chars& res_data, Offsets& res_offset) { + // Get array nested column + bool array_nested_type_is_nullable = false; + const UInt8* array_nested_null_map = nullptr; + ColumnPtr array_nested_column = nullptr; + const auto& array_column = reinterpret_cast<const ColumnArray&>(*argument_columns[1]); + + if (is_column_nullable(array_column.get_data())) { + const auto& array_nested_null_column = + reinterpret_cast<const ColumnNullable&>(array_column.get_data()); + // String's null map in array + array_nested_null_map = + array_nested_null_column.get_null_map_column().get_data().data(); + array_nested_column = array_nested_null_column.get_nested_column_ptr(); + } else { + array_nested_type_is_nullable = true; + array_nested_column = array_column.get_data_ptr(); + } + + auto const_array_nested_null_map = ColumnUInt8::create(array_nested_column->size(), 0); + if (array_nested_type_is_nullable) { + array_nested_null_map = const_array_nested_null_map->get_data().data(); + } + + const auto& string_column = reinterpret_cast<const ColumnString&>(*array_nested_column); + const ColumnString::Chars& string_src_chars = string_column.get_chars(); + const ColumnString::Offsets& src_string_offsets = string_column.get_offsets(); + const ColumnArray::Offsets& src_array_offsets = array_column.get_offsets(); + ColumnArray::Offset current_src_array_offset = 0; + + // Concat string in array + for (size_t i = 0; i < input_rows_count; ++i) { + auto& seq_offsets = *offsets_list[0]; + auto& seq_chars = *chars_list[0]; + auto& seq_nullmap = *null_list[0]; + + if (seq_nullmap[i]) { + res_data.push_back('\0'); Review Comment: no need to append zero -- 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