Skip to content

Commit 1daa31e

Browse files
committed
Ensure deterministic order of aggregates
when pushing partial aggregation through join
1 parent 7af29d5 commit 1daa31e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

core/trino-main/src/main/java/io/trino/sql/planner/iterative/rule/PushPartialAggregationThroughJoin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package io.trino.sql.planner.iterative.rule;
1515

1616
import com.google.common.collect.ImmutableList;
17+
import com.google.common.collect.ImmutableMap;
1718
import com.google.common.collect.ImmutableSet;
1819
import com.google.common.collect.Streams;
1920
import io.trino.Session;
@@ -36,7 +37,6 @@
3637
import io.trino.sql.planner.plan.ProjectNode;
3738
import org.assertj.core.util.VisibleForTesting;
3839

39-
import java.util.HashMap;
4040
import java.util.HashSet;
4141
import java.util.List;
4242
import java.util.Map;
@@ -328,7 +328,7 @@ private PlanNode replaceJoin(
328328

329329
private PlanNode toIntermediateAggregation(AggregationNode partialAggregation, PlanNode source, Context context)
330330
{
331-
Map<Symbol, AggregationNode.Aggregation> intermediateAggregation = new HashMap<>();
331+
ImmutableMap.Builder<Symbol, Aggregation> intermediateAggregation = ImmutableMap.builder();
332332
for (Map.Entry<Symbol, AggregationNode.Aggregation> entry : partialAggregation.getAggregations().entrySet()) {
333333
AggregationNode.Aggregation aggregation = entry.getValue();
334334
ResolvedFunction resolvedFunction = aggregation.getResolvedFunction();
@@ -353,7 +353,7 @@ private PlanNode toIntermediateAggregation(AggregationNode partialAggregation, P
353353
return new AggregationNode(
354354
context.getIdAllocator().getNextId(),
355355
source,
356-
intermediateAggregation,
356+
intermediateAggregation.buildOrThrow(),
357357
partialAggregation.getGroupingSets(),
358358
// preGroupedSymbols reflect properties of the input. Splitting the aggregation and pushing partial aggregation
359359
// through the join may or may not preserve these properties. Hence, it is safest to drop preGroupedSymbols here.

0 commit comments

Comments
 (0)