Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.9k
[feature](nereids) support multi_distinct_collect_list and multi_distinct_array_agg#65245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -17,6 +17,7 @@ | ||
| #include "exprs/aggregate/aggregate_function_array_agg.h" | ||
| #include "common/exception.h" | ||
| #include "core/call_on_type_index.h" | ||
| #include "exprs/aggregate/aggregate_function_collect.h" | ||
| #include "exprs/aggregate/aggregate_function_simple_factory.h" | ||
| @@ -25,17 +26,37 @@ | ||
| namespace doris { | ||
| template <PrimitiveType T> | ||
| AggregateFunctionPtr do_create_agg_function_collect(const DataTypes& argument_types, | ||
| AggregateFunctionPtr do_create_agg_function_collect(bool distinct, const std::string& name, | ||
| const DataTypes& argument_types, | ||
| const bool result_is_nullable, | ||
Baymine marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| const AggregateFunctionAttr& attr) { | ||
| if (distinct) { | ||
| if constexpr (T == INVALID_TYPE) { | ||
Baymine marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| throw Exception(ErrorCode::INTERNAL_ERROR, | ||
| "unexpected type for array_agg distinct, please check the input"); | ||
| } else { | ||
| // array_agg keeps NULL elements, so multi_distinct_array_agg must preserve a single | ||
| // NULL when the input contains nulls. Feed the nullable column straight to the | ||
| // aggregate (create_ignore_nullable, no null-skipping wrapper) and let the ShowNull | ||
| // collect function record whether a null was seen; the Set still dedups the values. | ||
| if (argument_types[0]->is_nullable()) { | ||
| return creator_without_type::create_ignore_nullable<AggregateFunctionCollect< | ||
| AggregateFunctionCollectSetData<T, false>, false, true>>( | ||
| argument_types, result_is_nullable, attr, name); | ||
| } | ||
| return creator_without_type::create< | ||
Baymine marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| AggregateFunctionCollect<AggregateFunctionCollectSetData<T, false>, false>>( | ||
| argument_types, result_is_nullable, attr, name); | ||
| } | ||
| } | ||
| if (argument_types[0]->is_nullable()) { | ||
| return creator_without_type::create_ignore_nullable< | ||
| AggregateFunctionArrayAgg<AggregateFunctionArrayAggData<T>>>( | ||
| argument_types, result_is_nullable, attr); | ||
| } else { | ||
| return creator_without_type::create< | ||
| AggregateFunctionCollect<AggregateFunctionCollectListData<T, false>, false>>( | ||
| argument_types, result_is_nullable, attr); | ||
| argument_types, result_is_nullable, attr, name); | ||
| } | ||
| } | ||
| @@ -44,23 +65,25 @@ AggregateFunctionPtr create_aggregate_function_array_agg(const std::string& name | ||
| const DataTypePtr& result_type, | ||
| const bool result_is_nullable, | ||
| const AggregateFunctionAttr& attr) { | ||
| bool distinct = name == "multi_distinct_array_agg"; | ||
| AggregateFunctionPtr agg_fn; | ||
| auto call = [&](const auto& type) -> bool { | ||
| using DispatcType = std::decay_t<decltype(type)>; | ||
| agg_fn = do_create_agg_function_collect<DispatcType::PType>(argument_types, | ||
| agg_fn = do_create_agg_function_collect<DispatcType::PType>(distinct, name, argument_types, | ||
| result_is_nullable, attr); | ||
| return true; | ||
| }; | ||
| if (!dispatch_switch_all(argument_types[0]->get_primitive_type(), call)) { | ||
| // We do not care what the real type is. | ||
| agg_fn = do_create_agg_function_collect<INVALID_TYPE>(argument_types, result_is_nullable, | ||
| attr); | ||
| agg_fn = do_create_agg_function_collect<INVALID_TYPE>(distinct, name, argument_types, | ||
| result_is_nullable, attr); | ||
| } | ||
| return agg_fn; | ||
| } | ||
| void register_aggregate_function_array_agg(AggregateFunctionSimpleFactory& factory) { | ||
| factory.register_function_both("array_agg", create_aggregate_function_array_agg); | ||
| factory.register_function_both("multi_distinct_array_agg", create_aggregate_function_array_agg); | ||
Baymine marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| } // namespace doris | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.