Search in sources :

Example 86 with AbstractLogicalOperator

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

the class RemoveRedundantProjectionRule method rewritePre.

@Override
public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue();
    if (op1.getOperatorTag() == LogicalOperatorTag.PROJECT) {
        Mutable<ILogicalOperator> opRef2 = op1.getInputs().get(0);
        AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue();
        if (op2.getOperatorTag() != LogicalOperatorTag.PROJECT) {
            return false;
        }
        ProjectOperator pi2 = (ProjectOperator) op2;
        opRef2.setValue(pi2.getInputs().get(0).getValue());
    } else {
        if (op1.getInputs().size() <= 0)
            return false;
        Mutable<ILogicalOperator> opRef2 = op1.getInputs().get(0);
        AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue();
        if (op2.getOperatorTag() != LogicalOperatorTag.PROJECT) {
            return false;
        }
        if (op2.getInputs().size() <= 0)
            return false;
        Mutable<ILogicalOperator> opRef3 = op2.getInputs().get(0);
        AbstractLogicalOperator op3 = (AbstractLogicalOperator) opRef3.getValue();
        List<LogicalVariable> liveVars2 = new ArrayList<LogicalVariable>();
        List<LogicalVariable> liveVars3 = new ArrayList<LogicalVariable>();
        VariableUtilities.getLiveVariables(op2, liveVars2);
        VariableUtilities.getLiveVariables(op3, liveVars3);
        if (!VariableUtilities.varListEqualUnordered(liveVars2, liveVars3))
            return false;
        opRef2.setValue(op3);
    }
    return true;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) ProjectOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.ProjectOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ArrayList(java.util.ArrayList)

Example 87 with AbstractLogicalOperator

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

the class PushMapOperatorDownThroughProductRule method rewritePost.

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue();
    // since a new LIMIT under a join can't generate the original result.
    if (!op1.isMap() || op1.getOperatorTag() == LogicalOperatorTag.LIMIT) {
        return false;
    }
    if (!OperatorPropertiesUtil.isMovable(op1)) {
        return false;
    }
    ;
    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;
        }
    }
}
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) ArrayList(java.util.ArrayList) AbstractBinaryJoinOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractBinaryJoinOperator)

Example 88 with AbstractLogicalOperator

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

the class PushNestedOrderByUnderPreSortedGroupByRule method rewritePost.

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
    if (op.getOperatorTag() != LogicalOperatorTag.GROUP) {
        return false;
    }
    if (op.getPhysicalOperator() == null) {
        return false;
    }
    AbstractPhysicalOperator pOp = (AbstractPhysicalOperator) op.getPhysicalOperator();
    if (pOp.getOperatorTag() != PhysicalOperatorTag.PRE_CLUSTERED_GROUP_BY) {
        return false;
    }
    GroupByOperator gby = (GroupByOperator) op;
    ILogicalPlan plan = gby.getNestedPlans().get(0);
    AbstractLogicalOperator op1 = (AbstractLogicalOperator) plan.getRoots().get(0).getValue();
    if (op1.getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
        return false;
    }
    Mutable<ILogicalOperator> opRef2 = op1.getInputs().get(0);
    AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue();
    if (op2.getOperatorTag() != LogicalOperatorTag.ORDER) {
        return false;
    }
    OrderOperator order1 = (OrderOperator) op2;
    if (!isIndependentFromChildren(order1)) {
        return false;
    }
    AbstractPhysicalOperator pOrder1 = (AbstractPhysicalOperator) op2.getPhysicalOperator();
    if (pOrder1.getOperatorTag() != PhysicalOperatorTag.STABLE_SORT && pOrder1.getOperatorTag() != PhysicalOperatorTag.IN_MEMORY_STABLE_SORT) {
        return false;
    }
    // StableSortPOperator sort1 = (StableSortPOperator) pOrder1;
    AbstractLogicalOperator op3 = (AbstractLogicalOperator) op.getInputs().get(0).getValue();
    if (op3.getOperatorTag() != LogicalOperatorTag.ORDER) {
        return false;
    }
    AbstractPhysicalOperator pOp3 = (AbstractPhysicalOperator) op3.getPhysicalOperator();
    if (pOp3.getOperatorTag() != PhysicalOperatorTag.STABLE_SORT) {
        return false;
    }
    OrderOperator order2 = (OrderOperator) op3;
    StableSortPOperator sort2 = (StableSortPOperator) pOp3;
    // int k = 0;
    for (Pair<IOrder, Mutable<ILogicalExpression>> oe : order1.getOrderExpressions()) {
        order2.getOrderExpressions().add(oe);
    // sortColumns[n2 + k] = sort1.getSortColumns()[k];
    // ++k;
    }
    // sort2.setSortColumns(sortColumns);
    sort2.computeDeliveredProperties(order2, null);
    // remove order1
    ILogicalOperator underOrder1 = order1.getInputs().get(0).getValue();
    opRef2.setValue(underOrder1);
    return true;
}
Also used : Mutable(org.apache.commons.lang3.mutable.Mutable) GroupByOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) IOrder(org.apache.hyracks.algebricks.core.algebra.operators.logical.OrderOperator.IOrder) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) AbstractPhysicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.physical.AbstractPhysicalOperator) ILogicalPlan(org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan) OrderOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.OrderOperator) StableSortPOperator(org.apache.hyracks.algebricks.core.algebra.operators.physical.StableSortPOperator)

