if (left.isDistributed() || right.isDistributed()) {
switch (node.getType()) {
case INNER:
case LEFT:
right.setRoot(new SinkNode(idAllocator.getNextId(), right.getRoot(), right.getRoot().getOutputSymbols()));
left.setRoot(new JoinNode(node.getId(),
node.getType(),
left.getRoot(),
new ExchangeNode(idAllocator.getNextId(), right.getId(), right.getRoot().getOutputSymbols()),
node.getCriteria()));
left.addChild(right.build());
return left;
case RIGHT:
left.setRoot(new SinkNode(idAllocator.getNextId(), left.getRoot(), left.getRoot().getOutputSymbols()));
right.setRoot(new JoinNode(node.getId(),
node.getType(),
new ExchangeNode(idAllocator.getNextId(), left.getId(), left.getRoot().getOutputSymbols()),
right.getRoot(),
node.getCriteria()));
right.addChild(left.build());
return right;
default:
throw new UnsupportedOperationException("Unsupported join type: " + node.getType());
}
}
else {
JoinNode join = new JoinNode(node.getId(), node.getType(), left.getRoot(), right.getRoot(), node.getCriteria());
return createSingleNodePlan(join)
.setChildren(Iterables.concat(left.getChildren(), right.getChildren()));
}
}