Search in sources :

Example 66 with MutableObject

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.mutable.MutableObject in project asterixdb by apache.

the class InlineSubplanInputForNestedTupleSourceRule method applySpecialFlattening.

private Pair<Boolean, LinkedHashMap<LogicalVariable, LogicalVariable>> applySpecialFlattening(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    SubplanOperator subplanOp = (SubplanOperator) opRef.getValue();
    Mutable<ILogicalOperator> inputOpRef = subplanOp.getInputs().get(0);
    LinkedHashMap<LogicalVariable, LogicalVariable> replacedVarMap = new LinkedHashMap<>();
    // Recursively applies this rule to the nested plan of the subplan operator,
    // for the case where there are nested subplan operators within {@code subplanOp}.
    Pair<Boolean, LinkedHashMap<LogicalVariable, LogicalVariable>> result = rewriteSubplanOperator(subplanOp.getNestedPlans().get(0).getRoots().get(0), context);
    ILogicalOperator inputOpBackup = inputOpRef.getValue();
    // Gets live variables and covering variables from the subplan's input operator.
    Pair<ILogicalOperator, Set<LogicalVariable>> primaryOpAndVars = EquivalenceClassUtils.findOrCreatePrimaryKeyOpAndVariables(inputOpBackup, false, context);
    ILogicalOperator inputOp = primaryOpAndVars.first;
    Set<LogicalVariable> primaryKeyVars = primaryOpAndVars.second;
    inputOpRef.setValue(inputOp);
    Set<LogicalVariable> liveVars = new HashSet<>();
    VariableUtilities.getLiveVariables(inputOp, liveVars);
    Pair<Set<LogicalVariable>, Mutable<ILogicalOperator>> notNullVarsAndTopJoinRef = SubplanFlatteningUtil.inlineLeftNtsInSubplanJoin(subplanOp, context);
    if (notNullVarsAndTopJoinRef.first == null) {
        inputOpRef.setValue(inputOpBackup);
        return new Pair<>(false, replacedVarMap);
    }
    Set<LogicalVariable> notNullVars = notNullVarsAndTopJoinRef.first;
    Mutable<ILogicalOperator> topJoinRef = notNullVarsAndTopJoinRef.second;
    // Creates a group-by operator.
    List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> groupByList = new ArrayList<Pair<LogicalVariable, Mutable<ILogicalExpression>>>();
    List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> groupByDecorList = new ArrayList<Pair<LogicalVariable, Mutable<ILogicalExpression>>>();
    GroupByOperator groupbyOp = new GroupByOperator(groupByList, groupByDecorList, subplanOp.getNestedPlans());
    for (LogicalVariable coverVar : primaryKeyVars) {
        LogicalVariable newVar = context.newVar();
        groupByList.add(new Pair<>(newVar, new MutableObject<>(new VariableReferenceExpression(coverVar))));
        // Adds variables for replacements in ancestors.
        replacedVarMap.put(coverVar, newVar);
    }
    for (LogicalVariable liveVar : liveVars) {
        if (primaryKeyVars.contains(liveVar)) {
            continue;
        }
        groupByDecorList.add(new Pair<>(null, new MutableObject<>(new VariableReferenceExpression(liveVar))));
    }
    groupbyOp.getInputs().add(new MutableObject<>(topJoinRef.getValue()));
    if (!notNullVars.isEmpty()) {
        // Adds a select operator into the nested plan for group-by to remove tuples with NULL on {@code assignVar}, i.e.,
        // subplan input tuples that are filtered out within a subplan.
        List<Mutable<ILogicalExpression>> nullCheckExprRefs = new ArrayList<>();
        for (LogicalVariable notNullVar : notNullVars) {
            Mutable<ILogicalExpression> filterVarExpr = new MutableObject<>(new VariableReferenceExpression(notNullVar));
            List<Mutable<ILogicalExpression>> args = new ArrayList<>();
            args.add(filterVarExpr);
            List<Mutable<ILogicalExpression>> argsForNotFunction = new ArrayList<>();
            argsForNotFunction.add(new MutableObject<>(new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.IS_MISSING), args)));
            nullCheckExprRefs.add(new MutableObject<>(new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.NOT), argsForNotFunction)));
        }
        Mutable<ILogicalExpression> selectExprRef = nullCheckExprRefs.size() > 1 ? new MutableObject<>(new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.AND), nullCheckExprRefs)) : nullCheckExprRefs.get(0);
        SelectOperator selectOp = new SelectOperator(selectExprRef, false, null);
        topJoinRef.setValue(selectOp);
        selectOp.getInputs().add(new MutableObject<>(new NestedTupleSourceOperator(new MutableObject<>(groupbyOp))));
    } else {
        // The original join operator in the Subplan is a left-outer join.
        // Therefore, no null-check variable is injected and no SelectOperator needs to be added.
        topJoinRef.setValue(new NestedTupleSourceOperator(new MutableObject<>(groupbyOp)));
    }
    opRef.setValue(groupbyOp);
    OperatorManipulationUtil.computeTypeEnvironmentBottomUp(groupbyOp, context);
    VariableUtilities.substituteVariables(groupbyOp, result.second, context);
    replacedVarMap.putAll(result.second);
    return new Pair<>(true, replacedVarMap);
}
Also used : NestedTupleSourceOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.NestedTupleSourceOperator) HashSet(java.util.HashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) SubplanOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.SubplanOperator) SelectOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.SelectOperator) HashSet(java.util.HashSet) Pair(org.apache.hyracks.algebricks.common.utils.Pair) MutableObject(org.apache.commons.lang3.mutable.MutableObject) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression) LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) GroupByOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)

