diff --git a/presto-main/src/main/java/io/prestosql/sql/planner/optimizations/UnaliasSymbolReferences.java b/presto-main/src/main/java/io/prestosql/sql/planner/optimizations/UnaliasSymbolReferences.java index 6f381a9ce3e8..9f8a54128aa8 100644 --- a/presto-main/src/main/java/io/prestosql/sql/planner/optimizations/UnaliasSymbolReferences.java +++ b/presto-main/src/main/java/io/prestosql/sql/planner/optimizations/UnaliasSymbolReferences.java @@ -297,21 +297,22 @@ public PlanAndMappings visitExchange(ExchangeNode node, UnaliasContext context) } } } - - // 2. for multiple ExchangeNode sources, if different output symbols result from the same lists of canonical input symbols, map all those outputs to the same symbol - Map, Symbol> inputsToOutputs = new HashMap<>(); - for (int i = 0; i < rewrittenOutputs.size(); i++) { - ImmutableList.Builder inputsBuilder = ImmutableList.builder(); - for (List inputs : rewrittenInputs) { - inputsBuilder.add(inputs.get(i)); - } - List inputs = inputsBuilder.build(); - Symbol previous = inputsToOutputs.get(inputs); - if (previous == null || rewrittenOutputs.get(i).equals(previous)) { - inputsToOutputs.put(inputs, rewrittenOutputs.get(i)); - } - else { - newMapping.put(rewrittenOutputs.get(i), previous); + else { + // 2. for multiple ExchangeNode sources, if different output symbols result from the same lists of canonical input symbols, map all those outputs to the same symbol + Map, Symbol> inputsToOutputs = new HashMap<>(); + for (int i = 0; i < rewrittenOutputs.size(); i++) { + ImmutableList.Builder inputsBuilder = ImmutableList.builder(); + for (List inputs : rewrittenInputs) { + inputsBuilder.add(inputs.get(i)); + } + List inputs = inputsBuilder.build(); + Symbol previous = inputsToOutputs.get(inputs); + if (previous == null || rewrittenOutputs.get(i).equals(previous)) { + inputsToOutputs.put(inputs, rewrittenOutputs.get(i)); + } + else { + newMapping.put(rewrittenOutputs.get(i), previous); + } } }