@Override protected R visitSortItem(SortItem node, C context) { return process(node.getSortKey(), context); }
StringBuilder builder = new StringBuilder(); builder.append(formatExpression(input.getSortKey(), parameters));
private void verifySelectDistinct(QuerySpecification node, List<Expression> outputExpressions) { for (SortItem item : node.getOrderBy().get().getSortItems()) { Expression expression = item.getSortKey(); if (expression instanceof LongLiteral) { continue; } Expression rewrittenOrderByExpression = ExpressionTreeRewriter.rewriteWith(new OrderByExpressionRewriter(extractNamedOutputExpressions(node.getSelect())), expression); int index = outputExpressions.indexOf(rewrittenOrderByExpression); if (index == -1) { throw new SemanticException(ORDER_BY_MUST_BE_IN_SELECT, node.getSelect(), "For SELECT DISTINCT, ORDER BY expressions must appear in select list"); } if (!isDeterministic(expression)) { throw new SemanticException(NONDETERMINISTIC_ORDER_BY_EXPRESSION_WITH_SELECT_DISTINCT, expression, "Non deterministic ORDER BY expression is not supported with SELECT DISTINCT"); } } }
Expression expression = item.getSortKey();
@Override public Boolean visitWindow(Window node, Void context) { for (Expression expression : node.getPartitionBy()) { if (!process(expression, context)) { throw new SemanticException(MUST_BE_AGGREGATE_OR_GROUP_BY, expression, "PARTITION BY expression '%s' must be an aggregate expression or appear in GROUP BY clause", expression); } } for (SortItem sortItem : getSortItemsFromOrderBy(node.getOrderBy())) { Expression expression = sortItem.getSortKey(); if (!process(expression, context)) { throw new SemanticException(MUST_BE_AGGREGATE_OR_GROUP_BY, expression, "ORDER BY expression '%s' must be an aggregate expression or appear in GROUP BY clause", expression); } } if (node.getFrame().isPresent()) { process(node.getFrame().get(), context); } return true; }
Symbol symbol = subPlan.translate(item.getSortKey());
process(sortItem.getSortKey(), context); Type type = getExpressionType(sortItem.getSortKey()); if (!type.isOrderable()) { throw new SemanticException(TYPE_MISMATCH, node, "%s is not orderable, and therefore cannot be used in window function ORDER BY", type); Type sortKeyType = process(sortItem.getSortKey(), context); if (!sortKeyType.isOrderable()) { throw new SemanticException(TYPE_MISMATCH, node, "ORDER BY can only be applied to orderable types (actual: %s)", sortKeyType.getDisplayName());
private static Function<SortItem, String> sortItemFormatterFunction(Function<QualifiedName, String> tableNameMapper, Optional<Function<String, String>> columnNameMapper, List<String> queryWithTables, char escapeIdentifier) { return input -> { StringBuilder builder = new StringBuilder(); builder.append(formatExpression(input.getSortKey(), tableNameMapper, columnNameMapper, queryWithTables, escapeIdentifier)); switch (input.getOrdering()) { case ASCENDING: builder.append(" ASC"); break; case DESCENDING: builder.append(" DESC"); break; default: throw new UnsupportedOperationException("unknown ordering: " + input.getOrdering()); } switch (input.getNullOrdering()) { case FIRST: builder.append(" NULLS FIRST"); break; case LAST: builder.append(" NULLS LAST"); break; case UNDEFINED: // no op break; default: throw new UnsupportedOperationException("unknown null ordering: " + input.getNullOrdering()); } return builder.toString(); }; }
if (orderByOutside != null) { orderBy = orderByOutside.stream() .map(e -> new Ordering(e.getOrdering(), mapper.apply(e.getSortKey()), e.getSortKey().toString())) .collect(Collectors.toList()); } else { orderBy = queryBody.getOrderBy().map(v -> v.getSortItems().stream().map(item -> new Ordering(item.getOrdering(), mapper.apply(item.getSortKey()), item.getSortKey().toString())) .collect(Collectors.toList())).orElse(ImmutableList.of());
node.getOrderBy().ifPresent((orderBy -> { for (SortItem sortItem : orderBy.getSortItems()) { String expression = RakamSqlFormatter.formatExpression(sortItem.getSortKey(), qualifiedNameStringFunction, columnMappingFunction, ' '); reportRequest.orderBys.add(new GARequest.ReportRequest.OrderBy(expression, sortItem.getOrdering()));
@Override protected R visitSortItem(SortItem node, C context) { return process(node.getSortKey(), context); }
@Override protected R visitSortItem(SortItem node, C context) { return process(node.getSortKey(), context); }
StringBuilder builder = new StringBuilder(); builder.append(formatExpression(input.getSortKey(), unmangleNames));
StringBuilder builder = new StringBuilder(); builder.append(formatExpression(input.getSortKey(), unmangleNames));
StringBuilder builder = new StringBuilder(); builder.append(formatExpression(input.getSortKey(), parameters));
@Override public R visitWindow(Window node, C context) { for (Expression expression : node.getPartitionBy()) { process(expression, context); } for (SortItem sortItem : node.getOrderBy()) { process(sortItem.getSortKey(), context); } if (node.getFrame().isPresent()) { process(node.getFrame().get(), context); } return null; }
Expression expression = item.getSortKey();
@Override public Boolean visitWindow(Window node, Void context) { for (Expression expression : node.getPartitionBy()) { if (!process(expression, context)) { throw new SemanticException(MUST_BE_AGGREGATE_OR_GROUP_BY, expression, "PARTITION BY expression '%s' must be an aggregate expression or appear in GROUP BY clause", expression); } } for (SortItem sortItem : node.getOrderBy()) { Expression expression = sortItem.getSortKey(); if (!process(expression, context)) { throw new SemanticException(MUST_BE_AGGREGATE_OR_GROUP_BY, expression, "ORDER BY expression '%s' must be an aggregate expression or appear in GROUP BY clause", expression); } } if (node.getFrame().isPresent()) { process(node.getFrame().get(), context); } return true; }
private List<FunctionCall> extractAggregates(QuerySpecification node) { AggregateExtractor extractor = new AggregateExtractor(metadata); for (SelectItem item : node.getSelect().getSelectItems()) { if (item instanceof SingleColumn) { extractor.process(((SingleColumn) item).getExpression(), null); } } for (SortItem item : node.getOrderBy()) { extractor.process(item.getSortKey(), null); } if (node.getHaving().isPresent()) { extractor.process(node.getHaving().get(), null); } List<FunctionCall> aggregates = extractor.getAggregates(); analysis.setAggregates(node, aggregates); return aggregates; }
nestedExtractor.process(sortItem.getSortKey(), null);