public static OrderBy ordering(SortItem... items) { return new OrderBy(ImmutableList.copyOf(items)); }
private static Optional<OrderBy> orderBy(List<SortItem> sortItems) { requireNonNull(sortItems, "sortItems is null"); if (sortItems.isEmpty()) { return Optional.empty(); } return Optional.of(new OrderBy(sortItems)); }
@Override public Node visitOver(SqlBaseParser.OverContext context) { Optional<OrderBy> orderBy = Optional.empty(); if (context.ORDER() != null) { orderBy = Optional.of(new OrderBy(getLocation(context.ORDER()), visit(context.sortItem(), SortItem.class))); } return new Window( getLocation(context), visit(context.partition, Expression.class), orderBy, visitIfPresent(context.windowFrame(), WindowFrame.class)); }
public FunctionCall getExpectedValue(SymbolAliases aliases) { List<Expression> symbolReferences = toSymbolReferences(args, aliases); if (isWindowFunction) { return new ExpectedWindowFunctionCall(symbolReferences); } Optional<OrderBy> orderByClause = Optional.empty(); if (!orderBy.isEmpty()) { orderByClause = Optional.of(new OrderBy(orderBy.stream() .map(item -> new SortItem( Symbol.from(aliases.get(item.getField())).toSymbolReference(), item.getOrdering(), item.getNullOrdering())) .collect(Collectors.toList()))); } return new FunctionCall(name, Optional.empty(), Optional.empty(), orderByClause, distinct, symbolReferences); }
@Test public void testSelectWithOrderBy() { assertStatement("SELECT * FROM table1 ORDER BY a", new Query( Optional.empty(), new QuerySpecification( selectList(new AllColumns()), Optional.of(new Table(QualifiedName.of("table1"))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new OrderBy(ImmutableList.of(new SortItem( new Identifier("a"), ASCENDING, UNDEFINED)))), Optional.empty()), Optional.empty(), Optional.empty())); }
orderBy = Optional.of(new OrderBy(getLocation(context.ORDER()), visit(context.sortItem(), SortItem.class)));
orderBy = Optional.of(new OrderBy(visit(context.sortItem(), SortItem.class)));
Optional.empty(), Optional.empty(), Optional.of(new OrderBy(ImmutableList.of(new SortItem(identifier("x"), DESCENDING, UNDEFINED)))), false, ImmutableList.of(identifier("x")))); Optional.empty(), Optional.empty(), Optional.of(new OrderBy(ImmutableList.of(new SortItem(new DereferenceExpression(new Identifier("t"), identifier("y")), ASCENDING, UNDEFINED)))), false, ImmutableList.of(new Identifier("x")))),
public static OrderBy ordering(SortItem... items) { return new OrderBy(ImmutableList.copyOf(items)); }
@Override public Node visitOver(SqlBaseParser.OverContext context) { Optional<OrderBy> orderBy = Optional.empty(); if (context.ORDER() != null) { orderBy = Optional.of(new OrderBy(getLocation(context.ORDER()), visit(context.sortItem(), SortItem.class))); } return new Window( getLocation(context), visit(context.partition, Expression.class), orderBy, visitIfPresent(context.windowFrame(), WindowFrame.class)); }
@Test public void testSelectWithOrderBy() { assertStatement("SELECT * FROM table1 ORDER BY a", new Query( Optional.empty(), new QuerySpecification( selectList(new AllColumns()), Optional.of(new Table(QualifiedName.of("table1"))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new OrderBy(ImmutableList.of(new SortItem( new Identifier("a"), ASCENDING, UNDEFINED)))), Optional.empty()), Optional.empty(), Optional.empty())); }
orderBy = Optional.of(new OrderBy(getLocation(context.ORDER()), visit(context.sortItem(), SortItem.class)));
Optional.empty(), Optional.empty(), Optional.of(new OrderBy(ImmutableList.of(new SortItem(identifier("x"), DESCENDING, UNDEFINED)))), false, ImmutableList.of(identifier("x")))); Optional.empty(), Optional.empty(), Optional.of(new OrderBy(ImmutableList.of(new SortItem(new DereferenceExpression(new Identifier("t"), identifier("y")), ASCENDING, UNDEFINED)))), false, ImmutableList.of(new Identifier("x")))),
orderBy = Optional.of(new OrderBy(visit(context.sortItem(), SortItem.class)));