Search in sources :

Example 11 with InnerJoinOperator

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

the class SwitchInnerJoinBranchRule method rewritePost.

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    ILogicalOperator op = opRef.getValue();
    if (op.getOperatorTag() != LogicalOperatorTag.INNERJOIN) {
        return false;
    }
    InnerJoinOperator joinOperator = (InnerJoinOperator) op;
    Mutable<ILogicalOperator> leftRef = joinOperator.getInputs().get(0);
    Mutable<ILogicalOperator> rightRef = joinOperator.getInputs().get(1);
    ILogicalOperator left = leftRef.getValue();
    ILogicalOperator right = rightRef.getValue();
    boolean leftCardinalityOne = OperatorPropertiesUtil.isCardinalityZeroOrOne(left);
    boolean rightCardinalityOne = OperatorPropertiesUtil.isCardinalityZeroOrOne(right);
    if (!leftCardinalityOne || rightCardinalityOne) {
        return false;
    }
    // The cardinality of the left branch is one and the cardinality of the right branch is not one.
    leftRef.setValue(right);
    rightRef.setValue(left);
    return true;
}
Also used : ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) InnerJoinOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator)

Example 12 with InnerJoinOperator

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

the class EliminateSubplanRule method elimSubplanOverEts.

private void elimSubplanOverEts(Mutable<ILogicalOperator> opRef, IOptimizationContext ctx) throws AlgebricksException {
    SubplanOperator subplan = (SubplanOperator) opRef.getValue();
    for (ILogicalPlan p : subplan.getNestedPlans()) {
        for (Mutable<ILogicalOperator> r : p.getRoots()) {
            OperatorManipulationUtil.ntsToEts(r, ctx);
        }
    }
    LinkedList<Mutable<ILogicalOperator>> allRoots = subplan.allRootsInReverseOrder();
    if (allRoots.size() == 1) {
        opRef.setValue(allRoots.get(0).getValue());
    } else {
        ILogicalOperator topOp = null;
        for (Mutable<ILogicalOperator> r : allRoots) {
            if (topOp == null) {
                topOp = r.getValue();
            } else {
                InnerJoinOperator j = new InnerJoinOperator(new MutableObject<ILogicalExpression>(ConstantExpression.TRUE));
                j.getInputs().add(new MutableObject<ILogicalOperator>(topOp));
                j.getInputs().add(r);
                ctx.setOutputTypeEnvironment(j, j.computeOutputTypeEnvironment(ctx));
                topOp = j;
            }
        }
        opRef.setValue(topOp);
    }
}
Also used : SubplanOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.SubplanOperator) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ILogicalPlan(org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan) InnerJoinOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator)

Example 13 with InnerJoinOperator

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

the class PushGroupByThroughProduct method rewritePost.

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue();
    if (op1.getOperatorTag() != LogicalOperatorTag.GROUP) {
        return false;
    }
    Mutable<ILogicalOperator> opRef2 = op1.getInputs().get(0);
    AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue();
    if (op2.getOperatorTag() != LogicalOperatorTag.INNERJOIN) {
        return false;
    }
    InnerJoinOperator join = (InnerJoinOperator) op2;
    if (!OperatorPropertiesUtil.isAlwaysTrueCond(join.getCondition().getValue())) {
        // not a product
        return false;
    }
    GroupByOperator gby = (GroupByOperator) op1;
    List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> decorToPush = new ArrayList<Pair<LogicalVariable, Mutable<ILogicalExpression>>>();
    List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> decorNotToPush = new ArrayList<Pair<LogicalVariable, Mutable<ILogicalExpression>>>();
    Mutable<ILogicalOperator> opLeftRef = join.getInputs().get(0);
    ILogicalOperator opLeft = opLeftRef.getValue();
    switch(canPushThrough(gby, opLeft, decorToPush, decorNotToPush)) {
        case REPEATED_DECORS:
            {
                return false;
            }
        case TRUE:
            {
                push(opRef, opRef2, 0, decorToPush, decorNotToPush, context);
                return true;
            }
        case FALSE:
            {
                decorToPush.clear();
                Mutable<ILogicalOperator> opRightRef = join.getInputs().get(1);
                ILogicalOperator opRight = opRightRef.getValue();
                if (canPushThrough(gby, opRight, decorToPush, decorNotToPush) == PushTestResult.TRUE) {
                    push(opRef, opRef2, 1, decorToPush, decorNotToPush, context);
                    return true;
                } else {
                    return false;
                }
            }
        default:
            {
                throw new IllegalStateException();
            }
    }
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) GroupByOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ArrayList(java.util.ArrayList) InnerJoinOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Example 14 with InnerJoinOperator

