public class BroadcastJoinPlanVisitor extends BasicLogicalPlanVisitor<GlobalPlanner.GlobalPlanContext, LogicalNode> {
@Override
public LogicalNode visitJoin(GlobalPlanner.GlobalPlanContext context, LogicalPlan plan, LogicalPlan.QueryBlock block,
JoinNode node, Stack<LogicalNode> stack) throws PlanningException {
LogicalNode leftChild = node.getLeftChild();
LogicalNode rightChild = node.getRightChild();
if (isScanNode(leftChild) && isScanNode(rightChild)) {
node.setCandidateBroadcast(true);
node.getBroadcastTargets().add(leftChild);
node.getBroadcastTargets().add(rightChild);
return node;
}
if(!isScanNode(leftChild)) {
visit(context, plan, block, leftChild, stack);
}
if(!isScanNode(rightChild)) {
visit(context, plan, block, rightChild, stack);
}
if(isBroadcastCandidateNode(leftChild) && isBroadcastCandidateNode(rightChild)) {
node.setCandidateBroadcast(true);
if(leftChild.getType() == NodeType.JOIN) {
node.getBroadcastTargets().addAll(((JoinNode)leftChild).getBroadcastTargets());
} else {
node.getBroadcastTargets().add(leftChild);
}
if(rightChild.getType() == NodeType.JOIN) {
node.getBroadcastTargets().addAll(((JoinNode)rightChild).getBroadcastTargets());
} else {
node.getBroadcastTargets().add(rightChild);
}
}