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

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

Introduction

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

Prototype

T getValue();

Source Link

Document

Gets the value of this mutable.

Usage

From source file:edu.uci.ics.hyracks.algebricks.core.algebra.util.OperatorPropertiesUtil.java

public static void getFreeVariablesInSubplans(AbstractOperatorWithNestedPlans op, Set<LogicalVariable> freeVars)
        throws AlgebricksException {
    for (ILogicalPlan p : op.getNestedPlans()) {
        for (Mutable<ILogicalOperator> r : p.getRoots()) {
            getFreeVariablesInSelfOrDesc((AbstractLogicalOperator) r.getValue(), freeVars);
        }// ww w .j a v a 2 s .com
    }
}

From source file:edu.uci.ics.hyracks.algebricks.core.algebra.util.OperatorPropertiesUtil.java

public static void computeSchemaRecIfNull(AbstractLogicalOperator op) throws AlgebricksException {
    if (op.getSchema() == null) {
        for (Mutable<ILogicalOperator> i : op.getInputs()) {
            computeSchemaRecIfNull((AbstractLogicalOperator) i.getValue());
        }// w  w  w .  jav  a2 s . com
        if (op.hasNestedPlans()) {
            AbstractOperatorWithNestedPlans a = (AbstractOperatorWithNestedPlans) op;
            for (ILogicalPlan p : a.getNestedPlans()) {
                for (Mutable<ILogicalOperator> r : p.getRoots()) {
                    computeSchemaRecIfNull((AbstractLogicalOperator) r.getValue());
                }
            }
        }
        op.recomputeSchema();
    }
}

From source file:edu.uci.ics.hyracks.algebricks.core.algebra.util.OperatorPropertiesUtil.java

/***
 * Recursively checks if the dest operator is in the path of a nested plan
 * /*from  w w w  .jav a 2 s  .  c  om*/
 * @param op
 * @param dest
 * @return
 */
private static boolean isDestInNestedPath(AbstractLogicalOperator op, ILogicalOperator dest) {
    if (op == dest) {
        return true;
    }
    for (Mutable<ILogicalOperator> i : op.getInputs()) {
        if (isDestInNestedPath((AbstractLogicalOperator) i.getValue(), dest)) {
            return true;
        }
    }
    if (op.hasNestedPlans()) {
        AbstractOperatorWithNestedPlans a = (AbstractOperatorWithNestedPlans) op;
        for (ILogicalPlan p : a.getNestedPlans()) {
            for (Mutable<ILogicalOperator> r : p.getRoots()) {
                if (isDestInNestedPath((AbstractLogicalOperator) r.getValue(), dest)) {
                    return true;
                }
            }
        }
    }
    return false;
}

From source file:edu.uci.ics.asterix.optimizer.rules.IntroduceDynamicTypeCastRule.java

/**
 * Inject a function to wrap a variable when necessary
 *
 * @param requiredRecordType//from   w w  w  .j  a  va  2 s. c o  m
 *            the required record type
 * @param recordVar
 *            the record variable
 * @param parent
 *            the current parent operator to be rewritten
 * @param context
 *            the optimization context
 * @param fd
 *            the function to be injected
 * @return true if cast is injected; false otherwise.
 * @throws AlgebricksException
 */