Example 67 with MutableObject

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.mutable.MutableObject in project asterixdb by apache.

the class InlineSubplanInputForNestedTupleSourceRule method applyGeneralFlattening.

private Pair<Boolean, LinkedHashMap<LogicalVariable, LogicalVariable>> applyGeneralFlattening(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    SubplanOperator subplanOp = (SubplanOperator) opRef.getValue();
    if (!SubplanFlatteningUtil.containsOperators(subplanOp, ImmutableSet.of(LogicalOperatorTag.DATASOURCESCAN, LogicalOperatorTag.INNERJOIN, // We don't have nested runtime for union-all and distinct hence we have to include them here.
    LogicalOperatorTag.LEFTOUTERJOIN, LogicalOperatorTag.UNIONALL, LogicalOperatorTag.DISTINCT))) {
        return new Pair<>(false, new LinkedHashMap<>());
    }
    Mutable<ILogicalOperator> inputOpRef = subplanOp.getInputs().get(0);
    ILogicalOperator inputOpBackup = inputOpRef.getValue();
    // Creates parameters for the left outer join operator.
    Pair<ILogicalOperator, Set<LogicalVariable>> primaryOpAndVars = EquivalenceClassUtils.findOrCreatePrimaryKeyOpAndVariables(inputOpBackup, true, context);
    ILogicalOperator inputOp = primaryOpAndVars.first;
    Set<LogicalVariable> primaryKeyVars = primaryOpAndVars.second;
    inputOpRef.setValue(inputOp);
    Set<LogicalVariable> inputLiveVars = new HashSet<>();
    VariableUtilities.getLiveVariables(inputOp, inputLiveVars);
    Pair<Map<LogicalVariable, LogicalVariable>, List<Pair<IOrder, Mutable<ILogicalExpression>>>> varMapAndOrderExprs = SubplanFlatteningUtil.inlineAllNestedTupleSource(subplanOp, context);
    Map<LogicalVariable, LogicalVariable> varMap = varMapAndOrderExprs.first;
    if (varMap == null) {
        inputOpRef.setValue(inputOpBackup);
        return new Pair<>(false, new LinkedHashMap<>());
    }
    Mutable<ILogicalOperator> lowestAggregateRefInSubplan = SubplanFlatteningUtil.findLowestAggregate(subplanOp.getNestedPlans().get(0).getRoots().get(0));
    Mutable<ILogicalOperator> rightInputOpRef = lowestAggregateRefInSubplan.getValue().getInputs().get(0);
    ILogicalOperator rightInputOp = rightInputOpRef.getValue();
    // Creates a variable to indicate whether a left input tuple is killed in the plan rooted at rightInputOp.
    LogicalVariable assignVar = context.newVar();
    ILogicalOperator assignOp = new AssignOperator(assignVar, new MutableObject<>(ConstantExpression.TRUE));
    assignOp.getInputs().add(rightInputOpRef);
    context.computeAndSetTypeEnvironmentForOperator(assignOp);
    rightInputOpRef = new MutableObject<>(assignOp);
    // Constructs the join predicate for the leftOuter join.
    List<Mutable<ILogicalExpression>> joinPredicates = new ArrayList<>();
    for (LogicalVariable liveVar : primaryKeyVars) {
        List<Mutable<ILogicalExpression>> arguments = new ArrayList<>();
        arguments.add(new MutableObject<>(new VariableReferenceExpression(liveVar)));
        LogicalVariable rightVar = varMap.get(liveVar);
        arguments.add(new MutableObject<>(new VariableReferenceExpression(rightVar)));
        ILogicalExpression expr = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(AlgebricksBuiltinFunctions.EQ), arguments);
        joinPredicates.add(new MutableObject<>(expr));
    }
    ILogicalExpression joinExpr = joinPredicates.size() > 1 ? new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(AlgebricksBuiltinFunctions.AND), joinPredicates) : joinPredicates.size() > 0 ? joinPredicates.get(0).getValue() : ConstantExpression.TRUE;
    LeftOuterJoinOperator leftOuterJoinOp = new LeftOuterJoinOperator(new MutableObject<>(joinExpr), inputOpRef, rightInputOpRef);
    OperatorManipulationUtil.computeTypeEnvironmentBottomUp(rightInputOp, context);
    context.computeAndSetTypeEnvironmentForOperator(leftOuterJoinOp);
    // Creates group-by operator.
    List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> groupByList = new ArrayList<Pair<LogicalVariable, Mutable<ILogicalExpression>>>();
    List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> groupByDecorList = new ArrayList<Pair<LogicalVariable, Mutable<ILogicalExpression>>>();
    List<ILogicalPlan> nestedPlans = new ArrayList<>();
    GroupByOperator groupbyOp = new GroupByOperator(groupByList, groupByDecorList, nestedPlans);
    LinkedHashMap<LogicalVariable, LogicalVariable> replacedVarMap = new LinkedHashMap<>();
    for (LogicalVariable liveVar : primaryKeyVars) {
        LogicalVariable newVar = context.newVar();
        groupByList.add(new Pair<>(newVar, new MutableObject<>(new VariableReferenceExpression(liveVar))));
        // Adds variables for replacements in ancestors.
        replacedVarMap.put(liveVar, newVar);
    }
    for (LogicalVariable liveVar : inputLiveVars) {
        if (primaryKeyVars.contains(liveVar)) {
            continue;
        }
        groupByDecorList.add(new Pair<>(null, new MutableObject<>(new VariableReferenceExpression(liveVar))));
    }
    // Sets up the nested plan for the groupby operator.
    Mutable<ILogicalOperator> aggOpRef = subplanOp.getNestedPlans().get(0).getRoots().get(0);
    // Clears the input of the lowest aggregate.
    lowestAggregateRefInSubplan.getValue().getInputs().clear();
    Mutable<ILogicalOperator> currentOpRef = lowestAggregateRefInSubplan;
    // Adds an optional order operator.
    List<Pair<IOrder, Mutable<ILogicalExpression>>> orderExprs = varMapAndOrderExprs.second;
    if (!orderExprs.isEmpty()) {
        OrderOperator orderOp = new OrderOperator(orderExprs);
        currentOpRef = new MutableObject<>(orderOp);
        lowestAggregateRefInSubplan.getValue().getInputs().add(currentOpRef);
    }
    // Adds a select operator into the nested plan for group-by to remove tuples with NULL on {@code assignVar}, i.e.,
    // subplan input tuples that are filtered out within a subplan.
    Mutable<ILogicalExpression> filterVarExpr = new MutableObject<>(new VariableReferenceExpression(assignVar));
    List<Mutable<ILogicalExpression>> args = new ArrayList<>();
    args.add(filterVarExpr);
    List<Mutable<ILogicalExpression>> argsForNotFunction = new ArrayList<>();
    argsForNotFunction.add(new MutableObject<>(new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.IS_MISSING), args)));
    SelectOperator selectOp = new SelectOperator(new MutableObject<>(new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.NOT), argsForNotFunction)), false, null);
    currentOpRef.getValue().getInputs().add(new MutableObject<>(selectOp));
    selectOp.getInputs().add(new MutableObject<>(new NestedTupleSourceOperator(new MutableObject<>(groupbyOp))));
    List<Mutable<ILogicalOperator>> nestedRoots = new ArrayList<>();
    nestedRoots.add(aggOpRef);
    nestedPlans.add(new ALogicalPlanImpl(nestedRoots));
    groupbyOp.getInputs().add(new MutableObject<>(leftOuterJoinOp));
    // Replaces subplan with the group-by operator.
    opRef.setValue(groupbyOp);
    OperatorManipulationUtil.computeTypeEnvironmentBottomUp(groupbyOp, context);
    // Recursively applys this rule to the nested plan of the subplan operator,
    // for the case where there are nested subplan operators within {@code subplanOp}.
    Pair<Boolean, LinkedHashMap<LogicalVariable, LogicalVariable>> result = rewriteSubplanOperator(rightInputOpRef, context);
    VariableUtilities.substituteVariables(leftOuterJoinOp, result.second, context);
    VariableUtilities.substituteVariables(groupbyOp, result.second, context);
    // No var mapping from the right input operator should be populated up.
    return new Pair<>(true, replacedVarMap);
}
Also used : NestedTupleSourceOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.NestedTupleSourceOperator) HashSet(java.util.HashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ArrayList(java.util.ArrayList) LeftOuterJoinOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.LeftOuterJoinOperator) LinkedHashMap(java.util.LinkedHashMap) SubplanOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.SubplanOperator) SelectOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.SelectOperator) ALogicalPlanImpl(org.apache.hyracks.algebricks.core.algebra.plan.ALogicalPlanImpl) ArrayList(java.util.ArrayList) List(java.util.List) Pair(org.apache.hyracks.algebricks.common.utils.Pair) HashSet(java.util.HashSet) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression) MutableObject(org.apache.commons.lang3.mutable.MutableObject) LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) GroupByOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator) IOrder(org.apache.hyracks.algebricks.core.algebra.operators.logical.OrderOperator.IOrder) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) OrderOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.OrderOperator) AssignOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) ILogicalPlan(org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 68 with MutableObject

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.mutable.MutableObject in project asterixdb by apache.

the class InlineAllNtsInSubplanVisitor method visitOrderOperator.

@Override
public ILogicalOperator visitOrderOperator(OrderOperator op, Void arg) throws AlgebricksException {
    visitSingleInputOperator(op);
    if (correlatedKeyVars.isEmpty()) {
        return op;
    }
    orderingExprs.clear();
    orderingExprs.addAll(cloneOrderingExpression(op.getOrderExpressions()));
    List<Pair<IOrder, Mutable<ILogicalExpression>>> orderExprList = new ArrayList<>();
    // Adds keyVars to the prefix of sorting columns.
    for (LogicalVariable keyVar : correlatedKeyVars) {
        orderExprList.add(new Pair<IOrder, Mutable<ILogicalExpression>>(OrderOperator.ASC_ORDER, new MutableObject<ILogicalExpression>(new VariableReferenceExpression(keyVar))));
    }
    orderExprList.addAll(op.getOrderExpressions());
    // Creates an order operator with the new expression list.
    OrderOperator orderOp = new OrderOperator(orderExprList);
    orderOp.getInputs().addAll(op.getInputs());
    context.computeAndSetTypeEnvironmentForOperator(orderOp);
    return orderOp;
}
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) IOrder(org.apache.hyracks.algebricks.core.algebra.operators.logical.OrderOperator.IOrder) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) ArrayList(java.util.ArrayList) OrderOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.OrderOperator) Pair(org.apache.hyracks.algebricks.common.utils.Pair) MutableObject(org.apache.commons.lang3.mutable.MutableObject)

