List of usage examples for org.apache.commons.lang3.mutable Mutable getValue
T getValue();
From source file:edu.uci.ics.asterix.optimizer.rules.CountVarToCountOneRule.java
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue(); if (op1.getOperatorTag() != LogicalOperatorTag.GROUP) { return false; }/*from www.j av a 2 s . c o m*/ GroupByOperator g = (GroupByOperator) op1; if (g.getNestedPlans().size() != 1) { return false; } ILogicalPlan p = g.getNestedPlans().get(0); if (p.getRoots().size() != 1) { return false; } AbstractLogicalOperator op2 = (AbstractLogicalOperator) p.getRoots().get(0).getValue(); if (op2.getOperatorTag() != LogicalOperatorTag.AGGREGATE) { return false; } AggregateOperator agg = (AggregateOperator) op2; if (agg.getExpressions().size() != 1) { return false; } ILogicalExpression exp2 = agg.getExpressions().get(0).getValue(); if (exp2.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) { return false; } AbstractFunctionCallExpression fun = (AbstractFunctionCallExpression) exp2; if (fun.getFunctionIdentifier() != AsterixBuiltinFunctions.COUNT) { return false; } ILogicalExpression exp3 = fun.getArguments().get(0).getValue(); if (exp3.getExpressionTag() != LogicalExpressionTag.VARIABLE) { return false; } if (((AbstractLogicalOperator) agg.getInputs().get(0).getValue()) .getOperatorTag() != LogicalOperatorTag.NESTEDTUPLESOURCE) { return false; } fun.getArguments().get(0).setValue(new ConstantExpression(new AsterixConstantValue(new AInt64(1L)))); return true; }
From source file:edu.uci.ics.hyracks.algebricks.core.algebra.operators.physical.NestedTupleSourcePOperator.java
@Override public void computeDeliveredProperties(ILogicalOperator op, IOptimizationContext context) { Mutable<ILogicalOperator> dataSource = ((NestedTupleSourceOperator) op).getDataSourceReference(); AbstractLogicalOperator op2 = (AbstractLogicalOperator) dataSource.getValue().getInputs().get(0).getValue(); IPhysicalPropertiesVector inheritedProps = op2.getDeliveredPhysicalProperties(); AbstractLogicalOperator parent = (AbstractLogicalOperator) dataSource.getValue(); if (parent.getOperatorTag() == LogicalOperatorTag.GROUP) { // The following part computes the data property regarding to each particular group. // TODO(buyingyi): we need to add the original data property as well. But currently // there are places assuming there is only one LocalOrderProperty and one // LocalGroupingProperty delivered by an operator. GroupByOperator gby = (GroupByOperator) parent; List<ILocalStructuralProperty> originalLocalProperties = inheritedProps.getLocalProperties(); List<ILocalStructuralProperty> newLocalProperties = null; if (originalLocalProperties != null) { newLocalProperties = new ArrayList<ILocalStructuralProperty>(); for (ILocalStructuralProperty lsp : inheritedProps.getLocalProperties()) { ILocalStructuralProperty newLsp = lsp.regardToGroup(gby.getGbyVarList()); if (newLsp != null) { newLocalProperties.add(newLsp); }/*ww w . ja v a 2 s . c om*/ } } deliveredProperties = new StructuralPropertiesVector(inheritedProps.getPartitioningProperty(), newLocalProperties); } else { deliveredProperties = inheritedProps.clone(); } }
From source file:edu.uci.ics.asterix.optimizer.rules.IntroduceUnionRule.java
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { if (!opRef.getValue().getOperatorTag().equals(LogicalOperatorTag.ASSIGN)) { return false; }/* w ww.ja v a2 s .co m*/ AssignOperator assignUnion = (AssignOperator) opRef.getValue(); if (assignUnion.getExpressions().get(0).getValue().getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) return false; AbstractFunctionCallExpression u = (AbstractFunctionCallExpression) assignUnion.getExpressions().get(0) .getValue(); if (!AsterixBuiltinFunctions.UNION.equals(u.getFunctionIdentifier())) { return false; } //Retrieving the logical variables for the union from the two aggregates which are inputs to the join Mutable<ILogicalOperator> join = assignUnion.getInputs().get(0); LogicalOperatorTag tag1 = join.getValue().getOperatorTag(); if (tag1 != LogicalOperatorTag.INNERJOIN && tag1 != LogicalOperatorTag.LEFTOUTERJOIN) { return false; } AbstractBinaryJoinOperator join1 = (AbstractBinaryJoinOperator) join.getValue(); ILogicalExpression cond1 = join1.getCondition().getValue(); // don't try to push a product down if (!OperatorPropertiesUtil.isAlwaysTrueCond(cond1)) { return false; } List<Mutable<ILogicalOperator>> joinInputs = join.getValue().getInputs(); Mutable<ILogicalOperator> left_branch = joinInputs.get(0); Mutable<ILogicalOperator> right_branch = joinInputs.get(1); List<LogicalVariable> input1Var = new ArrayList<LogicalVariable>(); VariableUtilities.getProducedVariables(left_branch.getValue(), input1Var); List<LogicalVariable> input2Var = new ArrayList<LogicalVariable>(); VariableUtilities.getProducedVariables(right_branch.getValue(), input2Var); List<Triple<LogicalVariable, LogicalVariable, LogicalVariable>> varMap = new ArrayList<Triple<LogicalVariable, LogicalVariable, LogicalVariable>>( 1); Triple<LogicalVariable, LogicalVariable, LogicalVariable> triple = new Triple<LogicalVariable, LogicalVariable, LogicalVariable>( input1Var.get(0), input2Var.get(0), assignUnion.getVariables().get(0)); varMap.add(triple); UnionAllOperator unionOp = new UnionAllOperator(varMap); unionOp.getInputs().add(left_branch); unionOp.getInputs().add(right_branch); context.computeAndSetTypeEnvironmentForOperator(unionOp); opRef.setValue(unionOp); return true; }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.ExtractGbyExpressionsRule.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 if (context.checkIfInDontApplySet(this, op1)) { return false; } context.addToDontApplySet(this, op1); GroupByOperator g = (GroupByOperator) op1; boolean r1 = gbyExprWasRewritten(g, context); boolean r2 = decorExprWasRewritten(g, context); boolean fired = r1 || r2; if (fired) { context.computeAndSetTypeEnvironmentForOperator(g); } return fired; }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushAssignDownThroughProductRule.java
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue(); if (op1.getOperatorTag() != LogicalOperatorTag.ASSIGN) { return false; }//from ww w . j av a 2 s. co m Mutable<ILogicalOperator> op2Ref = op1.getInputs().get(0); AbstractLogicalOperator op2 = (AbstractLogicalOperator) op2Ref.getValue(); if (op2.getOperatorTag() != LogicalOperatorTag.INNERJOIN) { return false; } AbstractBinaryJoinOperator join = (AbstractBinaryJoinOperator) op2; if (join.getCondition().getValue() != ConstantExpression.TRUE) { return false; } List<LogicalVariable> used = new ArrayList<LogicalVariable>(); VariableUtilities.getUsedVariables(op1, used); Mutable<ILogicalOperator> b0Ref = op2.getInputs().get(0); ILogicalOperator b0 = b0Ref.getValue(); List<LogicalVariable> b0Scm = new ArrayList<LogicalVariable>(); VariableUtilities.getLiveVariables(b0, b0Scm); if (b0Scm.containsAll(used)) { // push assign on left branch op2Ref.setValue(b0); b0Ref.setValue(op1); opRef.setValue(op2); return true; } else { Mutable<ILogicalOperator> b1Ref = op2.getInputs().get(1); ILogicalOperator b1 = b1Ref.getValue(); List<LogicalVariable> b1Scm = new ArrayList<LogicalVariable>(); VariableUtilities.getLiveVariables(b1, b1Scm); if (b1Scm.containsAll(used)) { // push assign on right branch op2Ref.setValue(b1); b1Ref.setValue(op1); opRef.setValue(op2); return true; } else { return false; } } }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushMapOperatorDownThroughProductRule.java
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue(); if (!op1.isMap()) { return false; }/* ww w . j av a 2 s . c om*/ Mutable<ILogicalOperator> op2Ref = op1.getInputs().get(0); AbstractLogicalOperator op2 = (AbstractLogicalOperator) op2Ref.getValue(); if (op2.getOperatorTag() != LogicalOperatorTag.INNERJOIN) { return false; } AbstractBinaryJoinOperator join = (AbstractBinaryJoinOperator) op2; if (!OperatorPropertiesUtil.isAlwaysTrueCond(join.getCondition().getValue())) { return false; } List<LogicalVariable> used = new ArrayList<LogicalVariable>(); VariableUtilities.getUsedVariables(op1, used); Mutable<ILogicalOperator> b0Ref = op2.getInputs().get(0); ILogicalOperator b0 = b0Ref.getValue(); List<LogicalVariable> b0Scm = new ArrayList<LogicalVariable>(); VariableUtilities.getLiveVariables(b0, b0Scm); if (b0Scm.containsAll(used)) { // push operator on left branch op2Ref.setValue(b0); b0Ref.setValue(op1); opRef.setValue(op2); return true; } else { Mutable<ILogicalOperator> b1Ref = op2.getInputs().get(1); ILogicalOperator b1 = b1Ref.getValue(); List<LogicalVariable> b1Scm = new ArrayList<LogicalVariable>(); VariableUtilities.getLiveVariables(b1, b1Scm); if (b1Scm.containsAll(used)) { // push operator on right branch op2Ref.setValue(b1); b1Ref.setValue(op1); opRef.setValue(op2); return true; } else { return false; } } }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushUnnestDownThroughProductRule.java
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue(); if (op1.getOperatorTag() != LogicalOperatorTag.UNNEST) { return false; }/* ww w.j a v a2s . c o m*/ Mutable<ILogicalOperator> op2Ref = op1.getInputs().get(0); AbstractLogicalOperator op2 = (AbstractLogicalOperator) op2Ref.getValue(); if (op2.getOperatorTag() != LogicalOperatorTag.INNERJOIN) { return false; } AbstractBinaryJoinOperator join = (AbstractBinaryJoinOperator) op2; if (join.getCondition().getValue() != ConstantExpression.TRUE) { return false; } List<LogicalVariable> used = new ArrayList<LogicalVariable>(); VariableUtilities.getUsedVariables(op1, used); Mutable<ILogicalOperator> b0Ref = op2.getInputs().get(0); ILogicalOperator b0 = b0Ref.getValue(); List<LogicalVariable> b0Scm = new ArrayList<LogicalVariable>(); VariableUtilities.getLiveVariables(b0, b0Scm); if (b0Scm.containsAll(used)) { // push unnest on left branch op2Ref.setValue(b0); b0Ref.setValue(op1); opRef.setValue(op2); return true; } else { Mutable<ILogicalOperator> b1Ref = op2.getInputs().get(1); ILogicalOperator b1 = b1Ref.getValue(); List<LogicalVariable> b1Scm = new ArrayList<LogicalVariable>(); VariableUtilities.getLiveVariables(b1, b1Scm); if (b1Scm.containsAll(used)) { // push unnest on right branch op2Ref.setValue(b1); b1Ref.setValue(op1); opRef.setValue(op2); return true; } else { return false; } } }
From source file:edu.uci.ics.asterix.optimizer.rules.IntroduceUnnestForCollectionToSequenceRule.java
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (op.getOperatorTag() != LogicalOperatorTag.ASSIGN) { return false; }//from w w w . j av a 2s. co m AssignOperator assign = (AssignOperator) op; List<Mutable<ILogicalExpression>> exprs = assign.getExpressions(); if (exprs.size() != 1) { return false; } ILogicalExpression expr = exprs.get(0).getValue(); if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) { return false; } AbstractFunctionCallExpression func = (AbstractFunctionCallExpression) expr; if (func.getFunctionIdentifier() != AsterixBuiltinFunctions.COLLECTION_TO_SEQUENCE) { return false; } IVariableTypeEnvironment env = assign.computeInputTypeEnvironment(context); ILogicalExpression argExpr = func.getArguments().get(0).getValue(); IAType outerExprType = (IAType) env.getType(expr); IAType innerExprType = (IAType) env.getType(argExpr); if (outerExprType.equals(innerExprType)) { /** nothing is changed with the collection-to-sequence function, remove the collection-sequence function call */ assign.getExpressions().set(0, new MutableObject<ILogicalExpression>(argExpr)); return true; } /** change the assign operator to an unnest operator */ LogicalVariable var = assign.getVariables().get(0); @SuppressWarnings("unchecked") UnnestOperator unnest = new UnnestOperator(var, new MutableObject<ILogicalExpression>(new UnnestingFunctionCallExpression( FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.SCAN_COLLECTION), new MutableObject<ILogicalExpression>(argExpr)))); unnest.getInputs().addAll(assign.getInputs()); opRef.setValue(unnest); context.computeAndSetTypeEnvironmentForOperator(unnest); return true; }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.EliminateSubplanRule.java
private void elimSubplanOverEts(Mutable<ILogicalOperator> opRef, IOptimizationContext ctx) throws AlgebricksException { SubplanOperator subplan = (SubplanOperator) opRef.getValue(); for (ILogicalPlan p : subplan.getNestedPlans()) { for (Mutable<ILogicalOperator> r : p.getRoots()) { OperatorManipulationUtil.ntsToEts(r, ctx); }//from ww w. jav a 2 s. co m } LinkedList<Mutable<ILogicalOperator>> allRoots = subplan.allRootsInReverseOrder(); if (allRoots.size() == 1) { opRef.setValue(allRoots.get(0).getValue()); } else { ILogicalOperator topOp = null; for (Mutable<ILogicalOperator> r : allRoots) { if (topOp == null) { topOp = r.getValue(); } else { LeftOuterJoinOperator j = new LeftOuterJoinOperator( new MutableObject<ILogicalExpression>(ConstantExpression.TRUE)); j.getInputs().add(new MutableObject<ILogicalOperator>(topOp)); j.getInputs().add(r); ctx.setOutputTypeEnvironment(j, j.computeOutputTypeEnvironment(ctx)); topOp = j; } } opRef.setValue(topOp); } }
From source file:edu.uci.ics.asterix.optimizer.rules.AddEquivalenceClassForRecordConstructorRule.java
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (op.getOperatorTag() != LogicalOperatorTag.ASSIGN) { return false; }// w ww .ja v a 2 s . com // Computes FDs and equivalence classes for the operator. PhysicalOptimizationsUtil.computeFDsAndEquivalenceClasses(op, context); AssignOperator assignOp = (AssignOperator) op; List<LogicalVariable> vars = assignOp.getVariables(); List<Mutable<ILogicalExpression>> exprRefs = assignOp.getExpressions(); return addEquivalenceClassesForRecordConstructor(vars, exprRefs, assignOp, context); }