eldenmoon commented on code in PR #17436: URL: https://github.com/apache/doris/pull/17436#discussion_r1125868175
########## be/src/vec/functions/array/function_array_concat.cpp: ########## @@ -0,0 +1,93 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include <cstddef> + +#include "vec/columns/column_array.h" +#include "vec/data_types/data_type_array.h" +#include "vec/functions/function.h" +#include "vec/functions/simple_function_factory.h" + +namespace doris::vectorized { + +// array_concat([1, 2], [7, 8], [5, 6]) -> [1, 2, 7, 8, 5, 6] +class FunctionArrayConcat : public IFunction { +public: + static constexpr auto name = "array_concat"; + + static FunctionPtr create() { return std::make_shared<FunctionArrayConcat>(); } + + String get_name() const override { return name; } + + bool is_variadic() const override { return true; } + + size_t get_number_of_arguments() const override { return 1; } + + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { + DCHECK(arguments.size() > 0) + << "function: " << get_name() << ", arguments should not be empty"; + for (const auto& arg : arguments) { + DCHECK(is_array(arg)) << "argument for function array_concat should be DataTypeArray" + << " and argument is " << arg->get_name(); + } + return arguments[0]; + } + + Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, + const size_t result, size_t input_rows_count) override { + DataTypePtr column_type = block.get_by_position(arguments[0]).type; + auto nested_type = assert_cast<const DataTypeArray&>(*column_type).get_nested_type(); + auto result_column = ColumnArray::create(nested_type->create_column(), + ColumnArray::ColumnOffsets::create()); + IColumn& result_nested_col = result_column->get_data(); + ColumnArray::Offsets64& column_offsets = result_column->get_offsets(); + column_offsets.resize(input_rows_count); + + size_t total_size = 0; + for (size_t col : arguments) { + ColumnPtr src_column = + block.get_by_position(col).column->convert_to_full_column_if_const(); + const auto& src_column_array = check_and_get_column<ColumnArray>(*src_column); Review Comment: we should get the nested column of array, and caculate it's size, other wise, it's the row size of array not the inner nested row size of the array. -- 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