Example 69 with MutableObject

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.mutable.MutableObject in project asterixdb by apache.

the class IntroduceLSMComponentFilterRule method changePlan.

private void changePlan(List<IOptimizableFuncExpr> optFuncExprs, AbstractLogicalOperator op, Dataset dataset, IOptimizationContext context) throws AlgebricksException {
    Queue<Mutable<ILogicalOperator>> queue = new LinkedList<>(op.getInputs());
    while (!queue.isEmpty()) {
        AbstractLogicalOperator descendantOp = (AbstractLogicalOperator) queue.poll().getValue();
        if (descendantOp == null) {
            continue;
        }
        if (descendantOp.getOperatorTag() == LogicalOperatorTag.DATASOURCESCAN) {
            DataSourceScanOperator dataSourceScanOp = (DataSourceScanOperator) descendantOp;
            DataSource ds = (DataSource) dataSourceScanOp.getDataSource();
            if (dataset.getDatasetName().compareTo(((DatasetDataSource) ds).getDataset().getDatasetName()) == 0) {
                List<LogicalVariable> minFilterVars = new ArrayList<>();
                List<LogicalVariable> maxFilterVars = new ArrayList<>();
                AssignOperator assignOp = createAssignOperator(optFuncExprs, minFilterVars, maxFilterVars, context);
                dataSourceScanOp.setMinFilterVars(minFilterVars);
                dataSourceScanOp.setMaxFilterVars(maxFilterVars);
                List<Mutable<ILogicalExpression>> additionalFilteringExpressions = new ArrayList<>();
                for (LogicalVariable var : assignOp.getVariables()) {
                    additionalFilteringExpressions.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(var)));
                }
                dataSourceScanOp.setAdditionalFilteringExpressions(additionalFilteringExpressions);
                assignOp.getInputs().add(new MutableObject<>(dataSourceScanOp.getInputs().get(0).getValue()));
                dataSourceScanOp.getInputs().get(0).setValue(assignOp);
            }
        } else if (descendantOp.getOperatorTag() == LogicalOperatorTag.UNNEST_MAP) {
            UnnestMapOperator unnestMapOp = (UnnestMapOperator) descendantOp;
            ILogicalExpression unnestExpr = unnestMapOp.getExpressionRef().getValue();
            if (unnestExpr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
                AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) unnestExpr;
                FunctionIdentifier fid = f.getFunctionIdentifier();
                if (!fid.equals(BuiltinFunctions.INDEX_SEARCH)) {
                    throw new IllegalStateException();
                }
                AccessMethodJobGenParams jobGenParams = new AccessMethodJobGenParams();
                jobGenParams.readFromFuncArgs(f.getArguments());
                if (dataset.getDatasetName().compareTo(jobGenParams.datasetName) == 0) {
                    List<LogicalVariable> minFilterVars = new ArrayList<>();
                    List<LogicalVariable> maxFilterVars = new ArrayList<>();
                    AssignOperator assignOp = createAssignOperator(optFuncExprs, minFilterVars, maxFilterVars, context);
                    unnestMapOp.setMinFilterVars(minFilterVars);
                    unnestMapOp.setMaxFilterVars(maxFilterVars);
                    List<Mutable<ILogicalExpression>> additionalFilteringExpressions = new ArrayList<>();
                    for (LogicalVariable var : assignOp.getVariables()) {
                        additionalFilteringExpressions.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(var)));
                    }
                    unnestMapOp.setAdditionalFilteringExpressions(additionalFilteringExpressions);
                    assignOp.getInputs().add(new MutableObject<>(unnestMapOp.getInputs().get(0).getValue()));
                    unnestMapOp.getInputs().get(0).setValue(assignOp);
                }
            }
        }
        queue.addAll(descendantOp.getInputs());
    }
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) UnnestMapOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.UnnestMapOperator) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ArrayList(java.util.ArrayList) AssignOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator) LinkedList(java.util.LinkedList) DataSource(org.apache.asterix.metadata.declared.DataSource) DatasetDataSource(org.apache.asterix.metadata.declared.DatasetDataSource) Mutable(org.apache.commons.lang3.mutable.Mutable) FunctionIdentifier(org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) DataSourceScanOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.DataSourceScanOperator) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) MutableObject(org.apache.commons.lang3.mutable.MutableObject)

