Search in sources :

Example 1 with OrderModifier

use of org.apache.asterix.lang.common.clause.OrderbyClause.OrderModifier in project asterixdb by apache.

the class FormatPrintVisitor method visit.

@Override
public Void visit(OrderbyClause oc, Integer step) throws CompilationException {
    out.print(skip(step) + "order by ");
    List<OrderModifier> mlist = oc.getModifierList();
    List<Expression> list = oc.getOrderbyList();
    int index = 0;
    int size = list.size();
    for (Expression expr : oc.getOrderbyList()) {
        expr.accept(this, step);
        OrderModifier orderModifier = mlist.get(index);
        if (orderModifier != OrderModifier.ASC) {
            out.print(" " + orderModifier.toString().toLowerCase());
        }
        if (++index < size) {
            out.print(COMMA);
        }
    }
    out.println();
    return null;
}
Also used : TypeReferenceExpression(org.apache.asterix.lang.common.expression.TypeReferenceExpression) Expression(org.apache.asterix.lang.common.base.Expression) TypeExpression(org.apache.asterix.lang.common.expression.TypeExpression) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) OrderModifier(org.apache.asterix.lang.common.clause.OrderbyClause.OrderModifier)

Example 2 with OrderModifier

use of org.apache.asterix.lang.common.clause.OrderbyClause.OrderModifier 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

Expression (org.apache.asterix.lang.common.base.Expression)2 OrderModifier (org.apache.asterix.lang.common.clause.OrderbyClause.OrderModifier)2 QuantifiedExpression (org.apache.asterix.lang.common.expression.QuantifiedExpression)2 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)1 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)1 TypeExpression (org.apache.asterix.lang.common.expression.TypeExpression)1 TypeReferenceExpression (org.apache.asterix.lang.common.expression.TypeReferenceExpression)1 QuantifiedPair (org.apache.asterix.lang.common.struct.QuantifiedPair)1 Mutable (org.apache.commons.lang3.mutable.Mutable)1 MutableObject (org.apache.commons.lang3.mutable.MutableObject)1 Pair (org.apache.hyracks.algebricks.common.utils.Pair)1 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)1 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)1 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)1 AggregateFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression)1 ConstantExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression)1 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)1 UnnestingFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.UnnestingFunctionCallExpression)1 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)1 OrderOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.OrderOperator)1