Fixed UsedVariableVisitor for the Splitoperator

 - The used variables of SplitOperator and ReplicateOperator
   now don't include the used variables from their output(s).

Change-Id: Iae861c1339cf00c5a53aa2b5b5b14113ec53484b
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1273
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Yingyi Bu <buyingyi@gmail.com>
diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/logical/visitors/UsedVariableVisitor.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/logical/visitors/UsedVariableVisitor.java
index cfe2a37..3daa00f 100644
--- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/logical/visitors/UsedVariableVisitor.java
+++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/logical/visitors/UsedVariableVisitor.java
@@ -428,17 +428,12 @@
 
     @Override
     public Void visitReplicateOperator(ReplicateOperator op, Void arg) throws AlgebricksException {
-        for (Mutable<ILogicalOperator> outputOp : op.getOutputs()) {
-            VariableUtilities.getUsedVariables(outputOp.getValue(), usedVariables);
-        }
         return null;
     }
 
     @Override
     public Void visitSplitOperator(SplitOperator op, Void arg) throws AlgebricksException {
-        for (Mutable<ILogicalOperator> outputOp : op.getOutputs()) {
-            VariableUtilities.getUsedVariables(outputOp.getValue(), usedVariables);
-        }
+        op.getBranchingExpression().getValue().getUsedVariables(usedVariables);
         return null;
     }
 
diff --git a/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/RemoveUnusedAssignAndAggregateRule.java b/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/RemoveUnusedAssignAndAggregateRule.java
index 55831f0..5bf4e6881 100644
--- a/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/RemoveUnusedAssignAndAggregateRule.java
+++ b/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/RemoveUnusedAssignAndAggregateRule.java
@@ -383,7 +383,7 @@
             // We may have visited this operator before if there are multiple
             // paths in the plan.
             if (accumulatedUsedVarFromRootMap.containsKey(opRef)) {
-                accumulatedUsedVarFromRootMap.get(opRef).addAll(usedVarsSetInThisOp);
+                accumulatedUsedVarFromRootMap.get(opRef).addAll(accumulatedUsedVarFromRootSet);
             } else {
                 accumulatedUsedVarFromRootMap.put(opRef, new HashSet<LogicalVariable>(accumulatedUsedVarFromRootSet));
             }