eldenmoon commented on code in PR #17436: URL: https://github.com/apache/doris/pull/17436#discussion_r1125696675
########## be/src/vec/functions/array/function_array_concat.cpp: ########## @@ -0,0 +1,84 @@ +// 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(); Review Comment: we could do `reserve` for result_nested_col for more efficiency ########## be/src/vec/functions/array/function_array_concat.cpp: ########## @@ -0,0 +1,84 @@ +// Licensed to the Apache Software Foundation (ASF) under one Review Comment: also need add this doc to sidebar `docs/sidebars.json` ########## regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions_by_literal.groovy: ########## @@ -223,6 +223,14 @@ suite("test_array_functions_by_literal") { qt_sql """select array_apply(array(cast (24.99 as decimal(10,3)),cast (25.99 as decimal(10,3))), ">", '25')""" qt_sql """select array_apply(array(cast (24.99 as decimal(10,3)),cast (25.99 as decimal(10,3))), "!=", '25.99')""" + qt_sql "select array_concat([1, 2, 3], [2, 3, 4], [8, 1, 2], [9])" + qt_sql "select array_concat([12, 23], [25, null], [null], [66])" + qt_sql "select array_concat([1.2, 1.8], [9.0, 2.2], [2.8])" + qt_sql "select array_concat(['aaa', null], ['bbb', 'fff'], [null, 'ccc'])" Review Comment: add a null case like array_concat(null, [1, 2, 3], null) -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
