zclllyybb commented on code in PR #48994: URL: https://github.com/apache/doris/pull/48994#discussion_r2009213622
########## be/src/vec/exprs/lambda_function/varray_reduce_function.cpp: ########## @@ -0,0 +1,309 @@ +// 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/core.h> + +#include <memory> +#include <string> +#include <utility> +#include <vector> + +#include "common/status.h" +#include "vec/aggregate_functions/aggregate_function.h" +#include "vec/columns/column.h" +#include "vec/columns/column_array.h" +#include "vec/columns/column_nullable.h" +#include "vec/common/assert_cast.h" +#include "vec/core/block.h" +#include "vec/core/column_numbers.h" +#include "vec/core/column_with_type_and_name.h" +#include "vec/data_types/data_type_array.h" +#include "vec/data_types/data_type_nullable.h" +#include "vec/exprs/lambda_function/lambda_function.h" +#include "vec/exprs/lambda_function/lambda_function_factory.h" +#include "vec/exprs/vcolumn_ref.h" +#include "vec/exprs/vslot_ref.h" +#include "vec/functions/array/function_array_utils.h" +#include "vec/functions/function.h" + +namespace doris::vectorized { +#include "common/compile_check_begin.h" +class VExprContext; + +// extend a block with all required parameters +struct ReduceLambdaArgs { + // the lambda function need the column ids of all the slots + std::vector<int> output_slot_ref_indexs; + // which line is extended to the original block + int64_t current_row_idx = 0; + // the size of the current array + int64_t cur_size = 0; + // offset of column array + const ColumnArray::Offsets64* offsets_ptr = nullptr; +}; + +class ArrayReduceFunction : public LambdaFunction { + ENABLE_FACTORY_CREATOR(ArrayReduceFunction); + +public: + ~ArrayReduceFunction() override = default; + + static constexpr auto name = "array_reduce"; + + static LambdaFunctionPtr create() { return std::make_shared<ArrayReduceFunction>(); } + + std::string get_name() const override { return name; } + + doris::Status execute(VExprContext* context, doris::vectorized::Block* block, + int* result_column_id, const DataTypePtr& result_type, + const VExprSPtrs& children) override { + ReduceLambdaArgs args; + // collect used slot ref in lambda function body + _collect_slot_ref_column_id(children[0], args); Review Comment: > I have a question, I am confused in which case there would be a slot ref column, can you give me a short explanation? I reuse the code from varray_map_function.cpp, but all cases I can imagine the slot_ref_column result is empty. try to reference a column name instead of lambda argument like `select array_map(x->(x+k0), k1) from arr;` -- 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