public static void substituteVariables(ILogicalOperator op, List<Pair<LogicalVariable, LogicalVariable>> oldVarNewVarMapHistory, ITypingContext ctx) throws AlgebricksException { for (Pair<LogicalVariable, LogicalVariable> entry : oldVarNewVarMapHistory) { VariableUtilities.substituteVariables(op, entry.first, entry.second, ctx); } }
public static void substituteVariablesInDescendantsAndSelf(ILogicalOperator op, LogicalVariable v1, LogicalVariable v2, ITypingContext ctx) throws AlgebricksException { for (Mutable<ILogicalOperator> childOp : op.getInputs()) { substituteVariablesInDescendantsAndSelf(childOp.getValue(), v1, v2, ctx); } substituteVariables(op, v1, v2, true, ctx); }
public static void substituteVariables(ILogicalOperator op, LogicalVariable v1, LogicalVariable v2, ITypingContext ctx) throws AlgebricksException { substituteVariables(op, v1, v2, true, ctx); }
public static void substituteVariablesInDescendantsAndSelf(ILogicalOperator op, Map<LogicalVariable, LogicalVariable> varMap, ITypingContext ctx) throws AlgebricksException { for (Entry<LogicalVariable, LogicalVariable> entry : varMap.entrySet()) { for (Mutable<ILogicalOperator> childOp : op.getInputs()) { substituteVariablesInDescendantsAndSelf(childOp.getValue(), entry.getKey(), entry.getValue(), ctx); } substituteVariables(op, entry.getKey(), entry.getValue(), true, ctx); } }
private void subtituteVariables(ILogicalOperator op) throws AlgebricksException { VariableUtilities.substituteVariables(op, subplanInputVarToCurrentVarMap, context); VariableUtilities.substituteVariables(op, varMapIntroducedByRewriting, context); }
/** * Substitute variable references inside an operator according to a variable map. * * @param op, * the operator for variable substitution. * @param varMap, * a map that maps old variables to new variables. Note that we enforce * the map to be a LinkedHashMap so as to be able to perform recursive * variable substitution within one pass. The order of variable substitution * is the entry insertion order of the LinkedHashMap. Typically, the LinkedHashMap * is populated by recursively, bottom-up traversing of the query plan. * For example, if $1->$2 and $2->$3 are orderly inserted into the map, $1 will be * replaced by $3 in the outcome of this method call. * * @param ctx, * a typing context that keeps track of types of each variable. * @throws AlgebricksException */ public static void substituteVariables(ILogicalOperator op, LinkedHashMap<LogicalVariable, LogicalVariable> varMap, ITypingContext ctx) throws AlgebricksException { for (Map.Entry<LogicalVariable, LogicalVariable> entry : varMap.entrySet()) { VariableUtilities.substituteVariables(op, entry.getKey(), entry.getValue(), ctx); } }
private void substInSubplan(AggregateOperator aggInner, LogicalVariable v1, LogicalVariable v2, IOptimizationContext context) throws AlgebricksException { ILogicalOperator op = aggInner; while (op.getInputs().size() == 1) { VariableUtilities.substituteVariables(op, v1, v2, context); op = op.getInputs().get(0).getValue(); } } }
private ILogicalOperator copyAndSubstituteVar(ILogicalOperator op, ILogicalOperator argOp) throws AlgebricksException { ILogicalOperator newOp = OperatorManipulationUtil.deepCopy(argOp); variableMapping.clear(); IsomorphismUtilities.mapVariablesTopDown(op, argOp, variableMapping); List<LogicalVariable> liveVars = new ArrayList<>(); for (int i = 0; i < argOp.getInputs().size(); i++) { VariableUtilities.getLiveVariables(argOp.getInputs().get(i).getValue(), liveVars); } List<LogicalVariable> producedVars = new ArrayList<>(); VariableUtilities.getProducedVariables(argOp, producedVars); List<LogicalVariable> producedVarsNew = new ArrayList<>(); VariableUtilities.getProducedVariables(op, producedVarsNew); if (producedVars.size() != producedVarsNew.size()) { return newOp; } for (Entry<LogicalVariable, LogicalVariable> map : variableMapping.entrySet()) { if (liveVars.contains(map.getKey())) { VariableUtilities.substituteVariables(newOp, map.getKey(), map.getValue(), null); } } for (int i = 0; i < producedVars.size(); i++) { VariableUtilities.substituteVariables(newOp, producedVars.get(i), producedVarsNew.get(i), null); } return newOp; }
private ILogicalOperator visit(ILogicalOperator op) throws AlgebricksException { List<Map<LogicalVariable, LogicalVariable>> varMapSnapshots = new ArrayList<>(); for (Mutable<ILogicalOperator> childRef : op.getInputs()) { ILogicalOperator newChild = childRef.getValue().accept(this, null); childRef.setValue(newChild); // Replaces variables in op with the mapping obtained from one // child. VariableUtilities.substituteVariables(op, varMap, ctx); // Keep the map from current child and move to the next child. varMapSnapshots.add(new HashMap<LogicalVariable, LogicalVariable>(varMap)); varMap.clear(); } // Combine mappings from all children. for (Map<LogicalVariable, LogicalVariable> map : varMapSnapshots) { varMap.putAll(map); } // Only propagates necessary mappings to the parent operator. Set<LogicalVariable> liveVars = new HashSet<LogicalVariable>(); VariableUtilities.getLiveVariables(op, liveVars); varMap.values().retainAll(liveVars); return op; }
replacedVarMap.putAll(resultFromChild.second); VariableUtilities.substituteVariables(op, replacedVarMap, context); context.computeAndSetTypeEnvironmentForOperator(op); return new Pair<>(changed, replacedVarMapForAncestor);
private AssignOperator createAssignBelowUnionAllBranch(UnionAllOperator unionOp, int inputIndex, AssignOperator originalAssignOp, Set<LogicalVariable> assignUsedVars, IOptimizationContext context) throws AlgebricksException { AssignOperator newAssignOp = cloneAssignOperator(originalAssignOp, context); newAssignOp.getInputs() .add(new MutableObject<ILogicalOperator>(unionOp.getInputs().get(inputIndex).getValue())); unionOp.getInputs().get(inputIndex).setValue(newAssignOp); int numVarMappings = unionOp.getVariableMappings().size(); for (int i = 0; i < numVarMappings; i++) { Triple<LogicalVariable, LogicalVariable, LogicalVariable> varMapping = unionOp.getVariableMappings().get(i); if (assignUsedVars.contains(varMapping.third)) { LogicalVariable replacementVar; if (inputIndex == 0) { replacementVar = varMapping.first; } else { replacementVar = varMapping.second; } VariableUtilities.substituteVariables(newAssignOp, varMapping.third, replacementVar, context); } } context.computeAndSetTypeEnvironmentForOperator(newAssignOp); return newAssignOp; }
VariableUtilities.substituteVariables(currentOperator, cloneVarMap, null); varMap.putAll(cloneVarMap); eliminateSharedOperatorReference(childRef, opRefSet); VariableUtilities.substituteVariables(currentOperator, childVarMap, null);
varRef.setSourceLocation(sourceLoc); newGbyOp.addGbyExpression(replGbyList.get(i), varRef); VariableUtilities.substituteVariables(gbyOp, newOpGbyList.get(i), replGbyList.get(i), false, context);
VariableUtilities.substituteVariables(topOp, visitor.getVariableMapHistory(), context);
varRef.setSourceLocation(gbyOp.getSourceLocation()); newGbyOp.addDecorExpression(newDecorVar, varRef); VariableUtilities.substituteVariables(gbyOp.getNestedPlans().get(0).getRoots().get(0).getValue(), var, newDecorVar, context);
context.computeAndSetTypeEnvironmentForOperator(newAssignOperator); newAssignOperator.computeOutputTypeEnvironment(context); VariableUtilities.substituteVariables(parent, recordVar, newAssignVar, context); return newAssignVar; if (replacedVar != null) { VariableUtilities.substituteVariables(parent, recordVar, replacedVar, context); return replacedVar;
OperatorManipulationUtil.computeTypeEnvironmentBottomUp(groupbyOp, context); VariableUtilities.substituteVariables(groupbyOp, result.second, context); replacedVarMap.putAll(result.second); return new Pair<>(true, replacedVarMap);
ILogicalOperator currentOp = topRef.getValue(); while (currentOp != result) { VariableUtilities.substituteVariables(currentOp, subplanLocalVarMap, context); currentOp = currentOp.getInputs().get(0).getValue();
newAssignChildOp.getInputs().set(0, new MutableObject<ILogicalOperator>(newAssign)); if (hasFilter) { VariableUtilities.substituteVariables(newAssignChildOp, inputRecord, v, context); VariableUtilities.substituteVariables(assignOp, inputRecord, v, context); VariableUtilities.substituteVariables(insertOp, inputRecord, v, context); context.computeAndSetTypeEnvironmentForOperator(newAssign); if (hasFilter) { context.computeAndSetTypeEnvironmentForOperator(insertOp); for (AbstractLogicalOperator op : opStack) { VariableUtilities.substituteVariables(op, inputRecord, v, context); context.computeAndSetTypeEnvironmentForOperator(op);
public static void substituteVarRec(AbstractLogicalOperator op, LogicalVariable v1, LogicalVariable v2, boolean goThroughNts, ITypingContext ctx) throws AlgebricksException { VariableUtilities.substituteVariables(op, v1, v2, goThroughNts, ctx); for (Mutable<ILogicalOperator> opRef2 : op.getInputs()) { substituteVarRec((AbstractLogicalOperator) opRef2.getValue(), v1, v2, goThroughNts, ctx); } if (op.getOperatorTag() == LogicalOperatorTag.NESTEDTUPLESOURCE && goThroughNts) { NestedTupleSourceOperator nts = (NestedTupleSourceOperator) op; if (nts.getDataSourceReference() != null) { AbstractLogicalOperator op2 = (AbstractLogicalOperator) nts.getDataSourceReference().getValue().getInputs().get(0).getValue(); substituteVarRec(op2, v1, v2, goThroughNts, ctx); } } if (op.hasNestedPlans()) { AbstractOperatorWithNestedPlans aonp = (AbstractOperatorWithNestedPlans) op; for (ILogicalPlan p : aonp.getNestedPlans()) { for (Mutable<ILogicalOperator> ref : p.getRoots()) { AbstractLogicalOperator aop = (AbstractLogicalOperator) ref.getValue(); substituteVarRec(aop, v1, v2, goThroughNts, ctx); } } } }