Example 70 with MutableObject

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.mutable.MutableObject in project asterixdb by apache.

the class LangExpressionToPlanTranslator method visit.

@Override
public Pair<ILogicalOperator, LogicalVariable> visit(OrderbyClause oc, Mutable<ILogicalOperator> tupSource) throws CompilationException {
    OrderOperator ord = new OrderOperator();
    Iterator<OrderModifier> modifIter = oc.getModifierList().iterator();
    Mutable<ILogicalOperator> topOp = tupSource;
    for (Expression e : oc.getOrderbyList()) {
        Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = langExprToAlgExpression(e, topOp);
        OrderModifier m = modifIter.next();
        OrderOperator.IOrder comp = (m == OrderModifier.ASC) ? OrderOperator.ASC_ORDER : OrderOperator.DESC_ORDER;
        ord.getOrderExpressions().add(new Pair<>(comp, new MutableObject<>(p.first)));
        topOp = p.second;
    }
    ord.getInputs().add(topOp);
    if (oc.getNumTuples() > 0) {
        ord.getAnnotations().put(OperatorAnnotations.CARDINALITY, oc.getNumTuples());
    }
    if (oc.getNumFrames() > 0) {
        ord.getAnnotations().put(OperatorAnnotations.MAX_NUMBER_FRAMES, oc.getNumFrames());
    }
    if (oc.getRangeMap() != null) {
        Iterator<OrderModifier> orderModifIter = oc.getModifierList().iterator();
        boolean ascending = (orderModifIter.next() == OrderModifier.ASC);
        RangeMapBuilder.verifyRangeOrder(oc.getRangeMap(), ascending);
        ord.getAnnotations().put(OperatorAnnotations.USE_RANGE_CONNECTOR, oc.getRangeMap());
    }
    return new Pair<>(ord, null);
}
Also used : ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) OrderOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.OrderOperator) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) AggregateFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression) Expression(org.apache.asterix.lang.common.base.Expression) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression) ConstantExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) UnnestingFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.UnnestingFunctionCallExpression) OrderModifier(org.apache.asterix.lang.common.clause.OrderbyClause.OrderModifier) MutableObject(org.apache.commons.lang3.mutable.MutableObject) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) Pair(org.apache.hyracks.algebricks.common.utils.Pair) QuantifiedPair(org.apache.asterix.lang.common.struct.QuantifiedPair)

Aggregations

MutableObject (org.apache.commons.lang3.mutable.MutableObject)111 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)60 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)58 ArrayList (java.util.ArrayList)55 Mutable (org.apache.commons.lang3.mutable.Mutable)55 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)52 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)49 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)28 Pair (org.apache.hyracks.algebricks.common.utils.Pair)27 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)23 List (java.util.List)22 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)21 ConstantExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression)18 ILogicalPlan (org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan)17 AggregateFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression)14 Test (org.junit.Test)14 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)13 UnnestingFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.UnnestingFunctionCallExpression)13 NestedTupleSourceOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.NestedTupleSourceOperator)13 HashSet (java.util.HashSet)12