List of usage examples for org.apache.commons.lang3.mutable Mutable getValue
T getValue();
From source file:edu.uci.ics.asterix.optimizer.rules.PushGroupByThroughProduct.java
private PushTestResult canPushThrough(GroupByOperator gby, ILogicalOperator branch, List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> toPush, List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> notToPush) throws AlgebricksException { Collection<LogicalVariable> fromBranch = new HashSet<LogicalVariable>(); VariableUtilities.getLiveVariables(branch, fromBranch); Collection<LogicalVariable> usedInGbyExprList = new ArrayList<LogicalVariable>(); for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : gby.getGroupByList()) { p.second.getValue().getUsedVariables(usedInGbyExprList); }// w ww . j a va 2 s . c o m if (!fromBranch.containsAll(usedInGbyExprList)) { return PushTestResult.FALSE; } Set<LogicalVariable> free = new HashSet<LogicalVariable>(); for (ILogicalPlan p : gby.getNestedPlans()) { for (Mutable<ILogicalOperator> r : p.getRoots()) { OperatorPropertiesUtil.getFreeVariablesInSelfOrDesc((AbstractLogicalOperator) r.getValue(), free); } } if (!fromBranch.containsAll(free)) { return PushTestResult.FALSE; } Set<LogicalVariable> decorVarRhs = new HashSet<LogicalVariable>(); decorVarRhs.clear(); for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : gby.getDecorList()) { ILogicalExpression expr = p.second.getValue(); if (expr.getExpressionTag() != LogicalExpressionTag.VARIABLE) { return PushTestResult.FALSE; } VariableReferenceExpression varRef = (VariableReferenceExpression) expr; LogicalVariable v = varRef.getVariableReference(); if (decorVarRhs.contains(v)) { return PushTestResult.REPEATED_DECORS; } decorVarRhs.add(v); if (fromBranch.contains(v)) { toPush.add(p); } else { notToPush.add(p); } } return PushTestResult.TRUE; }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.SubplanOutOfGroupRule.java
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op0 = (AbstractLogicalOperator) opRef.getValue(); if (op0.getOperatorTag() != LogicalOperatorTag.GROUP) { return false; }/*from w ww . j av a2 s .c o m*/ GroupByOperator gby = (GroupByOperator) op0; Iterator<ILogicalPlan> plansIter = gby.getNestedPlans().iterator(); ILogicalPlan p = null; while (plansIter.hasNext()) { p = plansIter.next(); } if (p == null) { return false; } if (p.getRoots().size() != 1) { return false; } Mutable<ILogicalOperator> op1Ref = p.getRoots().get(0); AbstractLogicalOperator op1 = (AbstractLogicalOperator) op1Ref.getValue(); boolean found = false; while (op1.getInputs().size() == 1) { if (op1.getOperatorTag() == LogicalOperatorTag.SUBPLAN) { SubplanOperator subplan = (SubplanOperator) op1; AbstractLogicalOperator op2 = (AbstractLogicalOperator) subplan.getInputs().get(0).getValue(); if (OperatorPropertiesUtil.isNullTest(op2)) { if (subplan.getNestedPlans().size() == 1) { ILogicalPlan p1 = subplan.getNestedPlans().get(0); if (p1.getRoots().size() == 1) { AbstractLogicalOperator r1 = (AbstractLogicalOperator) p1.getRoots().get(0).getValue(); if (r1.getOperatorTag() == LogicalOperatorTag.INNERJOIN || r1.getOperatorTag() == LogicalOperatorTag.LEFTOUTERJOIN) { // now, check that it propagates all variables, // so it can be pushed List<LogicalVariable> op2Vars = new ArrayList<LogicalVariable>(); VariableUtilities.getLiveVariables(op2, op2Vars); List<LogicalVariable> op1Vars = new ArrayList<LogicalVariable>(); VariableUtilities.getLiveVariables(subplan, op1Vars); if (op1Vars.containsAll(op2Vars)) { found = true; break; } } } } } } op1Ref = op1.getInputs().get(0); op1 = (AbstractLogicalOperator) op1Ref.getValue(); } if (!found) { return false; } ILogicalOperator subplan = op1; ILogicalOperator op2 = op1.getInputs().get(0).getValue(); op1Ref.setValue(op2); Mutable<ILogicalOperator> opUnderRef = gby.getInputs().get(0); ILogicalOperator opUnder = opUnderRef.getValue(); subplan.getInputs().clear(); subplan.getInputs().add(new MutableObject<ILogicalOperator>(opUnder)); opUnderRef.setValue(subplan); return true; }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.NestedSubplanToJoinRule.java
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { if (context.checkIfInDontApplySet(this, opRef.getValue())) return false; context.addToDontApplySet(this, opRef.getValue()); ILogicalOperator op1 = opRef.getValue(); if (op1.getInputs().size() == 0) { return false; }//from w w w.ja v a 2s. com boolean rewritten = false; for (int index = 0; index < op1.getInputs().size(); index++) { AbstractLogicalOperator child = (AbstractLogicalOperator) op1.getInputs().get(index).getValue(); if (child.getOperatorTag() != LogicalOperatorTag.SUBPLAN) { continue; } AbstractOperatorWithNestedPlans subplan = (AbstractOperatorWithNestedPlans) child; Set<LogicalVariable> freeVars = new HashSet<LogicalVariable>(); OperatorPropertiesUtil.getFreeVariablesInSubplans(subplan, freeVars); if (!freeVars.isEmpty()) { /** * the subplan is correlated with the outer plan, other rules can deal with it */ continue; } /** get the input operator of the subplan operator */ ILogicalOperator subplanInput = subplan.getInputs().get(0).getValue(); AbstractLogicalOperator subplanInputOp = (AbstractLogicalOperator) subplanInput; /** If the other join branch is a trivial plan, do not do the rewriting. */ if (subplanInputOp.getOperatorTag() == LogicalOperatorTag.EMPTYTUPLESOURCE) { continue; } /** get all nested top operators */ List<ILogicalPlan> nestedPlans = subplan.getNestedPlans(); List<Mutable<ILogicalOperator>> nestedRoots = new ArrayList<Mutable<ILogicalOperator>>(); for (ILogicalPlan nestedPlan : nestedPlans) { nestedRoots.addAll(nestedPlan.getRoots()); } if (nestedRoots.size() == 0) { /** there is no nested top operators */ continue; } /** expend the input and roots into a DAG of nested loop joins */ Mutable<ILogicalExpression> expr = new MutableObject<ILogicalExpression>(ConstantExpression.TRUE); Mutable<ILogicalOperator> nestedRootRef = nestedRoots.get(0); ILogicalOperator join = new LeftOuterJoinOperator(expr, new MutableObject<ILogicalOperator>(subplanInput), nestedRootRef); /** rewrite the nested tuple source to be empty tuple source */ rewriteNestedTupleSource(nestedRootRef); for (int i = 1; i < nestedRoots.size(); i++) { join = new LeftOuterJoinOperator(expr, new MutableObject<ILogicalOperator>(join), nestedRoots.get(i)); } op1.getInputs().get(index).setValue(join); context.computeAndSetTypeEnvironmentForOperator(join); rewritten = true; } return rewritten; }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushLimitDownRule.java
/** * When a global Limit over a merge-exchange is found, a local Limit is * pushed down./*from w w w.ja va 2s . c om*/ */ @Override public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (op.getOperatorTag() != LogicalOperatorTag.LIMIT) { return false; } LimitOperator opLim = (LimitOperator) op; if (!opLim.isTopmostLimitOp()) { return false; } Mutable<ILogicalOperator> opRef2 = opLim.getInputs().get(0); AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue(); if (context.checkAndAddToAlreadyCompared(op, op2)) { return false; } if (op2.getOperatorTag() != LogicalOperatorTag.EXCHANGE) { return false; } PhysicalOperatorTag op2PTag = op2.getPhysicalOperator().getOperatorTag(); // we should test for any kind of merge if (op2PTag != PhysicalOperatorTag.RANDOM_MERGE_EXCHANGE && op2PTag != PhysicalOperatorTag.SORT_MERGE_EXCHANGE) { return false; } LinkedList<LogicalVariable> usedVars1 = new LinkedList<LogicalVariable>(); VariableUtilities.getUsedVariables(opLim, usedVars1); do { if (op2.getOperatorTag() == LogicalOperatorTag.EMPTYTUPLESOURCE || op2.getOperatorTag() == LogicalOperatorTag.NESTEDTUPLESOURCE || op2.getOperatorTag() == LogicalOperatorTag.LIMIT) { return false; } if (op2.getInputs().size() > 1 || !op2.isMap()) { break; } LinkedList<LogicalVariable> vars2 = new LinkedList<LogicalVariable>(); VariableUtilities.getProducedVariables(op2, vars2); if (!OperatorPropertiesUtil.disjoint(vars2, usedVars1)) { return false; } // we assume pipelineable ops. have only one input opRef2 = op2.getInputs().get(0); op2 = (AbstractLogicalOperator) opRef2.getValue(); } while (true); LimitOperator clone2 = null; if (opLim.getOffset().getValue() == null) { clone2 = new LimitOperator(opLim.getMaxObjects().getValue(), false); } else { // push limit (max+offset) IFunctionInfo finfoAdd = context.getMetadataProvider() .lookupFunction(AlgebricksBuiltinFunctions.NUMERIC_ADD); ScalarFunctionCallExpression maxPlusOffset = new ScalarFunctionCallExpression(finfoAdd, opLim.getMaxObjects(), opLim.getOffset()); clone2 = new LimitOperator(maxPlusOffset, false); } clone2.setPhysicalOperator(new StreamLimitPOperator(false)); clone2.getInputs().add(new MutableObject<ILogicalOperator>(op2)); clone2.setExecutionMode(op2.getExecutionMode()); clone2.recomputeSchema(); opRef2.setValue(clone2); context.computeAndSetTypeEnvironmentForOperator(clone2); return true; }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.InsertOuterJoinRule.java
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op0 = (AbstractLogicalOperator) opRef.getValue(); if (op0.getOperatorTag() != LogicalOperatorTag.SUBPLAN) { return false; }/*from w w w . j ava 2s.c o m*/ SubplanOperator subplan = (SubplanOperator) op0; Iterator<ILogicalPlan> plansIter = subplan.getNestedPlans().iterator(); ILogicalPlan p = null; while (plansIter.hasNext()) { p = plansIter.next(); } if (p == null) { return false; } if (p.getRoots().size() != 1) { return false; } Mutable<ILogicalOperator> subplanRoot = p.getRoots().get(0); AbstractLogicalOperator op1 = (AbstractLogicalOperator) subplanRoot.getValue(); Mutable<ILogicalOperator> opUnder = subplan.getInputs().get(0); if (OperatorPropertiesUtil.isNullTest((AbstractLogicalOperator) opUnder.getValue())) { return false; } switch (op1.getOperatorTag()) { case INNERJOIN: { InnerJoinOperator join = (InnerJoinOperator) op1; Mutable<ILogicalOperator> leftRef = join.getInputs().get(0); Mutable<ILogicalOperator> rightRef = join.getInputs().get(1); Mutable<ILogicalOperator> ntsRef = getNtsAtEndOfPipeline(leftRef); if (ntsRef == null) { ntsRef = getNtsAtEndOfPipeline(rightRef); if (ntsRef == null) { return false; } else { Mutable<ILogicalOperator> t = leftRef; leftRef = rightRef; rightRef = t; } } ntsRef.setValue(opUnder.getValue()); LeftOuterJoinOperator loj = new LeftOuterJoinOperator(join.getCondition()); loj.getInputs().add(leftRef); loj.getInputs().add(rightRef); opRef.setValue(loj); context.computeAndSetTypeEnvironmentForOperator(loj); return true; } case LEFTOUTERJOIN: { LeftOuterJoinOperator join = (LeftOuterJoinOperator) op1; Mutable<ILogicalOperator> leftRef = join.getInputs().get(0); Mutable<ILogicalOperator> ntsRef = getNtsAtEndOfPipeline(leftRef); if (ntsRef == null) { return false; } ntsRef.setValue(opUnder.getValue()); opRef.setValue(join); context.computeAndSetTypeEnvironmentForOperator(join); return true; } default: { return false; } } }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushSubplanIntoGroupByRule.java
/** * Removes unused aggregation variables (and expressions) * //ww w .ja va 2 s .co m * @param gby * @throws AlgebricksException */ private void cleanup(GroupByOperator gby) throws AlgebricksException { for (ILogicalPlan nestedPlan : gby.getNestedPlans()) { for (Mutable<ILogicalOperator> rootRef : nestedPlan.getRoots()) { AggregateOperator aggOp = (AggregateOperator) rootRef.getValue(); for (int varIndex = aggOp.getVariables().size() - 1; varIndex >= 0; varIndex--) { if (!usedVarsSoFar.contains(aggOp.getVariables().get(varIndex))) { aggOp.getVariables().remove(varIndex); aggOp.getExpressions().remove(varIndex); } } } } }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushUnnestDownThroughUnionRule.java
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator unnest = (AbstractLogicalOperator) opRef.getValue(); if (unnest.getOperatorTag() != LogicalOperatorTag.UNNEST) { return false; }/* w w w .ja v a 2s . co m*/ UnnestOperator unnestOpRef = (UnnestOperator) opRef.getValue(); Mutable<ILogicalOperator> unionOp = unnest.getInputs().get(0); AbstractLogicalOperator unionAbstractOp = (AbstractLogicalOperator) unionOp.getValue(); if (unionAbstractOp.getOperatorTag() != LogicalOperatorTag.UNIONALL) { return false; } LogicalVariable unnestVar1 = context.newVar(); UnnestOperator unnest1 = new UnnestOperator(unnestVar1, new MutableObject<ILogicalExpression>(unnestOpRef.getExpressionRef().getValue().cloneExpression())); LogicalVariable unnestVar2 = context.newVar(); UnnestOperator unnest2 = new UnnestOperator(unnestVar2, new MutableObject<ILogicalExpression>(unnestOpRef.getExpressionRef().getValue().cloneExpression())); //Getting the two topmost branched and adding them as an input to the unnests: Mutable<ILogicalOperator> branch1 = unionAbstractOp.getInputs().get(0); ILogicalOperator agg1 = branch1.getValue(); List<LogicalVariable> agg1_var = new ArrayList<LogicalVariable>(); VariableUtilities.getLiveVariables(agg1, agg1_var); Mutable<ILogicalOperator> branch2 = unionAbstractOp.getInputs().get(1); ILogicalOperator agg2 = branch2.getValue(); List<LogicalVariable> agg2_var = new ArrayList<LogicalVariable>(); VariableUtilities.getLiveVariables(agg2, agg2_var); //Modifying the unnest so it has the right variable List<LogicalVariable> var_unnest_1 = new ArrayList<LogicalVariable>(); unnest1.getExpressionRef().getValue().getUsedVariables(var_unnest_1); unnest1.getExpressionRef().getValue().substituteVar(var_unnest_1.get(0), agg1_var.get(0)); List<LogicalVariable> var_unnest2 = new ArrayList<LogicalVariable>(); unnest2.getExpressionRef().getValue().getUsedVariables(var_unnest2); unnest2.getExpressionRef().getValue().substituteVar(var_unnest2.get(0), agg2_var.get(0)); unnest1.getInputs().add(branch1); unnest2.getInputs().add(branch2); context.computeAndSetTypeEnvironmentForOperator(unnest1); context.computeAndSetTypeEnvironmentForOperator(unnest2); //creating a new union operator with the updated logical variables List<Triple<LogicalVariable, LogicalVariable, LogicalVariable>> varMap = new ArrayList<Triple<LogicalVariable, LogicalVariable, LogicalVariable>>( 1); Triple<LogicalVariable, LogicalVariable, LogicalVariable> union_triple_vars = new Triple<LogicalVariable, LogicalVariable, LogicalVariable>( unnestVar1, unnestVar2, unnestOpRef.getVariables().get(0)); varMap.add(union_triple_vars); UnionAllOperator unionOpFinal = new UnionAllOperator(varMap); unionOpFinal.getInputs().add(new MutableObject<ILogicalOperator>(unnest1)); unionOpFinal.getInputs().add(new MutableObject<ILogicalOperator>(unnest2)); context.computeAndSetTypeEnvironmentForOperator(unionOpFinal); opRef.setValue(unionOpFinal); return true; }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.AbstractExtractExprRule.java
protected LogicalVariable extractExprIntoAssignOpRef(ILogicalExpression gExpr, Mutable<ILogicalOperator> opRef2, IOptimizationContext context) throws AlgebricksException { LogicalVariable v = context.newVar(); AssignOperator a = new AssignOperator(v, new MutableObject<ILogicalExpression>(gExpr)); a.getInputs().add(new MutableObject<ILogicalOperator>(opRef2.getValue())); opRef2.setValue(a);/*from ww w. j av a 2s.c o m*/ if (gExpr.getExpressionTag() == LogicalExpressionTag.CONSTANT) { context.addNotToBeInlinedVar(v); } context.computeAndSetTypeEnvironmentForOperator(a); return v; }
From source file:edu.uci.ics.asterix.optimizer.rules.RemoveUnusedOneToOneEquiJoinRule.java
private boolean removeUnusedJoin(Mutable<ILogicalOperator> opRef) throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); boolean modified = false; usedVars.clear();/*from w ww . j a v a2 s .c om*/ VariableUtilities.getUsedVariables(op, usedVars); // Propagate used variables from parents downwards. parentsUsedVars.addAll(usedVars); int numInputs = op.getInputs().size(); for (int i = 0; i < numInputs; i++) { Mutable<ILogicalOperator> childOpRef = op.getInputs().get(i); int unusedJoinBranchIndex = removeJoinFromInputBranch(childOpRef); if (unusedJoinBranchIndex >= 0) { int usedBranchIndex = (unusedJoinBranchIndex == 0) ? 1 : 0; // Remove join at input index i, by hooking up op's input i with // the join's branch at unusedJoinBranchIndex. AbstractBinaryJoinOperator joinOp = (AbstractBinaryJoinOperator) childOpRef.getValue(); op.getInputs().set(i, joinOp.getInputs().get(usedBranchIndex)); modified = true; } // Descend into children. if (removeUnusedJoin(childOpRef)) { modified = true; } } return modified; }
From source file:edu.uci.ics.asterix.optimizer.rules.InlineUnnestFunctionRule.java
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue(); if (context.checkIfInDontApplySet(this, op1)) return false; context.addToDontApplySet(this, op1); if (op1.getOperatorTag() != LogicalOperatorTag.UNNEST) return false; UnnestOperator unnestOperator = (UnnestOperator) op1; AbstractFunctionCallExpression expr = (AbstractFunctionCallExpression) unnestOperator.getExpressionRef() .getValue();// ww w . j a v a 2 s . c o m //we only inline for the scan-collection function if (expr.getFunctionIdentifier() != AsterixBuiltinFunctions.SCAN_COLLECTION) return false; // inline all variables from an unnesting function call AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr; List<Mutable<ILogicalExpression>> args = funcExpr.getArguments(); for (int i = 0; i < args.size(); i++) { ILogicalExpression argExpr = args.get(i).getValue(); if (argExpr.getExpressionTag() == LogicalExpressionTag.VARIABLE) { VariableReferenceExpression varExpr = (VariableReferenceExpression) argExpr; inlineVariable(varExpr.getVariableReference(), unnestOperator); } } return true; }