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

[GLUTEN-7311]A patch for supporting multiple aggregate phases in one step #504

Open
wants to merge 1 commit into
base: rebase_ch/20241010
Choose a base branch
from
Open
Changes from all commits
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
22 changes: 17 additions & 5 deletions src/Interpreters/Aggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,28 @@ Block Aggregator::Params::getHeader(

for (const auto & aggregate : aggregates)
{
size_t arguments_size = aggregate.argument_names.size();
DataTypes argument_types(arguments_size);
for (size_t j = 0; j < arguments_size; ++j)
argument_types[j] = header.getByName(aggregate.argument_names[j]).type;

DataTypePtr type;
if (final)
type = aggregate.function->getResultType();
else
type = std::make_shared<DataTypeAggregateFunction>(aggregate.function, argument_types, aggregate.parameters);
{
/// This could happen in gluten when there are multiple aggregate phases in one aggregation step.
/// Since a aggregation function's arguments cannot be aggregate data, this should be OK.
const auto * input_col = header.findByName(aggregate.column_name);
if (input_col && typeid_cast<const DataTypeAggregateFunction*>(input_col->type.get()))
{
type = input_col->type;
}
else
{
size_t arguments_size = aggregate.argument_names.size();
DataTypes argument_types(arguments_size);
for (size_t j = 0; j < arguments_size; ++j)
argument_types[j] = header.getByName(aggregate.argument_names[j]).type;
type = std::make_shared<DataTypeAggregateFunction>(aggregate.function, argument_types, aggregate.parameters);
}
}

res.insert({ type, aggregate.column_name });
}
Expand Down