Search in sources :

Example 26 with ILogicalOperator

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

the class RemoveUnusedOneToOneEquiJoinRule method gatherProducingDataScans.

private void gatherProducingDataScans(Mutable<ILogicalOperator> opRef, List<LogicalVariable> joinUsedVars, List<DataSourceScanOperator> dataScans) {
    AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
    if (op.getOperatorTag() != LogicalOperatorTag.DATASOURCESCAN) {
        for (Mutable<ILogicalOperator> inputOp : op.getInputs()) {
            gatherProducingDataScans(inputOp, joinUsedVars, dataScans);
        }
        return;
    }
    DataSourceScanOperator dataScan = (DataSourceScanOperator) op;
    fillPKVars(dataScan, pkVars);
    // Check if join uses all PK vars.
    if (joinUsedVars.containsAll(pkVars)) {
        dataScans.add(dataScan);
    }
}
Also used : AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) DataSourceScanOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.DataSourceScanOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)

Example 27 with ILogicalOperator

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

the class RemoveLeftOuterUnnestForLeftOuterJoinRule method rewritePre.

@Override
public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    ILogicalOperator op1 = opRef.getValue();
    // Checks the plan pattern.
    if (!checkOperatorPattern(op1)) {
        return false;
    }
    LeftOuterUnnestOperator outerUnnest = (LeftOuterUnnestOperator) op1;
    GroupByOperator gbyOperator = (GroupByOperator) outerUnnest.getInputs().get(0).getValue();
    LeftOuterJoinOperator lojOperator = (LeftOuterJoinOperator) gbyOperator.getInputs().get(0).getValue();
    // Checks whether the left outer unnest and the group-by operator are qualified for rewriting.
    Triple<Boolean, ILogicalExpression, ILogicalExpression> checkGbyResult = checkUnnestAndGby(outerUnnest, gbyOperator);
    // The argument for listify and not(is-missing(...)) check should be variables.
    if (!isVariableReference(checkGbyResult.second) || !isVariableReference(checkGbyResult.third)) {
        return false;
    }
    // Checks whether both the listify variable and the condition test variable are from the right input
    // branch of the left outer join.
    LogicalVariable listifyVar = ((VariableReferenceExpression) checkGbyResult.second).getVariableReference();
    LogicalVariable conditionTestVar = ((VariableReferenceExpression) checkGbyResult.third).getVariableReference();
    if (!checkListifyAndConditionVar(lojOperator, listifyVar, conditionTestVar)) {
        return false;
    }
    // Does the rewrite.
    removeGroupByAndOuterUnnest(opRef, context, outerUnnest, gbyOperator, lojOperator, listifyVar);
    return true;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) 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) LeftOuterJoinOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.LeftOuterJoinOperator) LeftOuterUnnestOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.LeftOuterUnnestOperator)

Example 28 with ILogicalOperator

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

the class RemoveLeftOuterUnnestForLeftOuterJoinRule method checkNestedPlan.

// Checks the nested plan for the group-by operator.
private Pair<Boolean, ILogicalOperator> checkNestedPlan(GroupByOperator gbyOperator) {
    List<ILogicalPlan> nestedPlans = gbyOperator.getNestedPlans();
    if (nestedPlans.size() > 1) {
        return new Pair<>(false, null);
    }
    ILogicalPlan plan = nestedPlans.get(0);
    List<Mutable<ILogicalOperator>> roots = plan.getRoots();
    if (roots.size() > 1) {
        return new Pair<>(false, null);
    }
    ILogicalOperator root = roots.get(0).getValue();
    return new Pair<>(true, root);
}
Also used : Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ILogicalPlan(org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Example 29 with ILogicalOperator

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

the class RemoveLeftOuterUnnestForLeftOuterJoinRule method checkGroupBy.

// Checks the group-by operator on top of the left outer join operator.
private Triple<Boolean, ILogicalExpression, ILogicalExpression> checkGroupBy(GroupByOperator gbyOperator, LogicalVariable varToUnnest) {
    Pair<Boolean, ILogicalOperator> checkNestedPlanResult = checkNestedPlan(gbyOperator);
    if (!checkNestedPlanResult.first) {
        return new Triple<>(false, null, null);
    }
    ILogicalOperator root = checkNestedPlanResult.second;
    if (root.getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
        return new Triple<>(false, null, null);
    }
    // Checks aggregate.
    AggregateOperator agg = (AggregateOperator) root;
    Pair<Boolean, ILogicalExpression> listifyArgPair = checksAggregate(agg, varToUnnest);
    if (!listifyArgPair.first) {
        return new Triple<>(false, null, null);
    }
    // Checks select.
    ILogicalOperator rootInputOp = root.getInputs().get(0).getValue();
    if (rootInputOp.getOperatorTag() != LogicalOperatorTag.SELECT) {
        return new Triple<>(false, null, null);
    }
    SelectOperator select = (SelectOperator) rootInputOp;
    Pair<Boolean, ILogicalExpression> conditionArgPair = checkSelect(select);
    return new Triple<>(true, listifyArgPair.second, conditionArgPair.second);
}
Also used : Triple(org.apache.hyracks.algebricks.common.utils.Triple) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) SelectOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.SelectOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) AggregateOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator)

Example 30 with ILogicalOperator

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

the class AccessMethodUtils method retainInputs.

//Get Variables used by afterSelectRefs that were created before the datasource
//If there are any, we should retain inputs
public static boolean retainInputs(List<LogicalVariable> dataSourceVariables, ILogicalOperator sourceOp, List<Mutable<ILogicalOperator>> afterSelectRefs) throws AlgebricksException {
    List<LogicalVariable> usedVars = new ArrayList<>();
    List<LogicalVariable> producedVars = new ArrayList<>();
    List<LogicalVariable> liveVars = new ArrayList<>();
    VariableUtilities.getLiveVariables(sourceOp, liveVars);
    for (Mutable<ILogicalOperator> opMutable : afterSelectRefs) {
        ILogicalOperator op = opMutable.getValue();
        VariableUtilities.getUsedVariables(op, usedVars);
        VariableUtilities.getProducedVariables(op, producedVars);
    }
    usedVars.removeAll(producedVars);
    usedVars.removeAll(dataSourceVariables);
    usedVars.retainAll(liveVars);
    return usedVars.isEmpty() ? false : true;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ArrayList(java.util.ArrayList)

Aggregations

ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)355 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)196 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)130 Mutable (org.apache.commons.lang3.mutable.Mutable)125 ArrayList (java.util.ArrayList)119 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)117 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)86 ILogicalPlan (org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan)73 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)57 Pair (org.apache.hyracks.algebricks.common.utils.Pair)53 MutableObject (org.apache.commons.lang3.mutable.MutableObject)51 HashSet (java.util.HashSet)46 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)43 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)36 GroupByOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator)36 RecordDescriptor (org.apache.hyracks.api.dataflow.value.RecordDescriptor)33 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)29 AggregateOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator)28 SubplanOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.SubplanOperator)26 AggregateFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression)25