public static LogicalVariable addWrapperFunction(ARecordType requiredRecordType, LogicalVariable recordVar,
        ILogicalOperator parent, IOptimizationContext context, FunctionIdentifier fd)
        throws AlgebricksException {
    List<Mutable<ILogicalOperator>> opRefs = parent.getInputs();
    for (int index = 0; index < opRefs.size(); index++) {
        Mutable<ILogicalOperator> opRef = opRefs.get(index);
        ILogicalOperator op = opRef.getValue();

        /** get produced vars */
        List<LogicalVariable> producedVars = new ArrayList<LogicalVariable>();
        VariableUtilities.getProducedVariables(op, producedVars);
        IVariableTypeEnvironment env = op.computeOutputTypeEnvironment(context);
        for (int i = 0; i < producedVars.size(); i++) {
            LogicalVariable var = producedVars.get(i);
            if (var.equals(recordVar)) {
                /** insert an assign operator to call the function on-top-of the variable */
                IAType actualType = (IAType) env.getVarType(var);
                AbstractFunctionCallExpression cast = new ScalarFunctionCallExpression(
                        FunctionUtils.getFunctionInfo(fd));
                cast.getArguments()
                        .add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(var)));
                /** enforce the required record type */
                TypeComputerUtilities.setRequiredAndInputTypes(cast, requiredRecordType, actualType);
                LogicalVariable newAssignVar = context.newVar();
                AssignOperator newAssignOperator = new AssignOperator(newAssignVar,
                        new MutableObject<ILogicalExpression>(cast));
                newAssignOperator.getInputs().add(new MutableObject<ILogicalOperator>(op));
                opRef.setValue(newAssignOperator);
                context.computeAndSetTypeEnvironmentForOperator(newAssignOperator);
                newAssignOperator.computeOutputTypeEnvironment(context);
                VariableUtilities.substituteVariables(parent, recordVar, newAssignVar, context);
                return newAssignVar;
            }
        }
        /** recursive descend to the operator who produced the recordVar */
        LogicalVariable replacedVar = addWrapperFunction(requiredRecordType, recordVar, op, context, fd);
        if (replacedVar != null) {
            /** substitute the recordVar by the replacedVar for operators who uses recordVar */
            VariableUtilities.substituteVariables(parent, recordVar, replacedVar, context);
            return replacedVar;
        }
    }
    return null;
}

From source file:edu.uci.ics.hyracks.algebricks.core.algebra.util.OperatorPropertiesUtil.java

/**
 * @param op/* w  w w.  j a  v a  2 s  .  co m*/
 *            , the start operator.
 * @param dest
 *            , the destination operator (a direct/indirect input operator).
 * @param usedVars
 *            , the collection of used variables.
 * @param producedVars
 *            , the collection of produced variables.
 * @return if the current operator is on the path from the original start operator to the destination operator.
 * @throws AlgebricksException
 */
private static boolean collectUsedAndProducedVariablesInPath(ILogicalOperator op, ILogicalOperator dest,
        Set<LogicalVariable> usedVars, Set<LogicalVariable> producedVars) throws AlgebricksException {
    if (op == dest) {
        return true;
    }
    boolean onPath = false;
    if (((AbstractLogicalOperator) op).hasNestedPlans()) {
        AbstractOperatorWithNestedPlans a = (AbstractOperatorWithNestedPlans) op;
        for (ILogicalPlan p : a.getNestedPlans()) {
            for (Mutable<ILogicalOperator> r : p.getRoots()) {
                if (isDestInNestedPath((AbstractLogicalOperator) r.getValue(), dest)) {
                    onPath = true;
                }
            }
        }
    }
    for (Mutable<ILogicalOperator> childRef : op.getInputs()) {
        if (collectUsedAndProducedVariablesInPath(childRef.getValue(), dest, usedVars, producedVars)) {
            onPath = true;
        }
    }
    if (onPath) {
        VariableUtilities.getUsedVariables(op, usedVars);
        VariableUtilities.getProducedVariables(op, producedVars);
    }
    return onPath;
}

From source file:edu.uci.ics.hyracks.algebricks.core.algebra.util.OperatorPropertiesUtil.java

public static void computeSchemaAndPropertiesRecIfNull(AbstractLogicalOperator op, IOptimizationContext context)
        throws AlgebricksException {
    if (op.getSchema() == null) {
        for (Mutable<ILogicalOperator> i : op.getInputs()) {
            computeSchemaAndPropertiesRecIfNull((AbstractLogicalOperator) i.getValue(), context);
        }/*  www .ja  va2 s . c  om*/
        if (op.hasNestedPlans()) {
            AbstractOperatorWithNestedPlans a = (AbstractOperatorWithNestedPlans) op;
            for (ILogicalPlan p : a.getNestedPlans()) {
                for (Mutable<ILogicalOperator> r : p.getRoots()) {
                    computeSchemaAndPropertiesRecIfNull((AbstractLogicalOperator) r.getValue(), context);
                }
            }
        }
        op.recomputeSchema();
        op.computeDeliveredPhysicalProperties(context);
    }
}

