be/src/exprs/aggregate/aggregate_function_foreach.cpp
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | // This file is copied from |
18 | | // https://github.com/ClickHouse/ClickHouse/blob/master/src/AggregateFunctions/Combinators/AggregateFunctionForEach.cpp |
19 | | // and modified by Doris |
20 | | |
21 | | #include "exprs/aggregate/aggregate_function_foreach.h" |
22 | | |
23 | | #include <memory> |
24 | | |
25 | | #include "core/data_type/data_type_array.h" |
26 | | #include "core/data_type/data_type_nullable.h" |
27 | | #include "exprs/aggregate/aggregate_function.h" |
28 | | #include "exprs/aggregate/aggregate_function_simple_factory.h" |
29 | | #include "exprs/aggregate/helpers.h" |
30 | | |
31 | | namespace doris { |
32 | | #include "common/compile_check_begin.h" |
33 | | |
34 | 1 | void register_aggregate_function_combinator_foreach(AggregateFunctionSimpleFactory& factory) { |
35 | 1 | AggregateFunctionCreator creator = |
36 | 1 | [&](const std::string& name, const DataTypes& types, const DataTypePtr& result_type, |
37 | 1 | const bool result_is_nullable, |
38 | 2 | const AggregateFunctionAttr& attr) -> AggregateFunctionPtr { |
39 | 2 | const std::string& suffix = AggregateFunctionForEach::AGG_FOREACH_SUFFIX; |
40 | 2 | DataTypes transform_arguments; |
41 | 2 | for (const auto& t : types) { |
42 | 2 | auto item_type = |
43 | 2 | assert_cast<const DataTypeArray*>(remove_nullable(t).get())->get_nested_type(); |
44 | 2 | transform_arguments.push_back((item_type)); |
45 | 2 | } |
46 | 2 | auto result_item_type = |
47 | 2 | assert_cast<const DataTypeArray*>(remove_nullable(result_type).get()) |
48 | 2 | ->get_nested_type(); |
49 | 2 | auto nested_function_name = name.substr(0, name.size() - suffix.size()); |
50 | 2 | auto nested_function = |
51 | 2 | factory.get(nested_function_name, transform_arguments, result_item_type, |
52 | 2 | result_is_nullable, BeExecVersionManager::get_newest_version(), attr); |
53 | 2 | if (!nested_function) { |
54 | 0 | throw Exception( |
55 | 0 | ErrorCode::INTERNAL_ERROR, |
56 | 0 | "The combiner did not find a foreach combiner function. nested function " |
57 | 0 | "name {} , args {}", |
58 | 0 | nested_function_name, types_name(types)); |
59 | 0 | } |
60 | 2 | return creator_without_type::create<AggregateFunctionForEach>(types, true, attr, |
61 | 2 | nested_function); |
62 | 2 | }; |
63 | 1 | factory.register_foreach_function_combinator( |
64 | 1 | creator, AggregateFunctionForEach::AGG_FOREACH_SUFFIX, true); |
65 | 1 | factory.register_foreach_function_combinator( |
66 | 1 | creator, AggregateFunctionForEach::AGG_FOREACH_SUFFIX, false); |
67 | 1 | } |
68 | | } // namespace doris |