Reshuffle output symbols in JoinNode.replaceChildren
Since order of symbols in child nodes might have changed,
therefore for cross joins order of join output symbols
need to be changed too
@@ -27,8 +27,10 @@ import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
+import java.util.stream.Stream;
import static com.facebook.presto.sql.planner.plan.JoinNode.Type.INNER;
+import static com.facebook.presto.util.ImmutableCollectors.toImmutableList;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
@@ -192,7 +194,13 @@ public class JoinNode
public PlanNode replaceChildren(List<PlanNode> newChildren)
{
checkArgument(newChildren.size() == 2, "expected newChildren to contain 2 nodes");
- return new JoinNode(getId(), type, newChildren.get(0), newChildren.get(1), criteria, outputSymbols, filter, leftHashSymbol, rightHashSymbol);
+ PlanNode newLeft = newChildren.get(0);
+ PlanNode newRight = newChildren.get(1);
+ // Reshuffle join output symbols (for cross joins) since order of symbols in child nodes might have changed
+ List<Symbol> newOutputSymbols = Stream.concat(newLeft.getOutputSymbols().stream(), newRight.getOutputSymbols().stream())
+ .filter(outputSymbols::contains)
+ .collect(toImmutableList());
+ return new JoinNode(getId(), type, newLeft, newRight, criteria, newOutputSymbols, filter, leftHashSymbol, rightHashSymbol);
}
public boolean isCrossJoin()
