This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 873fbfba56c [refactor](opt) merge BE function code of array_popback() and array_popfront() (#41985) 873fbfba56c is described below commit 873fbfba56c19e02c12ae4e2b2947409fc746b1f Author: Chester <cheste...@tencent.com> AuthorDate: Sat Oct 19 17:37:36 2024 +0800 [refactor](opt) merge BE function code of array_popback() and array_popfront() (#41985) ## Proposed changes Issue Number: close #xxx <!--Describe your changes.--> Since the code of **array_popback()** and **array_popfront()** is almost the same, we extracted the common logic into a class `FunctionArrayPop()` and made `FunctionArrayPopback()` and `FunctionArrayPopfront()` derive from it. As a result, these two parts of the BE function code are simplified, while their implementation remains unchanged. --- ...on_array_popback.cpp => function_array_pop.cpp} | 29 ++++-- .../functions/array/function_array_popfront.cpp | 100 --------------------- .../functions/array/function_array_register.cpp | 6 +- 3 files changed, 23 insertions(+), 112 deletions(-) diff --git a/be/src/vec/functions/array/function_array_popback.cpp b/be/src/vec/functions/array/function_array_pop.cpp similarity index 81% rename from be/src/vec/functions/array/function_array_popback.cpp rename to be/src/vec/functions/array/function_array_pop.cpp index dc1f7818292..f9b5c161ae1 100644 --- a/be/src/vec/functions/array/function_array_popback.cpp +++ b/be/src/vec/functions/array/function_array_pop.cpp @@ -43,13 +43,13 @@ class FunctionContext; namespace doris::vectorized { -class FunctionArrayPopback : public IFunction { +template <typename PopType> +class FunctionArrayPop : public IFunction { public: - static constexpr auto name = "array_popback"; - static FunctionPtr create() { return std::make_shared<FunctionArrayPopback>(); } + static FunctionPtr create() { return std::make_shared<PopType>(); } /// Get function name. - String get_name() const override { return name; } + String get_name() const override { return PopType::name; } bool is_variadic() const override { return false; } @@ -57,7 +57,7 @@ public: DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { DCHECK(is_array(arguments[0])) - << "First argument for function: " << name + << "First argument for function: " << PopType::name << " should be DataTypeArray but it has type " << arguments[0]->get_name() << "."; return arguments[0]; } @@ -77,8 +77,8 @@ public: bool is_nullable = src.nested_nullmap_data != nullptr; ColumnArrayMutableData dst = create_mutable_data(src.nested_col, is_nullable); dst.offsets_ptr->reserve(input_rows_count); - // start from 1 - auto offset_column = ColumnInt64::create(array_column->size(), 1); + // start from index depending on the PopType::start_offset + auto offset_column = ColumnInt64::create(array_column->size(), PopType::start_offset); // len - 1 auto length_column = ColumnInt64::create(); for (size_t row = 0; row < src.offsets_ptr->size(); ++row) { @@ -93,8 +93,21 @@ public: } }; -void register_function_array_popback(SimpleFunctionFactory& factory) { +class FunctionArrayPopback : public FunctionArrayPop<FunctionArrayPopback> { +public: + static constexpr auto name = "array_popback"; + static constexpr int start_offset = 1; +}; + +class FunctionArrayPopfront : public FunctionArrayPop<FunctionArrayPopfront> { +public: + static constexpr auto name = "array_popfront"; + static constexpr int start_offset = 2; +}; + +void register_function_array_pop(SimpleFunctionFactory& factory) { factory.register_function<FunctionArrayPopback>(); + factory.register_function<FunctionArrayPopfront>(); } } // namespace doris::vectorized diff --git a/be/src/vec/functions/array/function_array_popfront.cpp b/be/src/vec/functions/array/function_array_popfront.cpp deleted file mode 100644 index 3c879999055..00000000000 --- a/be/src/vec/functions/array/function_array_popfront.cpp +++ /dev/null @@ -1,100 +0,0 @@ -// 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 <fmt/format.h> -#include <glog/logging.h> -#include <stddef.h> - -#include <memory> -#include <ostream> -#include <string> -#include <utility> - -#include "common/status.h" -#include "vec/aggregate_functions/aggregate_function.h" -#include "vec/columns/column.h" -#include "vec/columns/column_vector.h" -#include "vec/columns/columns_number.h" -#include "vec/core/block.h" -#include "vec/core/column_numbers.h" -#include "vec/core/column_with_type_and_name.h" -#include "vec/core/types.h" -#include "vec/data_types/data_type.h" -#include "vec/functions/array/function_array_utils.h" -#include "vec/functions/function.h" -#include "vec/functions/simple_function_factory.h" - -namespace doris { -class FunctionContext; -} // namespace doris - -namespace doris::vectorized { - -class FunctionArrayPopfront : public IFunction { -public: - static constexpr auto name = "array_popfront"; - static FunctionPtr create() { return std::make_shared<FunctionArrayPopfront>(); } - - /// Get function name. - String get_name() const override { return name; } - - bool is_variadic() const override { return false; } - - size_t get_number_of_arguments() const override { return 1; } - - DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { - DCHECK(is_array(arguments[0])) - << "First argument for function: " << name - << " should be DataTypeArray but it has type " << arguments[0]->get_name() << "."; - return arguments[0]; - } - - Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, - size_t result, size_t input_rows_count) const override { - auto array_column = - block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); - // extract src array column - ColumnArrayExecutionData src; - if (!extract_column_array_info(*array_column, src)) { - return Status::RuntimeError( - fmt::format("execute failed, unsupported types for function {}({})", get_name(), - block.get_by_position(arguments[0]).type->get_name())); - } - // prepare dst array column - bool is_nullable = src.nested_nullmap_data ? true : false; - ColumnArrayMutableData dst = create_mutable_data(src.nested_col, is_nullable); - dst.offsets_ptr->reserve(input_rows_count); - // start from 2 - auto offset_column = ColumnInt64::create(array_column->size(), 2); - // len - 1 - auto length_column = ColumnInt64::create(); - for (size_t row = 0; row < src.offsets_ptr->size(); ++row) { - size_t off = (*src.offsets_ptr)[row - 1]; - size_t len = (*src.offsets_ptr)[row] - off; - length_column->insert_value(len - 1); - } - slice_array(dst, src, *offset_column, length_column.get()); - ColumnPtr res_column = assemble_column_array(dst); - block.replace_by_position(result, std::move(res_column)); - return Status::OK(); - } -}; - -void register_function_array_popfront(SimpleFunctionFactory& factory) { - factory.register_function<FunctionArrayPopfront>(); -} - -} // namespace doris::vectorized diff --git a/be/src/vec/functions/array/function_array_register.cpp b/be/src/vec/functions/array/function_array_register.cpp index 7b4103c54df..8d5428710a4 100644 --- a/be/src/vec/functions/array/function_array_register.cpp +++ b/be/src/vec/functions/array/function_array_register.cpp @@ -42,8 +42,7 @@ void register_function_array_enumerate(SimpleFunctionFactory&); void register_function_array_enumerate_uniq(SimpleFunctionFactory&); void register_function_array_range(SimpleFunctionFactory&); void register_function_array_compact(SimpleFunctionFactory&); -void register_function_array_popback(SimpleFunctionFactory&); -void register_function_array_popfront(SimpleFunctionFactory&); +void register_function_array_pop(SimpleFunctionFactory&); void register_function_array_with_constant(SimpleFunctionFactory&); void register_function_array_constructor(SimpleFunctionFactory&); void register_function_array_apply(SimpleFunctionFactory&); @@ -80,8 +79,7 @@ void register_function_array(SimpleFunctionFactory& factory) { register_function_array_enumerate_uniq(factory); register_function_array_range(factory); register_function_array_compact(factory); - register_function_array_popback(factory); - register_function_array_popfront(factory); + register_function_array_pop(factory); register_function_array_with_constant(factory); register_function_array_constructor(factory); register_function_array_apply(factory); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org