Skip to content

Commit

Permalink
[GLUTEN-6878][CH] Avoid name collisions in naming aggregate result (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lgbo-ustc authored Aug 16, 2024
1 parent fc9d273 commit d1da37f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cpp-ch/local-engine/Parser/AggregateRelParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ void AggregateRelParser::addPreProjection()

void AggregateRelParser::buildAggregateDescriptions(AggregateDescriptions & descriptions)
{
auto build_result_column_name = [](const String & function_name, const Array & params, const Strings & arg_names, substrait::AggregationPhase phase)
const auto & current_plan_header = plan->getCurrentDataStream().header;
auto build_result_column_name = [this, current_plan_header](const String & function_name, const Array & params, const Strings & arg_names, substrait::AggregationPhase phase)
{
if (phase == substrait::AggregationPhase::AGGREGATION_PHASE_INTERMEDIATE_TO_RESULT)
{
Expand All @@ -219,7 +220,12 @@ void AggregateRelParser::buildAggregateDescriptions(AggregateDescriptions & desc
result += "(";
result += boost::algorithm::join(arg_names, ",");
result += ")";
return result;
// Make the name unique to avoid name collision(issue #6878).
auto res = this->getUniqueName(result);
// Just a check for remining this issue.
if (current_plan_header.findByName(res))
throw DB::Exception(DB::ErrorCodes::LOGICAL_ERROR, "Name ({}) collision in header: {}", res, current_plan_header.dumpStructure());
return res;
};

for (auto & agg_info : aggregates)
Expand All @@ -228,6 +234,7 @@ void AggregateRelParser::buildAggregateDescriptions(AggregateDescriptions & desc
const auto & measure = agg_info.measure->measure();
description.column_name
= build_result_column_name(agg_info.function_name, agg_info.params, agg_info.arg_column_names, measure.phase());

agg_info.measure_column_name = description.column_name;
// std::cout << "description.column_name:" << description.column_name << std::endl;
description.argument_names = agg_info.arg_column_names;
Expand Down

0 comments on commit d1da37f

Please sign in to comment.