Search in sources :

Example 1 with AbstractAssignOperator

use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractAssignOperator in project asterixdb by apache.

the class FeedScanCollectionToUnnest method findVarOriginExpression.

private ILogicalExpression findVarOriginExpression(LogicalVariable v, ILogicalOperator op) throws AlgebricksException {
    boolean searchInputs = false;
    if (!(op instanceof AbstractAssignOperator)) {
        searchInputs = true;
    } else {
        AbstractAssignOperator aao = (AbstractAssignOperator) op;
        List<LogicalVariable> producedVars = new ArrayList<>();
        VariableUtilities.getProducedVariables(op, producedVars);
        int exprIndex = producedVars.indexOf(v);
        if (exprIndex == -1) {
            searchInputs = true;
        } else {
            ILogicalExpression originalCandidate = aao.getExpressions().get(exprIndex).getValue();
            if (originalCandidate.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
                searchInputs = true;
            } else {
                return originalCandidate;
            }
        }
    }
    if (searchInputs) {
        for (Mutable<ILogicalOperator> childOp : op.getInputs()) {
            ILogicalExpression ret = findVarOriginExpression(v, childOp.getValue());
            if (ret != null) {
                return ret;
            }
        }
    }
    throw new IllegalStateException("Unable to find the original expression that produced variable " + v);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AbstractAssignOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractAssignOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ArrayList(java.util.ArrayList)

Example 2 with AbstractAssignOperator

use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractAssignOperator in project asterixdb by apache.

the class IntroduceEnforcedListTypeRule method rewritePost.

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    if (context.checkIfInDontApplySet(this, opRef.getValue()))
        return false;
    AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
    context.addToDontApplySet(this, opRef.getValue());
    /**
         * rewrite list constructor types for list constructor functions
         */
    List<Mutable<ILogicalExpression>> expressions;
    switch(op.getOperatorTag()) {
        case ASSIGN:
            AbstractAssignOperator assignOp = (AbstractAssignOperator) op;
            expressions = assignOp.getExpressions();
            break;
        case UNNEST:
            AbstractUnnestOperator unnestOp = (AbstractUnnestOperator) op;
            expressions = Collections.singletonList(unnestOp.getExpressionRef());
            break;
        default:
            return false;
    }
    IVariableTypeEnvironment env = op.computeOutputTypeEnvironment(context);
    return rewriteExpressions(expressions, env);
}
Also used : AbstractUnnestOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractUnnestOperator) Mutable(org.apache.commons.lang3.mutable.Mutable) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) AbstractAssignOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractAssignOperator) IVariableTypeEnvironment(org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment)

Example 3 with AbstractAssignOperator

use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractAssignOperator in project asterixdb by apache.

the class IsomorphismVariableMappingVisitor method mapVariablesForAbstractAssign.

private void mapVariablesForAbstractAssign(ILogicalOperator left, ILogicalOperator right) throws AlgebricksException {
    if (left.getOperatorTag() != right.getOperatorTag()) {
        return;
    }
    AbstractAssignOperator leftOp = (AbstractAssignOperator) left;
    AbstractAssignOperator rightOp = (AbstractAssignOperator) right;
    List<LogicalVariable> producedVarLeft = new ArrayList<LogicalVariable>();
    List<LogicalVariable> producedVarRight = new ArrayList<LogicalVariable>();
    VariableUtilities.getProducedVariables(left, producedVarLeft);
    VariableUtilities.getProducedVariables(right, producedVarRight);
    mapVariablesForAbstractAssign(producedVarLeft, leftOp.getExpressions(), producedVarRight, rightOp.getExpressions());
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) AbstractAssignOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractAssignOperator) ArrayList(java.util.ArrayList)

Aggregations

AbstractAssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractAssignOperator)3 ArrayList (java.util.ArrayList)2 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)2 Mutable (org.apache.commons.lang3.mutable.Mutable)1 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)1 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)1 IVariableTypeEnvironment (org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment)1 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)1 AbstractUnnestOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractUnnestOperator)1