Example 89 with AbstractLogicalOperator

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

the class SetAlgebricksPhysicalOperatorsRule method rewritePre.

@Override
public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
    // }
    if (op.getPhysicalOperator() != null) {
        return false;
    }
    computeDefaultPhysicalOp(op, true, context);
    // context.addToDontApplySet(this, op);
    return true;
}
Also used : AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)

Example 90 with AbstractLogicalOperator

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

the class PushSubplanWithAggregateDownThroughProductRule method rewritePost.

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue();
    if (op1.getOperatorTag() != LogicalOperatorTag.SUBPLAN) {
        return false;
    }
    SubplanOperator subplan = (SubplanOperator) op1;
    if (subplan.getNestedPlans().size() != 1) {
        return false;
    }
    ILogicalPlan p = subplan.getNestedPlans().get(0);
    if (p.getRoots().size() != 1) {
        return false;
    }
    Mutable<ILogicalOperator> r = p.getRoots().get(0);
    if (((AbstractLogicalOperator) r.getValue()).getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
        return false;
    }
    Set<LogicalVariable> free = new HashSet<LogicalVariable>();
    OperatorPropertiesUtil.getFreeVariablesInSubplans(subplan, free);
    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;
    }
    Mutable<ILogicalOperator> b0Ref = op2.getInputs().get(0);
    ILogicalOperator b0 = b0Ref.getValue();
    List<LogicalVariable> b0Scm = new ArrayList<LogicalVariable>();
    VariableUtilities.getLiveVariables(b0, b0Scm);
    if (b0Scm.containsAll(free)) {
        // push subplan 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(free)) {
            // push subplan on right branch
            op2Ref.setValue(b1);
            b1Ref.setValue(op1);
            opRef.setValue(op2);
            return true;
        } else {
            return false;
        }
    }
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) SubplanOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.SubplanOperator) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ArrayList(java.util.ArrayList) ILogicalPlan(org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan) HashSet(java.util.HashSet) AbstractBinaryJoinOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractBinaryJoinOperator)

Aggregations

AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)236 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)116 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)91 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)82 ArrayList (java.util.ArrayList)65 Mutable (org.apache.commons.lang3.mutable.Mutable)60 ILogicalPlan (org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan)44 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)41 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)34 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)32 HashSet (java.util.HashSet)27 GroupByOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator)24 AggregateOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator)20 AbstractOperatorWithNestedPlans (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractOperatorWithNestedPlans)19 SelectOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.SelectOperator)19 StructuralPropertiesVector (org.apache.hyracks.algebricks.core.algebra.properties.StructuralPropertiesVector)19 AbstractBinaryJoinOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractBinaryJoinOperator)18 SubplanOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.SubplanOperator)16 UnnestOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.UnnestOperator)16 LinkedList (java.util.LinkedList)14