use of org.apache.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator 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)

Example 15 with InnerJoinOperator

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

the class AqlPlusExpressionToPlanTranslator method visitJoinClause.

@Override
public Pair<ILogicalOperator, LogicalVariable> visitJoinClause(JoinClause jc, Mutable<ILogicalOperator> tupSource) throws CompilationException {
    Mutable<ILogicalOperator> opRef = tupSource;
    Pair<ILogicalOperator, LogicalVariable> leftSide = null;
    for (Clause c : jc.getLeftClauses()) {
        leftSide = c.accept(this, opRef);
        opRef = new MutableObject<ILogicalOperator>(leftSide.first);
    }
    opRef = tupSource;
    Pair<ILogicalOperator, LogicalVariable> rightSide = null;
    for (Clause c : jc.getRightClauses()) {
        rightSide = c.accept(this, opRef);
        opRef = new MutableObject<ILogicalOperator>(rightSide.first);
    }
    Pair<ILogicalExpression, Mutable<ILogicalOperator>> whereCond = langExprToAlgExpression(jc.getWhereExpr(), tupSource);
    AbstractBinaryJoinOperator join;
    switch(jc.getKind()) {
        case INNER:
            join = new InnerJoinOperator(new MutableObject<ILogicalExpression>(whereCond.first));
            break;
        case LEFT_OUTER:
            join = new LeftOuterJoinOperator(new MutableObject<ILogicalExpression>(whereCond.first));
            break;
        default:
            throw new CompilationException(ErrorCode.COMPILATION_AQLPLUS_NO_SUCH_JOIN_TYPE);
    }
    join.getInputs().add(new MutableObject<ILogicalOperator>(leftSide.first));
    join.getInputs().add(new MutableObject<ILogicalOperator>(rightSide.first));
    return new Pair<ILogicalOperator, LogicalVariable>(join, null);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) CompilationException(org.apache.asterix.common.exceptions.CompilationException) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) LeftOuterJoinOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.LeftOuterJoinOperator) InnerJoinOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator) AbstractBinaryJoinOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractBinaryJoinOperator) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) MetaVariableClause(org.apache.asterix.lang.aql.clause.MetaVariableClause) JoinClause(org.apache.asterix.lang.aql.clause.JoinClause) Clause(org.apache.asterix.lang.common.base.Clause) MutableObject(org.apache.commons.lang3.mutable.MutableObject) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Aggregations

InnerJoinOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator)21 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)15 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)13 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)12 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)10 Mutable (org.apache.commons.lang3.mutable.Mutable)9 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)6 ILogicalPlan (org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan)6 MutableObject (org.apache.commons.lang3.mutable.MutableObject)5 AbstractBinaryJoinOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractBinaryJoinOperator)5 EmptyTupleSourceOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.EmptyTupleSourceOperator)5 Pair (org.apache.hyracks.algebricks.common.utils.Pair)4 SelectOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.SelectOperator)4 SubplanOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.SubplanOperator)4 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)3 GroupByOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator)3 MetadataProvider (org.apache.asterix.metadata.declared.MetadataProvider)2 Dataset (org.apache.asterix.metadata.entities.Dataset)2 AsterixConstantValue (org.apache.asterix.om.constants.AsterixConstantValue)2