/** * Cleans up the plan after combining similar branches into one branch making sure parents & children point to * each other correctly. */ private void cleanupPlan() { for (Mutable<ILogicalOperator> root : roots) { replicateToOutputs.clear(); newOutputs.clear(); findReplicateOp(root, replicateToOutputs); cleanup(replicateToOutputs, newOutputs); } }
/** * Collects all replicate operator starting from {@param parent} and all its descendants and keeps track of the * valid parents of a replicate operator. The indexes of valid parents will be set in the BitSet. * @param parent the current operator in consideration for which we want to find replicate op children. * @param replicateToOutputs where the replicate operators will be stored with all its parents (valid & invalid). */ private void findReplicateOp(Mutable<ILogicalOperator> parent, Map<Mutable<ILogicalOperator>, BitSet> replicateToOutputs) { List<Mutable<ILogicalOperator>> children = parent.getValue().getInputs(); for (Mutable<ILogicalOperator> childRef : children) { AbstractLogicalOperator child = (AbstractLogicalOperator) childRef.getValue(); if (child.getOperatorTag() == LogicalOperatorTag.REPLICATE || child.getOperatorTag() == LogicalOperatorTag.SPLIT) { AbstractReplicateOperator replicateChild = (AbstractReplicateOperator) child; int parentIndex = replicateChild.getOutputs().indexOf(parent); if (parentIndex >= 0) { BitSet replicateValidOutputs = replicateToOutputs.get(childRef); if (replicateValidOutputs == null) { replicateValidOutputs = new BitSet(); replicateToOutputs.put(childRef, replicateValidOutputs); } replicateValidOutputs.set(parentIndex); } } findReplicateOp(childRef, replicateToOutputs); } }