Example usage for org.apache.commons.lang3.mutable Mutable setValue

List of usage examples for org.apache.commons.lang3.mutable Mutable setValue

Introduction

In this page you can find the example usage for org.apache.commons.lang3.mutable Mutable setValue.

Prototype

void setValue(T value);

Source Link

Document

Sets the value of this mutable.

Usage

From source file:org.apache.hyracks.algebricks.rewriter.rules.subplan.IntroduceGroupByForSubplanRule.java

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
        throws AlgebricksException {
    AbstractLogicalOperator op0 = (AbstractLogicalOperator) opRef.getValue();
    if (op0.getOperatorTag() != LogicalOperatorTag.SUBPLAN) {
        return false;
    }/*w  ww.ja  v  a2s .  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> botRef = subplanRoot;
    AbstractLogicalOperator op2;
    // Project is optional
    if (op1.getOperatorTag() != LogicalOperatorTag.PROJECT) {
        op2 = op1;
    } else {
        ProjectOperator project = (ProjectOperator) op1;
        botRef = project.getInputs().get(0);
        op2 = (AbstractLogicalOperator) botRef.getValue();
    }
    if (op2.getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
        return false;
    }
    AggregateOperator aggregate = (AggregateOperator) op2;

    Set<LogicalVariable> free = new HashSet<LogicalVariable>();
    VariableUtilities.getUsedVariables(aggregate, free);

    Mutable<ILogicalOperator> op3Ref = aggregate.getInputs().get(0);
    AbstractLogicalOperator op3 = (AbstractLogicalOperator) op3Ref.getValue();

    while (op3.getInputs().size() == 1) {
        Set<LogicalVariable> prod = new HashSet<LogicalVariable>();
        VariableUtilities.getProducedVariables(op3, prod);
        free.removeAll(prod);
        VariableUtilities.getUsedVariables(op3, free);
        botRef = op3Ref;
        op3Ref = op3.getInputs().get(0);
        op3 = (AbstractLogicalOperator) op3Ref.getValue();
    }

    if (op3.getOperatorTag() != LogicalOperatorTag.INNERJOIN
            && op3.getOperatorTag() != LogicalOperatorTag.LEFTOUTERJOIN) {
        return false;
    }
    AbstractBinaryJoinOperator join = (AbstractBinaryJoinOperator) op3;
    if (join.getCondition().getValue() == ConstantExpression.TRUE) {
        return false;
    }
    VariableUtilities.getUsedVariables(join, free);

    AbstractLogicalOperator b0 = (AbstractLogicalOperator) join.getInputs().get(0).getValue();
    // see if there's an NTS at the end of the pipeline
    NestedTupleSourceOperator outerNts = getNts(b0);
    if (outerNts == null) {
        AbstractLogicalOperator b1 = (AbstractLogicalOperator) join.getInputs().get(1).getValue();
        outerNts = getNts(b1);
        if (outerNts == null) {
            return false;
        }
    }

    Set<LogicalVariable> pkVars = computeGbyVars(outerNts, free, context);
    if (pkVars == null || pkVars.size() < 1) {
        // there is no non-trivial primary key, group-by keys are all live variables
        // that were produced by descendant or self
        ILogicalOperator subplanInput = subplan.getInputs().get(0).getValue();
        pkVars = new HashSet<LogicalVariable>();
        //get live variables
        VariableUtilities.getLiveVariables(subplanInput, pkVars);

        //get produced variables
        Set<LogicalVariable> producedVars = new HashSet<LogicalVariable>();
        VariableUtilities.getProducedVariablesInDescendantsAndSelf(subplanInput, producedVars);

        //retain the intersection
        pkVars.retainAll(producedVars);
    }
    AlgebricksConfig.ALGEBRICKS_LOGGER.fine("Found FD for introducing group-by: " + pkVars);

    Mutable<ILogicalOperator> rightRef = join.getInputs().get(1);
    LogicalVariable testForNull = null;
    AbstractLogicalOperator right = (AbstractLogicalOperator) rightRef.getValue();
    switch (right.getOperatorTag()) {
    case UNNEST: {
        UnnestOperator innerUnnest = (UnnestOperator) right;
        // Select [ $y != null ]
        testForNull = innerUnnest.getVariable();
        break;
    }
    case RUNNINGAGGREGATE: {
        ILogicalOperator inputToRunningAggregate = right.getInputs().get(0).getValue();
        Set<LogicalVariable> producedVars = new ListSet<LogicalVariable>();
        VariableUtilities.getProducedVariables(inputToRunningAggregate, producedVars);
        if (!producedVars.isEmpty()) {
            // Select [ $y != null ]
            testForNull = producedVars.iterator().next();
        }
        break;
    }
    case DATASOURCESCAN: {
        DataSourceScanOperator innerScan = (DataSourceScanOperator) right;
        // Select [ $y != null ]
        if (innerScan.getVariables().size() == 1) {
            testForNull = innerScan.getVariables().get(0);
        }
        break;
    }
    default:
        break;
    }
    if (testForNull == null) {
        testForNull = context.newVar();
        AssignOperator tmpAsgn = new AssignOperator(testForNull,
                new MutableObject<ILogicalExpression>(ConstantExpression.TRUE));
        tmpAsgn.getInputs().add(new MutableObject<ILogicalOperator>(rightRef.getValue()));
        rightRef.setValue(tmpAsgn);
        context.computeAndSetTypeEnvironmentForOperator(tmpAsgn);
    }

    IFunctionInfo finfoEq = context.getMetadataProvider().lookupFunction(AlgebricksBuiltinFunctions.IS_MISSING);
    ILogicalExpression isNullTest = new ScalarFunctionCallExpression(finfoEq,
            new MutableObject<ILogicalExpression>(new VariableReferenceExpression(testForNull)));
    IFunctionInfo finfoNot = context.getMetadataProvider().lookupFunction(AlgebricksBuiltinFunctions.NOT);
    ScalarFunctionCallExpression nonNullTest = new ScalarFunctionCallExpression(finfoNot,
            new MutableObject<ILogicalExpression>(isNullTest));
    SelectOperator selectNonNull = new SelectOperator(new MutableObject<ILogicalExpression>(nonNullTest), false,
            null);
    GroupByOperator g = new GroupByOperator();
    Mutable<ILogicalOperator> newSubplanRef = new MutableObject<ILogicalOperator>(subplan);
    NestedTupleSourceOperator nts = new NestedTupleSourceOperator(new MutableObject<ILogicalOperator>(g));
    opRef.setValue(g);
    selectNonNull.getInputs().add(new MutableObject<ILogicalOperator>(nts));

    List<Mutable<ILogicalOperator>> prodInpList = botRef.getValue().getInputs();
    prodInpList.clear();
    prodInpList.add(new MutableObject<ILogicalOperator>(selectNonNull));

    ILogicalPlan gPlan = new ALogicalPlanImpl(new MutableObject<ILogicalOperator>(subplanRoot.getValue()));
    g.getNestedPlans().add(gPlan);
    subplanRoot.setValue(op3Ref.getValue());
    g.getInputs().add(newSubplanRef);

    HashSet<LogicalVariable> underVars = new HashSet<LogicalVariable>();
    VariableUtilities.getLiveVariables(subplan.getInputs().get(0).getValue(), underVars);
    underVars.removeAll(pkVars);
    Map<LogicalVariable, LogicalVariable> mappedVars = buildVarExprList(pkVars, context, g, g.getGroupByList());
    context.updatePrimaryKeys(mappedVars);
    for (LogicalVariable uv : underVars) {
        g.getDecorList().add(new Pair<LogicalVariable, Mutable<ILogicalExpression>>(null,
                new MutableObject<ILogicalExpression>(new VariableReferenceExpression(uv))));
    }
    OperatorPropertiesUtil.typeOpRec(subplanRoot, context);
    OperatorPropertiesUtil.typeOpRec(gPlan.getRoots().get(0), context);
    context.computeAndSetTypeEnvironmentForOperator(g);
    return true;
}

From source file:org.apache.hyracks.algebricks.rewriter.rules.subplan.IntroduceLeftOuterJoinForSubplanRule.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  .  java 2 s.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.isMissingTest((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:org.apache.hyracks.algebricks.rewriter.rules.subplan.NestedSubplanToJoinRule.java

/**
 * rewrite NestedTupleSource operators to EmptyTupleSource operators
 *
 * @param nestedRootRef//from w ww.  j  a  v a  2 s .  com
 */
private void rewriteNestedTupleSource(Mutable<ILogicalOperator> nestedRootRef, IOptimizationContext context)
        throws AlgebricksException {
    AbstractLogicalOperator nestedRoot = (AbstractLogicalOperator) nestedRootRef.getValue();
    if (nestedRoot.getOperatorTag() == LogicalOperatorTag.NESTEDTUPLESOURCE) {
        ILogicalOperator ets = new EmptyTupleSourceOperator();
        nestedRootRef.setValue(ets);
        context.computeAndSetTypeEnvironmentForOperator(ets);
    }
    List<Mutable<ILogicalOperator>> inputs = nestedRoot.getInputs();
    for (Mutable<ILogicalOperator> input : inputs) {
        rewriteNestedTupleSource(input, context);
    }
}

From source file:org.apache.hyracks.algebricks.rewriter.rules.subplan.ReplaceNtsWithSubplanInputOperatorVisitor.java

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();/* w w  w  .  java 2 s . c  o  m*/
    }

    // 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;
}

