Search in sources :

Example 1 with AbstractLogicalOperator

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

the class CancelUnnestWithNestedListifyRule method applyRuleDown.

private boolean applyRuleDown(Mutable<ILogicalOperator> opRef, Set<LogicalVariable> varSet, IOptimizationContext context) throws AlgebricksException {
    boolean changed = applies(opRef, varSet, context);
    AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
    VariableUtilities.getUsedVariables(op, varSet);
    if (op.hasNestedPlans()) {
        AbstractOperatorWithNestedPlans aonp = (AbstractOperatorWithNestedPlans) op;
        for (ILogicalPlan p : aonp.getNestedPlans()) {
            for (Mutable<ILogicalOperator> r : p.getRoots()) {
                if (applyRuleDown(r, varSet, context)) {
                    changed = true;
                }
                context.addToDontApplySet(this, r.getValue());
            }
        }
    }
    for (Mutable<ILogicalOperator> i : op.getInputs()) {
        if (applyRuleDown(i, varSet, context)) {
            changed = true;
        }
        context.addToDontApplySet(this, i.getValue());
    }
    return changed;
}
Also used : AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ILogicalPlan(org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan) AbstractOperatorWithNestedPlans(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractOperatorWithNestedPlans)

Example 2 with AbstractLogicalOperator

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

the class CountVarToCountOneRule method rewritePost.

// It is only for a group-by having just one aggregate which is a count.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue();
    if (op1.getOperatorTag() != LogicalOperatorTag.GROUP) {
        return false;
    }
    GroupByOperator g = (GroupByOperator) op1;
    if (g.getNestedPlans().size() != 1) {
        return false;
    }
    ILogicalPlan p = g.getNestedPlans().get(0);
    if (p.getRoots().size() != 1) {
        return false;
    }
    AbstractLogicalOperator op2 = (AbstractLogicalOperator) p.getRoots().get(0).getValue();
    if (op2.getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
        return false;
    }
    AggregateOperator agg = (AggregateOperator) op2;
    if (agg.getExpressions().size() != 1) {
        return false;
    }
    ILogicalExpression exp2 = agg.getExpressions().get(0).getValue();
    if (exp2.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
        return false;
    }
    AbstractFunctionCallExpression fun = (AbstractFunctionCallExpression) exp2;
    if (fun.getFunctionIdentifier() != BuiltinFunctions.COUNT) {
        return false;
    }
    ILogicalExpression exp3 = fun.getArguments().get(0).getValue();
    if (exp3.getExpressionTag() != LogicalExpressionTag.VARIABLE) {
        return false;
    }
    if (((AbstractLogicalOperator) agg.getInputs().get(0).getValue()).getOperatorTag() != LogicalOperatorTag.NESTEDTUPLESOURCE) {
        return false;
    }
    fun.getArguments().get(0).setValue(new ConstantExpression(new AsterixConstantValue(new AInt64(1L))));
    return true;
}
Also used : 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) AsterixConstantValue(org.apache.asterix.om.constants.AsterixConstantValue) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ConstantExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression) AggregateOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator) ILogicalPlan(org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan) AInt64(org.apache.asterix.om.base.AInt64)

Example 3 with AbstractLogicalOperator

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

the class FuzzyEqRule method rewritePost.

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
    // current operator is INNERJOIN or LEFTOUTERJOIN or SELECT
    Mutable<ILogicalExpression> expRef;
    if (op.getOperatorTag() == LogicalOperatorTag.INNERJOIN || op.getOperatorTag() == LogicalOperatorTag.LEFTOUTERJOIN) {
        AbstractBinaryJoinOperator joinOp = (AbstractBinaryJoinOperator) op;
        expRef = joinOp.getCondition();
    } else if (op.getOperatorTag() == LogicalOperatorTag.SELECT) {
        SelectOperator selectOp = (SelectOperator) op;
        expRef = selectOp.getCondition();
    } else {
        return false;
    }
    MetadataProvider metadataProvider = ((MetadataProvider) context.getMetadataProvider());
    IVariableTypeEnvironment env = context.getOutputTypeEnvironment(op);
    if (expandFuzzyEq(expRef, context, env, metadataProvider)) {
        context.computeAndSetTypeEnvironmentForOperator(op);
        return true;
    }
    return false;
}
Also used : ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) SelectOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.SelectOperator) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) MetadataProvider(org.apache.asterix.metadata.declared.MetadataProvider) IVariableTypeEnvironment(org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment) AbstractBinaryJoinOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractBinaryJoinOperator)

Example 4 with AbstractLogicalOperator

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

the class OperatorPropertiesUtil method collectUsedAndProducedVariablesInPath.

/**
     * @param op
     *            , the start operator.
     * @param dest
     *            , the destination operator (a direct/indirect input operator).
     * @param usedVars
     *            , the collection of used variables.
     * @param producedVars
     *            , the collection of produced variables.
     * @return if the current operator is on the path from the original start operator to the destination operator.
     * @throws AlgebricksException
     */
private static boolean collectUsedAndProducedVariablesInPath(ILogicalOperator op, ILogicalOperator dest, Set<LogicalVariable> usedVars, Set<LogicalVariable> producedVars) throws AlgebricksException {
    if (op == dest) {
        return true;
    }
    if (((AbstractLogicalOperator) op).hasNestedPlans()) {
        AbstractOperatorWithNestedPlans a = (AbstractOperatorWithNestedPlans) op;
        for (ILogicalPlan p : a.getNestedPlans()) {
            for (Mutable<ILogicalOperator> r : p.getRoots()) {
                if (collectUsedAndProducedVariablesInPath(r.getValue(), dest, usedVars, producedVars)) {
                    VariableUtilities.getUsedVariables(r.getValue(), usedVars);
                    VariableUtilities.getProducedVariables(r.getValue(), producedVars);
                    return true;
                }
            }
        }
    }
    for (Mutable<ILogicalOperator> childRef : op.getInputs()) {
        if (collectUsedAndProducedVariablesInPath(childRef.getValue(), dest, usedVars, producedVars)) {
            VariableUtilities.getUsedVariables(op, usedVars);
            VariableUtilities.getProducedVariables(op, producedVars);
            return true;
        }
    }
    return false;
}
Also used : AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ILogicalPlan(org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan) AbstractOperatorWithNestedPlans(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractOperatorWithNestedPlans)

Example 5 with AbstractLogicalOperator

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

the class JobBuilder method contributeMicroOperator.

@Override
public void contributeMicroOperator(ILogicalOperator op, IPushRuntimeFactory runtime, RecordDescriptor recDesc, AlgebricksPartitionConstraint pc) {
    microOps.put(op, new Pair<IPushRuntimeFactory, RecordDescriptor>(runtime, recDesc));
    revMicroOpMap.put(runtime, op);
    if (pc != null) {
        pcForMicroOps.put(op, pc);
    }
    AbstractLogicalOperator logicalOp = (AbstractLogicalOperator) op;
    if (logicalOp.getExecutionMode() == ExecutionMode.UNPARTITIONED && pc == null) {
        AlgebricksPartitionConstraint apc = countOneLocation;
        pcForMicroOps.put(logicalOp, apc);
    }
}
Also used : AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) RecordDescriptor(org.apache.hyracks.api.dataflow.value.RecordDescriptor) AlgebricksPartitionConstraint(org.apache.hyracks.algebricks.common.constraints.AlgebricksPartitionConstraint) IPushRuntimeFactory(org.apache.hyracks.algebricks.runtime.base.IPushRuntimeFactory)

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