List of usage examples for org.apache.commons.lang3.mutable Mutable getValue
T getValue();
From source file:edu.uci.ics.asterix.optimizer.rules.DisjunctivePredicateToJoinRule.java
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { SelectOperator select;//from www . j a va 2 s. c om if ((select = asSelectOperator(opRef)) == null) { return false; } AbstractFunctionCallExpression condEx; if ((condEx = asFunctionCallExpression(select.getCondition(), AlgebricksBuiltinFunctions.OR)) == null) { return false; } List<Mutable<ILogicalExpression>> args = condEx.getArguments(); VariableReferenceExpression varEx = null; IAType valType = null; HashSet<AsterixConstantValue> values = new HashSet<AsterixConstantValue>(); for (Mutable<ILogicalExpression> arg : args) { AbstractFunctionCallExpression fctCall; if ((fctCall = asFunctionCallExpression(arg, AlgebricksBuiltinFunctions.EQ)) == null) { return false; } boolean haveConst = false; boolean haveVar = false; List<Mutable<ILogicalExpression>> fctArgs = fctCall.getArguments(); for (Mutable<ILogicalExpression> fctArg : fctArgs) { final ILogicalExpression argExpr = fctArg.getValue(); switch (argExpr.getExpressionTag()) { case CONSTANT: haveConst = true; AsterixConstantValue value = (AsterixConstantValue) ((ConstantExpression) argExpr).getValue(); if (valType == null) { valType = value.getObject().getType(); } else if (!isCompatible(valType, value.getObject().getType())) { return false; } values.add(value); break; case VARIABLE: haveVar = true; final VariableReferenceExpression varArg = (VariableReferenceExpression) argExpr; if (varEx == null) { varEx = varArg; } else if (!varEx.getVariableReference().equals(varArg.getVariableReference())) { return false; } break; default: return false; } } if (!(haveVar && haveConst)) { return false; } } AOrderedList list = new AOrderedList(new AOrderedListType(valType, "orderedlist")); for (AsterixConstantValue value : values) { list.add(value.getObject()); } EmptyTupleSourceOperator ets = new EmptyTupleSourceOperator(); context.computeAndSetTypeEnvironmentForOperator(ets); ILogicalExpression cExp = new ConstantExpression(new AsterixConstantValue(list)); Mutable<ILogicalExpression> mutCExp = new MutableObject<ILogicalExpression>(cExp); IFunctionInfo scanFctInfo = AsterixBuiltinFunctions .getAsterixFunctionInfo(AsterixBuiltinFunctions.SCAN_COLLECTION); UnnestingFunctionCallExpression scanExp = new UnnestingFunctionCallExpression(scanFctInfo, mutCExp); LogicalVariable scanVar = context.newVar(); UnnestOperator unn = new UnnestOperator(scanVar, new MutableObject<ILogicalExpression>(scanExp)); unn.getInputs().add(new MutableObject<ILogicalOperator>(ets)); context.computeAndSetTypeEnvironmentForOperator(unn); IFunctionInfo eqFctInfo = AsterixBuiltinFunctions.getAsterixFunctionInfo(AlgebricksBuiltinFunctions.EQ); AbstractFunctionCallExpression eqExp = new ScalarFunctionCallExpression(eqFctInfo); eqExp.getArguments().add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(scanVar))); eqExp.getArguments().add(new MutableObject<ILogicalExpression>(varEx.cloneExpression())); eqExp.getAnnotations().put(IndexedNLJoinExpressionAnnotation.INSTANCE, IndexedNLJoinExpressionAnnotation.INSTANCE); InnerJoinOperator jOp = new InnerJoinOperator(new MutableObject<ILogicalExpression>(eqExp)); jOp.getInputs().add(new MutableObject<ILogicalOperator>(unn)); jOp.getInputs().add(select.getInputs().get(0)); opRef.setValue(jOp); context.computeAndSetTypeEnvironmentForOperator(jOp); return true; }
From source file:edu.uci.ics.asterix.optimizer.rules.PushGroupByThroughProduct.java
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue(); if (op1.getOperatorTag() != LogicalOperatorTag.GROUP) { return false; }/* ww w . j a va 2 s . c o m*/ Mutable<ILogicalOperator> opRef2 = op1.getInputs().get(0); AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue(); if (op2.getOperatorTag() != LogicalOperatorTag.INNERJOIN) { return false; } InnerJoinOperator join = (InnerJoinOperator) op2; if (!OperatorPropertiesUtil.isAlwaysTrueCond(join.getCondition().getValue())) { // not a product return false; } GroupByOperator gby = (GroupByOperator) op1; List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> decorToPush = new ArrayList<Pair<LogicalVariable, Mutable<ILogicalExpression>>>(); List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> decorNotToPush = new ArrayList<Pair<LogicalVariable, Mutable<ILogicalExpression>>>(); Mutable<ILogicalOperator> opLeftRef = join.getInputs().get(0); ILogicalOperator opLeft = opLeftRef.getValue(); switch (canPushThrough(gby, opLeft, decorToPush, decorNotToPush)) { case REPEATED_DECORS: { return false; } case TRUE: { push(opRef, opRef2, 0, decorToPush, decorNotToPush, context); return true; } case FALSE: { decorToPush.clear(); Mutable<ILogicalOperator> opRightRef = join.getInputs().get(1); ILogicalOperator opRight = opRightRef.getValue(); if (canPushThrough(gby, opRight, decorToPush, decorNotToPush) == PushTestResult.TRUE) { push(opRef, opRef2, 1, decorToPush, decorNotToPush, context); return true; } else { return false; } } default: { throw new IllegalStateException(); } } }
From source file:edu.uci.ics.asterix.optimizer.rules.PushAggFuncIntoStandaloneAggregateRule.java
private boolean fingAggFuncExprRef(List<Mutable<ILogicalExpression>> exprRefs, LogicalVariable aggVar, List<Mutable<ILogicalExpression>> srcAssignExprRefs) { for (Mutable<ILogicalExpression> exprRef : exprRefs) { ILogicalExpression expr = exprRef.getValue(); if (expr.getExpressionTag() == LogicalExpressionTag.VARIABLE) { if (((VariableReferenceExpression) expr).getVariableReference().equals(aggVar)) { return false; }//from www . j a v a 2s . c o m } if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) { continue; } AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr; FunctionIdentifier funcIdent = AsterixBuiltinFunctions .getAggregateFunction(funcExpr.getFunctionIdentifier()); if (funcIdent == null) { // Recursively look in func args. if (fingAggFuncExprRef(funcExpr.getArguments(), aggVar, srcAssignExprRefs) == false) { return false; } } else { // Check if this is the expr that uses aggVar. Collection<LogicalVariable> usedVars = new HashSet<LogicalVariable>(); funcExpr.getUsedVariables(usedVars); if (usedVars.contains(aggVar)) { srcAssignExprRefs.add(exprRef); } } } return true; }
From source file:edu.uci.ics.hyracks.algebricks.core.algebra.operators.physical.IndexInsertDeletePOperator.java
public IndexInsertDeletePOperator(List<LogicalVariable> primaryKeys, List<LogicalVariable> secondaryKeys, List<LogicalVariable> additionalFilteringKeys, Mutable<ILogicalExpression> filterExpr, IDataSourceIndex<?, ?> dataSourceIndex) { this.primaryKeys = primaryKeys; this.secondaryKeys = secondaryKeys; if (filterExpr != null) { this.filterExpr = filterExpr.getValue(); } else {/*from w w w . ja v a 2s . co m*/ this.filterExpr = null; } this.dataSourceIndex = dataSourceIndex; this.additionalFilteringKeys = additionalFilteringKeys; }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushAssignBelowUnionAllRule.java
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (!op.hasInputs()) { return false; }//from w w w . j av a 2 s. c om boolean modified = false; for (int i = 0; i < op.getInputs().size(); i++) { AbstractLogicalOperator childOp = (AbstractLogicalOperator) op.getInputs().get(i).getValue(); if (childOp.getOperatorTag() != LogicalOperatorTag.ASSIGN) { continue; } AssignOperator assignOp = (AssignOperator) childOp; for (Mutable<ILogicalExpression> expr : assignOp.getExpressions()) { if (!expr.getValue().isFunctional()) { return false; } } AbstractLogicalOperator childOfChildOp = (AbstractLogicalOperator) assignOp.getInputs().get(0) .getValue(); if (childOfChildOp.getOperatorTag() != LogicalOperatorTag.UNIONALL) { continue; } UnionAllOperator unionOp = (UnionAllOperator) childOfChildOp; Set<LogicalVariable> assignUsedVars = new HashSet<LogicalVariable>(); VariableUtilities.getUsedVariables(assignOp, assignUsedVars); List<LogicalVariable> assignVars = assignOp.getVariables(); AssignOperator[] newAssignOps = new AssignOperator[2]; for (int j = 0; j < unionOp.getInputs().size(); j++) { newAssignOps[j] = createAssignBelowUnionAllBranch(unionOp, j, assignOp, assignUsedVars, context); } // Add original assign variables to the union variable mappings. for (int j = 0; j < assignVars.size(); j++) { LogicalVariable first = newAssignOps[0].getVariables().get(j); LogicalVariable second = newAssignOps[1].getVariables().get(j); Triple<LogicalVariable, LogicalVariable, LogicalVariable> varMapping = new Triple<LogicalVariable, LogicalVariable, LogicalVariable>( first, second, assignVars.get(j)); unionOp.getVariableMappings().add(varMapping); } context.computeAndSetTypeEnvironmentForOperator(unionOp); // Remove original assign operator. op.getInputs().set(i, assignOp.getInputs().get(0)); context.computeAndSetTypeEnvironmentForOperator(op); modified = true; } return modified; }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushFunctionsBelowJoin.java
private void gatherFunctionCalls(Mutable<ILogicalExpression> exprRef, List<Mutable<ILogicalExpression>> funcExprs) { AbstractLogicalExpression expr = (AbstractLogicalExpression) exprRef.getValue(); if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) { return;/*from w ww .j av a 2 s . c o m*/ } // Check whether the function is a function we want to push. AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr; if (toPushFuncIdents.contains(funcExpr.getFunctionIdentifier())) { funcExprs.add(exprRef); } // Traverse arguments. for (Mutable<ILogicalExpression> funcArg : funcExpr.getArguments()) { gatherFunctionCalls(funcArg, funcExprs); } }
From source file:edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.visitors.ProducedVariableVisitor.java
@Override public Void visitGroupByOperator(GroupByOperator op, Void arg) throws AlgebricksException { for (ILogicalPlan p : op.getNestedPlans()) { for (Mutable<ILogicalOperator> r : p.getRoots()) { VariableUtilities.getLiveVariables(r.getValue(), producedVariables); }//from w ww .j a v a2 s. c o m } for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : op.getGroupByList()) { if (p.first != null) { producedVariables.add(p.first); } } for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : op.getDecorList()) { if (p.first != null) { producedVariables.add(p.first); } } return null; }
From source file:edu.uci.ics.asterix.optimizer.rules.am.IntroduceSelectAccessMethodRule.java
protected boolean matchesOperatorPattern(Mutable<ILogicalOperator> opRef, IOptimizationContext context) { // First check that the operator is a select and its condition is a function call. AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue(); if (context.checkIfInDontApplySet(this, op1)) { return false; }//from w ww. ja v a2 s . c o m if (op1.getOperatorTag() != LogicalOperatorTag.SELECT) { return false; } // Set and analyze select. selectRef = opRef; select = (SelectOperator) op1; // Check that the select's condition is a function call. ILogicalExpression condExpr = select.getCondition().getValue(); if (condExpr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) { return false; } selectCond = (AbstractFunctionCallExpression) condExpr; boolean res = subTree.initFromSubTree(op1.getInputs().get(0)); return res && subTree.hasDataSourceScan(); }
From source file:edu.uci.ics.asterix.optimizer.rules.RemoveUnusedOneToOneEquiJoinRule.java
private int removeJoinFromInputBranch(Mutable<ILogicalOperator> opRef) throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (op.getOperatorTag() != LogicalOperatorTag.INNERJOIN) { return -1; }/* w w w . j a v a 2 s.c o m*/ AbstractBinaryJoinOperator joinOp = (AbstractBinaryJoinOperator) op; // Make sure the join is an equi-join. if (!isEquiJoin(joinOp.getCondition())) { return -1; } int unusedJoinBranchIndex = -1; for (int i = 0; i < joinOp.getInputs().size(); i++) { liveVars.clear(); VariableUtilities.getLiveVariables(joinOp.getInputs().get(i).getValue(), liveVars); liveVars.retainAll(parentsUsedVars); if (liveVars.isEmpty()) { // None of the live variables from this branch are used by its parents. unusedJoinBranchIndex = i; break; } } if (unusedJoinBranchIndex < 0) { // The variables from both branches are used in the upstream plan. We cannot remove this join. return -1; } // Check whether one of the join branches is unused. usedVars.clear(); VariableUtilities.getUsedVariables(joinOp, usedVars); // Check whether all used variables originate from primary keys of exactly the same dataset. // Collect a list of datascans whose primary key variables are used in the join condition. gatherProducingDataScans(opRef, usedVars, dataScans); // Check that all datascans scan the same dataset, and that the join condition // only used primary key variables of those datascans. for (int i = 0; i < dataScans.size(); i++) { if (i > 0) { DatasetDataSource prevAqlDataSource = (DatasetDataSource) dataScans.get(i - 1).getDataSource(); DatasetDataSource currAqlDataSource = (DatasetDataSource) dataScans.get(i).getDataSource(); if (!prevAqlDataSource.getDataset().equals(currAqlDataSource.getDataset())) { return -1; } } // Remove from the used variables all the primary key vars of this dataset. fillPKVars(dataScans.get(i), pkVars); usedVars.removeAll(pkVars); } if (!usedVars.isEmpty()) { // The join condition also uses some other variables that are not primary // keys from datasource scans of the same dataset. return -1; } return unusedJoinBranchIndex; }
From source file:edu.uci.ics.hyracks.algebricks.core.algebra.operators.physical.SortGroupByPOperator.java
@Override public void computeDeliveredProperties(ILogicalOperator op, IOptimizationContext context) { List<ILocalStructuralProperty> propsLocal = new LinkedList<ILocalStructuralProperty>(); GroupByOperator gOp = (GroupByOperator) op; Set<LogicalVariable> columnSet = new ListSet<LogicalVariable>(); List<OrderColumn> ocs = new ArrayList<OrderColumn>(); if (!columnSet.isEmpty()) { propsLocal.add(new LocalGroupingProperty(columnSet)); }/*from w w w. j av a 2 s . c om*/ for (OrderColumn oc : orderColumns) { ocs.add(oc); } propsLocal.add(new LocalOrderProperty(ocs)); for (ILogicalPlan p : gOp.getNestedPlans()) { for (Mutable<ILogicalOperator> r : p.getRoots()) { ILogicalOperator rOp = r.getValue(); propsLocal.addAll(rOp.getDeliveredPhysicalProperties().getLocalProperties()); } } ILogicalOperator op2 = op.getInputs().get(0).getValue(); IPhysicalPropertiesVector childProp = op2.getDeliveredPhysicalProperties(); deliveredProperties = new StructuralPropertiesVector(childProp.getPartitioningProperty(), propsLocal); }