From source file:edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.visitors.LogicalPropertiesVisitor.java

private static void computeLogicalPropertiesRec(ILogicalOperator op, LogicalPropertiesVisitor visitor,
        IOptimizationContext context) throws AlgebricksException {
    for (Mutable<ILogicalOperator> ref : op.getInputs()) {
        computeLogicalPropertiesRec(ref.getValue(), visitor, context);
    }//from   www .  j a  v  a 2s. c o  m
    op.accept(visitor, context);
    if (AlgebricksConfig.DEBUG) {
        AlgebricksConfig.ALGEBRICKS_LOGGER.finest(
                "Logical properties visitor for " + op + ": " + context.getLogicalPropertiesVector(op) + "\n");
    }
}

From source file:edu.uci.ics.hyracks.algebricks.core.algebra.util.OperatorPropertiesUtil.java

/**
 * Adds the free variables of the plan rooted at that operator to the
 * collection provided./*from w  w  w.  j a  v  a2s. c  o m*/
 * 
 * @param op
 * @param vars
 *            - The collection to which the free variables will be added.
 */
public static void getFreeVariablesInSelfOrDesc(AbstractLogicalOperator op, Set<LogicalVariable> freeVars)
        throws AlgebricksException {
    HashSet<LogicalVariable> produced = new HashSet<LogicalVariable>();
    VariableUtilities.getProducedVariables(op, produced);
    for (LogicalVariable v : produced) {
        freeVars.remove(v);
    }

    HashSet<LogicalVariable> used = new HashSet<LogicalVariable>();
    VariableUtilities.getUsedVariables(op, used);
    for (LogicalVariable v : used) {
        if (!freeVars.contains(v)) {
            freeVars.add(v);
        }
    }

    if (op.hasNestedPlans()) {
        AbstractOperatorWithNestedPlans s = (AbstractOperatorWithNestedPlans) op;
        for (ILogicalPlan p : s.getNestedPlans()) {
            for (Mutable<ILogicalOperator> r : p.getRoots()) {
                getFreeVariablesInSelfOrDesc((AbstractLogicalOperator) r.getValue(), freeVars);
            }
        }
        s.getUsedVariablesExceptNestedPlans(freeVars);
        HashSet<LogicalVariable> produced2 = new HashSet<LogicalVariable>();
        s.getProducedVariablesExceptNestedPlans(produced2);
        freeVars.removeAll(produced);
    }
    for (Mutable<ILogicalOperator> i : op.getInputs()) {
        getFreeVariablesInSelfOrDesc((AbstractLogicalOperator) i.getValue(), freeVars);
    }
}

From source file:edu.uci.ics.hyracks.algebricks.core.algebra.util.OperatorManipulationUtil.java

