Search in sources :

Example 6 with LogicalOperatorTag

use of org.apache.hyracks.algebricks.core.algebra.base.LogicalOperatorTag in project asterixdb by apache.

the class AbstractDecorrelationRule method descOrSelfIsScanOrJoin.

protected boolean descOrSelfIsScanOrJoin(ILogicalOperator op2) {
    LogicalOperatorTag t = op2.getOperatorTag();
    if (isScanOrJoin(t)) {
        return true;
    }
    if (op2.getInputs().size() != 1) {
        return false;
    }
    ILogicalOperator alo = op2.getInputs().get(0).getValue();
    if (descOrSelfIsScanOrJoin(alo)) {
        return true;
    }
    return false;
}
Also used : LogicalOperatorTag(org.apache.hyracks.algebricks.core.algebra.base.LogicalOperatorTag) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)

Example 7 with LogicalOperatorTag

use of org.apache.hyracks.algebricks.core.algebra.base.LogicalOperatorTag in project asterixdb by apache.

the class RemoveRedundantVariablesRule method removeRedundantVariables.

private boolean removeRedundantVariables(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
    LogicalOperatorTag opTag = op.getOperatorTag();
    boolean modified = false;
    // Update equivalence class map.
    if (opTag == LogicalOperatorTag.ASSIGN) {
        AssignOperator assignOp = (AssignOperator) op;
        int numVars = assignOp.getVariables().size();
        for (int i = 0; i < numVars; i++) {
            ILogicalExpression expr = assignOp.getExpressions().get(i).getValue();
            if (expr.getExpressionTag() != LogicalExpressionTag.VARIABLE) {
                continue;
            }
            VariableReferenceExpression rhsVarRefExpr = (VariableReferenceExpression) expr;
            // Update equivalence class map.
            LogicalVariable lhs = assignOp.getVariables().get(i);
            LogicalVariable rhs = rhsVarRefExpr.getVariableReference();
            updateEquivalenceClassMap(lhs, rhs);
        }
    }
    // Replace variable references with their first representative.
    if (opTag == LogicalOperatorTag.PROJECT) {
        // The project operator does not use expressions, so we need to replace it's variables manually.
        if (replaceProjectVars((ProjectOperator) op)) {
            modified = true;
        }
    } else if (op.getOperatorTag() == LogicalOperatorTag.UNIONALL) {
        // Replace redundant variables manually in the UnionAll operator.
        if (replaceUnionAllVars((UnionAllOperator) op)) {
            modified = true;
        }
    } else {
        if (op.acceptExpressionTransform(substVisitor)) {
            modified = true;
        }
    }
    // Perform variable replacement in nested plans.
    if (op.hasNestedPlans()) {
        AbstractOperatorWithNestedPlans opWithNestedPlan = (AbstractOperatorWithNestedPlans) op;
        for (ILogicalPlan nestedPlan : opWithNestedPlan.getNestedPlans()) {
            for (Mutable<ILogicalOperator> rootRef : nestedPlan.getRoots()) {
                if (removeRedundantVariables(rootRef, context)) {
                    modified = true;
                }
            }
        }
    }
    // Deal with re-mapping of variables in group by.
    if (opTag == LogicalOperatorTag.GROUP) {
        if (handleGroupByVarRemapping((GroupByOperator) op)) {
            modified = true;
        }
    }
    if (modified) {
        context.computeAndSetTypeEnvironmentForOperator(op);
        context.addToDontApplySet(this, op);
    }
    // in the query plan.
    if (opTag == LogicalOperatorTag.DISTRIBUTE_RESULT || opTag == LogicalOperatorTag.SINK) {
        equivalentVarsMap.clear();
    }
    return modified;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) AssignOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) UnionAllOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.UnionAllOperator) LogicalOperatorTag(org.apache.hyracks.algebricks.core.algebra.base.LogicalOperatorTag) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) ILogicalPlan(org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan) AbstractOperatorWithNestedPlans(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractOperatorWithNestedPlans)

Example 8 with LogicalOperatorTag

use of org.apache.hyracks.algebricks.core.algebra.base.LogicalOperatorTag in project asterixdb by apache.

the class MoveFreeVariableOperatorOutOfSubplanRule method producedVariablesCanbePropagated.

// Checks whether there is a variable killing operator in the nested pipeline
private boolean producedVariablesCanbePropagated(ILogicalOperator operator) throws AlgebricksException {
    ILogicalOperator currentOperator = operator;
    // Makes sure the produced variables by operator are not killed in the nested pipeline below it.
    while (!currentOperator.getInputs().isEmpty()) {
        LogicalOperatorTag operatorTag = currentOperator.getOperatorTag();
        if (operatorTag == LogicalOperatorTag.AGGREGATE || operatorTag == LogicalOperatorTag.RUNNINGAGGREGATE || operatorTag == LogicalOperatorTag.GROUP) {
            return false;
        }
        if (operatorTag == LogicalOperatorTag.PROJECT) {
            Set<LogicalVariable> producedVars = new HashSet<>();
            VariableUtilities.getProducedVariables(currentOperator, producedVars);
            ProjectOperator projectOperator = (ProjectOperator) currentOperator;
            if (!projectOperator.getVariables().containsAll(producedVars)) {
                return false;
            }
        }
        currentOperator = currentOperator.getInputs().get(0).getValue();
    }
    return true;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) LogicalOperatorTag(org.apache.hyracks.algebricks.core.algebra.base.LogicalOperatorTag) ProjectOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.ProjectOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) HashSet(java.util.HashSet)

Example 9 with LogicalOperatorTag

use of org.apache.hyracks.algebricks.core.algebra.base.LogicalOperatorTag in project asterixdb by apache.

the class PushSelectDownRule method rewritePre.

@Override
public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
    if (op.getOperatorTag() != LogicalOperatorTag.SELECT) {
        return false;
    }
    Mutable<ILogicalOperator> opRef2 = op.getInputs().get(0);
    AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue();
    if (context.checkAndAddToAlreadyCompared(op, op2)) {
        return false;
    }
    LogicalOperatorTag tag2 = op2.getOperatorTag();
    if (tag2 == LogicalOperatorTag.INNERJOIN || tag2 == LogicalOperatorTag.LEFTOUTERJOIN || tag2 == LogicalOperatorTag.REPLICATE || tag2 == LogicalOperatorTag.SPLIT) {
        return false;
    } else {
        // not a join
        boolean res = propagateSelectionRec(opRef, opRef2);
        if (res) {
            OperatorPropertiesUtil.typeOpRec(opRef, context);
        }
        return res;
    }
}
Also used : AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) LogicalOperatorTag(org.apache.hyracks.algebricks.core.algebra.base.LogicalOperatorTag) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)

Aggregations

ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)9 LogicalOperatorTag (org.apache.hyracks.algebricks.core.algebra.base.LogicalOperatorTag)9 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)6 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)4 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Mutable (org.apache.commons.lang3.mutable.Mutable)2 AbstractBinaryJoinOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractBinaryJoinOperator)2 InnerJoinOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator)2 LinkedList (java.util.LinkedList)1 ILogicalPlan (org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan)1 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)1 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)1 IFunctionInfo (org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo)1 AbstractOperatorWithNestedPlans (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractOperatorWithNestedPlans)1 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)1 LimitOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.LimitOperator)1 ProjectOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.ProjectOperator)1 SelectOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.SelectOperator)1