Skip to content
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

[feature](function) Support for aggregate function foreach combiner #31526

Merged
merged 7 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cr
  • Loading branch information
Mryange committed Mar 2, 2024
commit 2691518bca3f088f149da414bb5753caec39ba32
13 changes: 7 additions & 6 deletions be/src/vec/aggregate_functions/aggregate_function_foreach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ namespace doris::vectorized {
void register_aggregate_function_combinator_foreach(AggregateFunctionSimpleFactory& factory) {
AggregateFunctionCreator creator = [&](const std::string& name, const DataTypes& types,
const bool result_is_nullable) -> AggregateFunctionPtr {
const std::string suffix = AggregateFunctionForEach::AGG_FOREACH_SUFFIX;
const std::string& suffix = AggregateFunctionForEach::AGG_FOREACH_SUFFIX;
DataTypes transform_arguments;
for (auto t : types) {
for (const auto& t : types) {
auto item_type =
assert_cast<const DataTypeArray*>(remove_nullable(t).get())->get_nested_type();
transform_arguments.push_back((item_type));
Expand All @@ -47,10 +47,11 @@ void register_aggregate_function_combinator_foreach(AggregateFunctionSimpleFacto
auto nested_function =
factory.get(nested_function_name, transform_arguments, result_is_nullable);
if (!nested_function) {
throw Exception(ErrorCode::INTERNAL_ERROR,
"The combiner did not find a corresponding function. nested function "
"name {} , args {}",
nested_function_name, types_name(types));
throw Exception(
ErrorCode::INTERNAL_ERROR,
"The combiner did not find a foreach combiner function. nested function "
"name {} , args {}",
nested_function_name, types_name(types));
}
return creator_without_type::create<AggregateFunctionForEach>(transform_arguments, true,
nested_function);
Expand Down
11 changes: 6 additions & 5 deletions be/src/vec/aggregate_functions/aggregate_function_foreach.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class AggregateFunctionForEach : public IAggregateFunctionDataHelper<AggregateFu
const size_t nested_size_of_data;
const size_t num_arguments;

AggregateFunctionForEachData& ensureAggregateData(AggregateDataPtr __restrict place,
size_t new_size, Arena& arena) const {
AggregateFunctionForEachData& ensure_aggregate_data(AggregateDataPtr __restrict place,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: pointer parameter 'place' can be pointer to const [readability-non-const-parameter]

Suggested change
AggregateFunctionForEachData& ensure_aggregate_data(AggregateDataPtr __restrict place,
AggregateFunctionForEachData& ensure_aggregate_data(const AggregateDataPtr __restrict place,

size_t new_size, Arena& arena) const {
AggregateFunctionForEachData& state = data(place);

/// Ensure we have aggregate states for new_size elements, allocate
Expand Down Expand Up @@ -113,6 +113,7 @@ class AggregateFunctionForEach : public IAggregateFunctionDataHelper<AggregateFu
for (i = 0; i < old_size; ++i) {
nested_function->merge(&new_state[i * nested_size_of_data],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

destory the old_state mem

&old_state[i * nested_size_of_data], &arena);
nested_function->destroy(&old_state[i * nested_size_of_data]);
}

state.array_of_aggregate_datas = new_state;
Expand Down Expand Up @@ -163,7 +164,7 @@ class AggregateFunctionForEach : public IAggregateFunctionDataHelper<AggregateFu
Arena* arena) const override {
const AggregateFunctionForEachData& rhs_state = data(rhs);
AggregateFunctionForEachData& state =
ensureAggregateData(place, rhs_state.dynamic_array_size, *arena);
ensure_aggregate_data(place, rhs_state.dynamic_array_size, *arena);

const char* rhs_nested_state = rhs_state.array_of_aggregate_datas;
char* nested_state = state.array_of_aggregate_datas;
Expand Down Expand Up @@ -193,7 +194,7 @@ class AggregateFunctionForEach : public IAggregateFunctionDataHelper<AggregateFu
size_t new_size = 0;
read_binary(new_size, buf);

ensureAggregateData(place, new_size, *arena);
ensure_aggregate_data(place, new_size, *arena);

char* nested_state = state.array_of_aggregate_datas;
for (size_t i = 0; i < new_size; ++i) {
Expand Down Expand Up @@ -251,7 +252,7 @@ class AggregateFunctionForEach : public IAggregateFunctionDataHelper<AggregateFu
}
}

AggregateFunctionForEachData& state = ensureAggregateData(place, end - begin, *arena);
AggregateFunctionForEachData& state = ensure_aggregate_data(place, end - begin, *arena);

char* nested_state = state.array_of_aggregate_datas;
for (size_t i = begin; i < end; ++i) {
Expand Down
Loading