From source file:org.apache.hyracks.algebricks.rewriter.rules.subplan.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  w w. j ava  2 s  . co  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.isMissingTest(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:org.apache.hyracks.algebricks.rewriter.rules.SwitchInnerJoinBranchRule.java

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
        throws AlgebricksException {
    ILogicalOperator op = opRef.getValue();
    if (op.getOperatorTag() != LogicalOperatorTag.INNERJOIN) {
        return false;
    }//from w w  w.  j a  v  a 2 s  .  com
    InnerJoinOperator joinOperator = (InnerJoinOperator) op;
    Mutable<ILogicalOperator> leftRef = joinOperator.getInputs().get(0);
    Mutable<ILogicalOperator> rightRef = joinOperator.getInputs().get(1);
    ILogicalOperator left = leftRef.getValue();
    ILogicalOperator right = rightRef.getValue();
    boolean leftCardinalityOne = OperatorPropertiesUtil.isCardinalityZeroOrOne(left);
    boolean rightCardinalityOne = OperatorPropertiesUtil.isCardinalityZeroOrOne(right);
    if (!leftCardinalityOne || rightCardinalityOne) {
        return false;
    }
    // The cardinality of the left branch is one and the cardinality of the right branch is not one.
    leftRef.setValue(right);
    rightRef.setValue(left);
    return true;
}

From source file:org.apache.hyracks.algebricks.rewriter.util.JoinUtils.java

public static void setJoinAlgorithmAndExchangeAlgo(AbstractBinaryJoinOperator op, IOptimizationContext context)
        throws AlgebricksException {
    List<LogicalVariable> sideLeft = new LinkedList<>();
    List<LogicalVariable> sideRight = new LinkedList<>();
    List<LogicalVariable> varsLeft = op.getInputs().get(0).getValue().getSchema();
    List<LogicalVariable> varsRight = op.getInputs().get(1).getValue().getSchema();
    if (isHashJoinCondition(op.getCondition().getValue(), varsLeft, varsRight, sideLeft, sideRight)) {
        BroadcastSide side = getBroadcastJoinSide(op.getCondition().getValue(), varsLeft, varsRight);
        if (side == null) {
            setHashJoinOp(op, JoinPartitioningType.PAIRWISE, sideLeft, sideRight, context);
        } else {/*from ww w .ja va  2s.c om*/
            switch (side) {
            case RIGHT:
                setHashJoinOp(op, JoinPartitioningType.BROADCAST, sideLeft, sideRight, context);
                break;
            case LEFT:
                Mutable<ILogicalOperator> opRef0 = op.getInputs().get(0);
                Mutable<ILogicalOperator> opRef1 = op.getInputs().get(1);
                ILogicalOperator tmp = opRef0.getValue();
                opRef0.setValue(opRef1.getValue());
                opRef1.setValue(tmp);
                setHashJoinOp(op, JoinPartitioningType.BROADCAST, sideRight, sideLeft, context);
                break;
            default:
                setHashJoinOp(op, JoinPartitioningType.PAIRWISE, sideLeft, sideRight, context);
            }
        }
    } else {
        setNestedLoopJoinOp(op, context);
    }
}

From source file:org.apache.vxquery.compiler.rewriter.algebricks_new_version.NestGroupByRule.java

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
        throws AlgebricksException {
    AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue();
    if (op1.getOperatorTag() != LogicalOperatorTag.SUBPLAN) {
        return false;
    }/*from   w w w .j a  va2 s. c  om*/
    SubplanOperator subplan = (SubplanOperator) op1;
    if (subplan.getNestedPlans().size() != 1) {
        return false;
    }
    ILogicalPlan p = subplan.getNestedPlans().get(0);
    if (p.getRoots().size() != 1) {
        return false;
    }

    Set<LogicalVariable> free = new HashSet<LogicalVariable>();
    OperatorPropertiesUtil.getFreeVariablesInSubplans(subplan, free);
    if (free.size() != 1) {
        return false;
    }
    LogicalVariable fVar = null;
    for (LogicalVariable v : free) {
        fVar = v;
        break;
    }

    AbstractLogicalOperator op2 = (AbstractLogicalOperator) op1.getInputs().get(0).getValue();
    if (op2.getOperatorTag() != LogicalOperatorTag.GROUP) {
        return false;
    }
    GroupByOperator gby = (GroupByOperator) op2;
    if (gby.getNestedPlans().size() != 1) {
        return false;
    }
    ILogicalPlan p2 = gby.getNestedPlans().get(0);
    if (p2.getRoots().size() != 1) {
        return false;
    }
    Mutable<ILogicalOperator> r2 = p2.getRoots().get(0);
    AbstractLogicalOperator opr2 = (AbstractLogicalOperator) r2.getValue();
    if (opr2.getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
        return false;
    }
    AggregateOperator aggOuter = (AggregateOperator) opr2;
    int posInAggList = aggOuter.getVariables().indexOf(fVar);
    if (posInAggList < 0) {
        return false;
    }
    AbstractLogicalOperator outerAggSon = (AbstractLogicalOperator) aggOuter.getInputs().get(0).getValue();
    if (outerAggSon.getOperatorTag() != LogicalOperatorTag.NESTEDTUPLESOURCE) {
        return false;
    }
    ILogicalExpression eAgg = aggOuter.getExpressions().get(posInAggList).getValue();
    if (eAgg.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
        return false;
    }
    AbstractFunctionCallExpression listifyCall = (AbstractFunctionCallExpression) eAgg;
    if (listifyCall.getFunctionIdentifier() != BuiltinOperators.SEQUENCE.getFunctionIdentifier()) {
        return false;
    }
    ILogicalExpression argListify = listifyCall.getArguments().get(0).getValue();
    if (argListify.getExpressionTag() != LogicalExpressionTag.VARIABLE) {
        return false;
    }

    Mutable<ILogicalOperator> r = p.getRoots().get(0);
    AbstractLogicalOperator opInS = (AbstractLogicalOperator) r.getValue();
    if (opInS.getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
        return false;
    }
    AggregateOperator aggInner = (AggregateOperator) opInS;
    do {
        opInS = (AbstractLogicalOperator) opInS.getInputs().get(0).getValue();
    } while (opInS.getOperatorTag() == LogicalOperatorTag.ASSIGN);
    if (opInS.getOperatorTag() != LogicalOperatorTag.GROUP) {
        return false;
    }
    AbstractLogicalOperator unnestParent = opInS;
    AbstractLogicalOperator opUnder = (AbstractLogicalOperator) opInS.getInputs().get(0).getValue();
    // skip Assigns
    while (opUnder.getOperatorTag() == LogicalOperatorTag.ASSIGN) {
        unnestParent = opUnder;
        opUnder = (AbstractLogicalOperator) opUnder.getInputs().get(0).getValue();
    }
    if (opUnder.getOperatorTag() != LogicalOperatorTag.UNNEST) {
        return false;
    }
    UnnestOperator unnest = (UnnestOperator) opUnder;
    AbstractLogicalOperator unnestSon = (AbstractLogicalOperator) unnest.getInputs().get(0).getValue();
    if (unnestSon.getOperatorTag() != LogicalOperatorTag.NESTEDTUPLESOURCE) {
        return false;
    }
    NestedTupleSourceOperator innerNts = (NestedTupleSourceOperator) unnestSon;

    ILogicalExpression eUnnest = unnest.getExpressionRef().getValue();
    if (eUnnest.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
        return false;
    }
    AbstractFunctionCallExpression uf = (AbstractFunctionCallExpression) eUnnest;
    if (uf.getFunctionIdentifier() != BuiltinOperators.ITERATE.getFunctionIdentifier()) {
        return false;
    }
    ILogicalExpression scanArg = uf.getArguments().get(0).getValue();
    if (scanArg.getExpressionTag() != LogicalExpressionTag.VARIABLE) {
        return false;
    }
    if (((VariableReferenceExpression) scanArg).getVariableReference() != fVar) {
        return false;
    }
    LogicalVariable uVar = unnest.getVariable();
    GroupByOperator innerGby = (GroupByOperator) opInS;
    Set<LogicalVariable> freeInInnerGby = new HashSet<LogicalVariable>();
    OperatorPropertiesUtil.getFreeVariablesInSubplans(innerGby, freeInInnerGby);
    for (LogicalVariable v : freeInInnerGby) {
        if (v != uVar) {
            return false;
        }
    }

    unnestParent.getInputs().get(0).setValue(innerNts);
    LogicalVariable listifiedVar = ((VariableReferenceExpression) argListify).getVariableReference();
    substInSubplan(aggInner, uVar, listifiedVar, context);
    gby.getNestedPlans().add(p);
    innerNts.getDataSourceReference().setValue(gby);
    opRef.setValue(gby);
    OperatorPropertiesUtil.typePlan(p, context);
    OperatorPropertiesUtil.typePlan(p2, context);
    context.computeAndSetTypeEnvironmentForOperator(gby);
    return true;

}

From source file:org.apache.vxquery.compiler.rewriter.rules.AbstractPushExpressionIntoDatascanRule.java

protected boolean processOperator(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
        throws AlgebricksException {
    boolean unnestOp = false;
    boolean assignOp = false;

    UnnestOperator unnest = null;/*from  ww w  .  j a va2s.  com*/
    AssignOperator assign = null;
    AbstractLogicalOperator op2 = null;

    if (dCtx == null) {
        VXQueryOptimizationContext vxqueryCtx = (VXQueryOptimizationContext) context;
        dCtx = ((VXQueryMetadataProvider) vxqueryCtx.getMetadataProvider()).getStaticContext();
    }
    AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue();
    if (!(op1.getOperatorTag() == getOperator())) {
        return false;
    }
    if (op1.getOperatorTag() == LogicalOperatorTag.UNNEST) {
        unnest = (UnnestOperator) op1;
        unnestOp = true;
        op2 = (AbstractLogicalOperator) unnest.getInputs().get(0).getValue();
    } else {
        assign = (AssignOperator) op1;
        assignOp = true;
        op2 = (AbstractLogicalOperator) assign.getInputs().get(0).getValue();
    }

    if (op2.getOperatorTag() != LogicalOperatorTag.DATASOURCESCAN) {
        return false;
    }
    DataSourceScanOperator datascan = (DataSourceScanOperator) op2;

    if (!usedVariables.contains(datascan.getVariables())) {

        Mutable<ILogicalExpression> expressionRef = null;
        if (unnestOp) {
            expressionRef = unnest.getExpressionRef();
        } else if (assignOp) {
            expressionRef = assign.getExpressions().get(0);
        }
        if (!(updateDataSource((IVXQueryDataSource) datascan.getDataSource(), expressionRef))) {
            return false;
        }
        if (unnestOp) {
            Mutable<ILogicalExpression> varExp = ExpressionToolbox.findVariableExpression(expressionRef,
                    datascan.getVariables().get(0));
            AssignOperator noOp = new AssignOperator(unnest.getVariable(), varExp);
            noOp.getInputs().addAll(unnest.getInputs());
            opRef.setValue(noOp);
        } else if (assignOp) {
            Mutable<ILogicalExpression> varExp = ExpressionToolbox
                    .findVariableExpression(assign.getExpressions().get(0), datascan.getVariables().get(0));
            AssignOperator noOp = new AssignOperator(assign.getVariables().get(0), varExp);
            noOp.getInputs().addAll(assign.getInputs());
            opRef.setValue(noOp);
        }

        return true;
    }
    return false;

}

From source file:org.apache.vxquery.compiler.rewriter.rules.AbstractRemoveRedundantTypeExpressionsRule.java

private boolean processTypeExpression(Mutable<ILogicalOperator> opRef, Mutable<ILogicalExpression> search) {
    boolean modified = false;
    SequenceType inputSequenceType;//from   ww w.ja v  a2s . c  om
    SequenceType sTypeArg;
    functionList.clear();
    ExpressionToolbox.findAllFunctionExpressions(search, getSearchFunction(), functionList);
    for (Mutable<ILogicalExpression> searchM : functionList) {
        // Get input function
        AbstractFunctionCallExpression searchFunction = (AbstractFunctionCallExpression) searchM.getValue();
        Mutable<ILogicalExpression> argFirstM = searchFunction.getArguments().get(ARG_DATA);

        // Find the input return type.
        inputSequenceType = ExpressionToolbox.getOutputSequenceType(opRef, argFirstM, dCtx);

        // Find the argument type.
        sTypeArg = null;
        if (hasTypeArgument()) {
            sTypeArg = ExpressionToolbox.getTypeExpressionTypeArgument(searchM, dCtx);
        }

        // remove
        if (matchesAllInstancesOf(sTypeArg, inputSequenceType)) {
            searchM.setValue(argFirstM.getValue());
            modified = true;
        }
    }
    return modified;
}