public static boolean setOperatorMode(AbstractLogicalOperator op) {
    boolean change = false;
    switch (op.getOperatorTag()) {
    case DATASOURCESCAN: {
        op.setExecutionMode(AbstractLogicalOperator.ExecutionMode.PARTITIONED);
        AbstractLogicalOperator currentOp = op;
        while (currentOp.getInputs().size() == 1) {
            AbstractLogicalOperator child = (AbstractLogicalOperator) currentOp.getInputs().get(0).getValue();
            if (child.getOperatorTag() == LogicalOperatorTag.EXCHANGE) {
                break;
            }// w w w  .j a  v  a 2 s  .co m
            child.setExecutionMode(AbstractLogicalOperator.ExecutionMode.PARTITIONED);
            currentOp = child;
        }
        change = true;
        break;
    }
    case NESTEDTUPLESOURCE: {
        NestedTupleSourceOperator nts = (NestedTupleSourceOperator) op;
        AbstractLogicalOperator prevOp = (AbstractLogicalOperator) nts.getDataSourceReference().getValue()
                .getInputs().get(0).getValue();
        if (prevOp.getExecutionMode() != AbstractLogicalOperator.ExecutionMode.UNPARTITIONED) {
            nts.setExecutionMode(AbstractLogicalOperator.ExecutionMode.LOCAL);
            change = true;
        }
        break;
    }
    default: {
        boolean forceUnpartitioned = false;
        if (op.getOperatorTag() == LogicalOperatorTag.LIMIT) {
            LimitOperator opLim = (LimitOperator) op;
            if (opLim.isTopmostLimitOp()) {
                opLim.setExecutionMode(AbstractLogicalOperator.ExecutionMode.UNPARTITIONED);
                change = true;
                forceUnpartitioned = true;
            }
        }
        if (op.getOperatorTag() == LogicalOperatorTag.AGGREGATE) {
            AggregateOperator aggOp = (AggregateOperator) op;
            if (aggOp.isGlobal()) {
                op.setExecutionMode(AbstractLogicalOperator.ExecutionMode.UNPARTITIONED);
                change = true;
                forceUnpartitioned = true;
            }
        }

        for (Mutable<ILogicalOperator> i : op.getInputs()) {
            boolean exit = false;
            AbstractLogicalOperator inputOp = (AbstractLogicalOperator) i.getValue();
            switch (inputOp.getExecutionMode()) {
            case PARTITIONED: {
                if (forceUnpartitioned)
                    break;
                op.setExecutionMode(AbstractLogicalOperator.ExecutionMode.PARTITIONED);
                change = true;
                exit = true;
                break;
            }
            case LOCAL: {
                op.setExecutionMode(AbstractLogicalOperator.ExecutionMode.LOCAL);
                change = true;
                break;
            }
            }
            if (exit) {
                break;
            }
        }
        break;
    }
    }
    return change;
}

From source file:edu.uci.ics.asterix.optimizer.rules.SetAsterixPhysicalOperatorsRule.java

private static void generateMergeAggregationExpressions(GroupByOperator gby, IOptimizationContext context)
        throws AlgebricksException {
    if (gby.getNestedPlans().size() != 1) {
        throw new AlgebricksException(
                "External group-by currently works only for one nested plan with one root containing"
                        + "an aggregate and a nested-tuple-source.");
    }/* w ww.  j a  v  a2  s .c  o m*/
    ILogicalPlan p0 = gby.getNestedPlans().get(0);
    if (p0.getRoots().size() != 1) {
        throw new AlgebricksException(
                "External group-by currently works only for one nested plan with one root containing"
                        + "an aggregate and a nested-tuple-source.");
    }
    IMergeAggregationExpressionFactory mergeAggregationExpressionFactory = context
            .getMergeAggregationExpressionFactory();
    Mutable<ILogicalOperator> r0 = p0.getRoots().get(0);
    AbstractLogicalOperator r0Logical = (AbstractLogicalOperator) r0.getValue();
    if (r0Logical.getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
        throw new AlgebricksException("The merge aggregation expression generation should not process a "
                + r0Logical.getOperatorTag() + " operator.");
    }
    AggregateOperator aggOp = (AggregateOperator) r0.getValue();
    List<Mutable<ILogicalExpression>> aggFuncRefs = aggOp.getExpressions();
    List<LogicalVariable> aggProducedVars = aggOp.getVariables();
    int n = aggOp.getExpressions().size();
    List<Mutable<ILogicalExpression>> mergeExpressionRefs = new ArrayList<Mutable<ILogicalExpression>>();
    for (int i = 0; i < n; i++) {
        ILogicalExpression mergeExpr = mergeAggregationExpressionFactory
                .createMergeAggregation(aggProducedVars.get(i), aggFuncRefs.get(i).getValue(), context);
        if (mergeExpr == null) {
            throw new AlgebricksException("The aggregation function " + aggFuncRefs.get(i).getValue()
                    + " does not have a registered intermediate aggregation function.");
        }
        mergeExpressionRefs.add(new MutableObject<ILogicalExpression>(mergeExpr));
    }
    aggOp.setMergeExpressions(mergeExpressionRefs);
}