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;
}
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);
}
Aggregations