Search in sources :

Example 16 with AbstractBinaryJoinOperator

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

the class PushUnnestDownThroughProductRule method rewritePost.

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue();
    if (op1.getOperatorTag() != LogicalOperatorTag.UNNEST) {
        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 (join.getCondition().getValue() != ConstantExpression.TRUE) {
        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 unnest 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 unnest 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 17 with AbstractBinaryJoinOperator

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

the class RemoveCartesianProductWithEmptyBranchRule method rewritePost.

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    ILogicalOperator op = opRef.getValue();
    if (op.getOperatorTag() != LogicalOperatorTag.INNERJOIN && op.getOperatorTag() != LogicalOperatorTag.LEFTOUTERJOIN) {
        return false;
    }
    AbstractBinaryJoinOperator joinOperator = (AbstractBinaryJoinOperator) op;
    ILogicalOperator left = joinOperator.getInputs().get(0).getValue();
    ILogicalOperator right = joinOperator.getInputs().get(1).getValue();
    if (!joinOperator.getCondition().getValue().equals(ConstantExpression.TRUE)) {
        return false;
    }
    if (emptyBranch(left)) {
        opRef.setValue(right);
        return true;
    }
    if (emptyBranch(right)) {
        opRef.setValue(left);
        return true;
    }
    return false;
}
Also used : ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) AbstractBinaryJoinOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractBinaryJoinOperator)

Example 18 with AbstractBinaryJoinOperator

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

the class PushGroupByThroughProduct method push.

private void push(Mutable<ILogicalOperator> opRefGby, Mutable<ILogicalOperator> opRefJoin, int branch, List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> decorToPush, List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> decorNotToPush, IOptimizationContext context) throws AlgebricksException {
    GroupByOperator gby = (GroupByOperator) opRefGby.getValue();
    AbstractBinaryJoinOperator join = (AbstractBinaryJoinOperator) opRefJoin.getValue();
    gby.getDecorList().clear();
    gby.getDecorList().addAll(decorToPush);
    for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : decorNotToPush) {
        LogicalVariable v1 = p.first;
        if (v1 != null) {
            VariableReferenceExpression varRef = (VariableReferenceExpression) p.second.getValue();
            LogicalVariable v2 = varRef.getVariableReference();
            OperatorManipulationUtil.substituteVarRec(join, v2, v1, true, context);
        }
    }
    Mutable<ILogicalOperator> branchRef = join.getInputs().get(branch);
    ILogicalOperator opBranch = branchRef.getValue();
    opRefJoin.setValue(opBranch);
    branchRef.setValue(gby);
    opRefGby.setValue(join);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) Mutable(org.apache.commons.lang3.mutable.Mutable) GroupByOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) AbstractBinaryJoinOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractBinaryJoinOperator)

Example 19 with AbstractBinaryJoinOperator

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

the class PushAggFuncIntoStandaloneAggregateRule method pushAggregateFunctionThroughJoin.

/**
     * Does the actual push of aggregates for qualified joins.
     *
     * @param join
     * @param assignOp
     *            that contains aggregate function calls.
     * @param context
     * @throws AlgebricksException
     */
private void pushAggregateFunctionThroughJoin(AbstractBinaryJoinOperator join, AssignOperator assignOp, IOptimizationContext context) throws AlgebricksException {
    for (Mutable<ILogicalOperator> branchRef : join.getInputs()) {
        AbstractLogicalOperator branch = (AbstractLogicalOperator) branchRef.getValue();
        if (branch.getOperatorTag() == LogicalOperatorTag.AGGREGATE) {
            AggregateOperator aggOp = (AggregateOperator) branch;
            pushAggregateFunction(aggOp, assignOp, context);
        } else if (branch.getOperatorTag() == LogicalOperatorTag.INNERJOIN || branch.getOperatorTag() == LogicalOperatorTag.LEFTOUTERJOIN) {
            AbstractBinaryJoinOperator childJoin = (AbstractBinaryJoinOperator) branch;
            pushAggregateFunctionThroughJoin(childJoin, assignOp, context);
        }
    }
}
Also used : AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) AggregateOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator) AbstractBinaryJoinOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractBinaryJoinOperator)

Example 20 with AbstractBinaryJoinOperator

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

the class PushProperJoinThroughProduct method rewritePost.

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
    LogicalOperatorTag tag1 = op.getOperatorTag();
    if (tag1 != LogicalOperatorTag.INNERJOIN && tag1 != LogicalOperatorTag.LEFTOUTERJOIN) {
        return false;
    }
    AbstractBinaryJoinOperator join1 = (AbstractBinaryJoinOperator) op;
    ILogicalExpression cond1 = join1.getCondition().getValue();
    // don't try to push a product down
    if (OperatorPropertiesUtil.isAlwaysTrueCond(cond1)) {
        return false;
    }
    Mutable<ILogicalOperator> opRef2 = op.getInputs().get(0);
    AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue();
    while (op2.isMap()) {
        opRef2 = op2.getInputs().get(0);
        op2 = (AbstractLogicalOperator) opRef2.getValue();
    }
    if (op2.getOperatorTag() != LogicalOperatorTag.INNERJOIN) {
        return false;
    }
    InnerJoinOperator product = (InnerJoinOperator) op2;
    if (!OperatorPropertiesUtil.isAlwaysTrueCond(product.getCondition().getValue())) {
        return false;
    }
    usedInCond1AndMaps.clear();
    cond1.getUsedVariables(usedInCond1AndMaps);
    Mutable<ILogicalOperator> opIterRef = op.getInputs().get(0);
    ILogicalOperator opIter = opIterRef.getValue();
    do {
        VariableUtilities.getUsedVariables(opIter, usedInCond1AndMaps);
        opIterRef = opIter.getInputs().get(0);
        opIter = opIterRef.getValue();
    } while (opIter.isMap());
    productLeftBranchVars.clear();
    ILogicalOperator opLeft = op2.getInputs().get(0).getValue();
    VariableUtilities.getLiveVariables(opLeft, productLeftBranchVars);
    if (!OperatorPropertiesUtil.disjoint(usedInCond1AndMaps, productLeftBranchVars)) {
        return false;
    }
    // now push the operators from in between joins, too
    opIterRef = op.getInputs().get(0);
    opIter = opIterRef.getValue();
    Mutable<ILogicalOperator> op3Ref = product.getInputs().get(1);
    ILogicalOperator op3 = op3Ref.getValue();
    opRef2.setValue(op3);
    op3Ref.setValue(join1);
    opRef.setValue(product);
    return true;
}
Also used : ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) 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) InnerJoinOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator) AbstractBinaryJoinOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractBinaryJoinOperator)

Aggregations

AbstractBinaryJoinOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractBinaryJoinOperator)27 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)24 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)18 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)14 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)11 ArrayList (java.util.ArrayList)9 SelectOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.SelectOperator)9 Mutable (org.apache.commons.lang3.mutable.Mutable)7 MutableObject (org.apache.commons.lang3.mutable.MutableObject)5 InnerJoinOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator)5 Dataset (org.apache.asterix.metadata.entities.Dataset)4 ILogicalPlan (org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan)4 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)4 AggregateOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator)4 LeftOuterJoinOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.LeftOuterJoinOperator)4 HashSet (java.util.HashSet)3 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)3 Clause (org.apache.asterix.lang.common.base.Clause)2 MetadataProvider (org.apache.asterix.metadata.declared.MetadataProvider)2 IAType (org.apache.asterix.om.types.IAType)2