io.prestosql.sql.tree.QuerySpecification.getOrderBy()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(67)

本文整理了Java中io.prestosql.sql.tree.QuerySpecification.getOrderBy方法的一些代码示例,展示了QuerySpecification.getOrderBy的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。QuerySpecification.getOrderBy方法的具体详情如下:
包路径:io.prestosql.sql.tree.QuerySpecification
类名称:QuerySpecification
方法名:getOrderBy

QuerySpecification.getOrderBy介绍

暂无

代码示例

代码示例来源:origin: io.prestosql/presto-main

private void analyzeWindowFunctions(QuerySpecification node, List<Expression> outputExpressions, List<Expression> orderByExpressions)
{
  analysis.setWindowFunctions(node, analyzeWindowFunctions(node, outputExpressions));
  if (node.getOrderBy().isPresent()) {
    analysis.setOrderByWindowFunctions(node.getOrderBy().get(), analyzeWindowFunctions(node, orderByExpressions));
  }
}

代码示例来源:origin: prestosql/presto

private void analyzeWindowFunctions(QuerySpecification node, List<Expression> outputExpressions, List<Expression> orderByExpressions)
{
  analysis.setWindowFunctions(node, analyzeWindowFunctions(node, outputExpressions));
  if (node.getOrderBy().isPresent()) {
    analysis.setOrderByWindowFunctions(node.getOrderBy().get(), analyzeWindowFunctions(node, orderByExpressions));
  }
}

代码示例来源:origin: prestosql/presto

private PlanBuilder limit(PlanBuilder subPlan, QuerySpecification node)
{
  return limit(subPlan, node.getOrderBy(), node.getLimit());
}

代码示例来源:origin: prestosql/presto

private boolean hasAggregates(QuerySpecification node)
{
  ImmutableList.Builder<Node> toExtractBuilder = ImmutableList.builder();
  toExtractBuilder.addAll(node.getSelect().getSelectItems().stream()
      .filter(SingleColumn.class::isInstance)
      .collect(toImmutableList()));
  toExtractBuilder.addAll(getSortItemsFromOrderBy(node.getOrderBy()));
  node.getHaving().ifPresent(toExtractBuilder::add);
  List<FunctionCall> aggregates = extractAggregateFunctions(toExtractBuilder.build(), metadata.getFunctionRegistry());
  return !aggregates.isEmpty();
}

代码示例来源:origin: io.prestosql/presto-main

private List<Expression> analyzeOrderBy(QuerySpecification node, Scope orderByScope, List<Expression> outputExpressions)
{
  checkState(node.getOrderBy().isPresent(), "orderBy is absent");
  List<SortItem> sortItems = getSortItemsFromOrderBy(node.getOrderBy());
  if (node.getSelect().isDistinct()) {
    verifySelectDistinct(node, outputExpressions);
  }
  return analyzeOrderBy(node, sortItems, orderByScope);
}

代码示例来源:origin: prestosql/presto

private List<Expression> analyzeOrderBy(QuerySpecification node, Scope orderByScope, List<Expression> outputExpressions)
{
  checkState(node.getOrderBy().isPresent(), "orderBy is absent");
  List<SortItem> sortItems = getSortItemsFromOrderBy(node.getOrderBy());
  if (node.getSelect().isDistinct()) {
    verifySelectDistinct(node, outputExpressions);
  }
  return analyzeOrderBy(node, sortItems, orderByScope);
}

代码示例来源:origin: io.prestosql/presto-main

private boolean hasAggregates(QuerySpecification node)
{
  ImmutableList.Builder<Node> toExtractBuilder = ImmutableList.builder();
  toExtractBuilder.addAll(node.getSelect().getSelectItems().stream()
      .filter(SingleColumn.class::isInstance)
      .collect(toImmutableList()));
  toExtractBuilder.addAll(getSortItemsFromOrderBy(node.getOrderBy()));
  node.getHaving().ifPresent(toExtractBuilder::add);
  List<FunctionCall> aggregates = extractAggregateFunctions(toExtractBuilder.build(), metadata.getFunctionRegistry());
  return !aggregates.isEmpty();
}

代码示例来源:origin: io.prestosql/presto-main

private PlanBuilder limit(PlanBuilder subPlan, QuerySpecification node)
{
  return limit(subPlan, node.getOrderBy(), node.getLimit());
}

代码示例来源:origin: prestosql/presto

private PlanBuilder sort(PlanBuilder subPlan, QuerySpecification node)
{
  return sort(subPlan, node.getOrderBy(), node.getLimit(), analysis.getOrderByExpressions(node));
}

代码示例来源:origin: io.prestosql/presto-main

private PlanBuilder sort(PlanBuilder subPlan, QuerySpecification node)
{
  return sort(subPlan, node.getOrderBy(), node.getLimit(), analysis.getOrderByExpressions(node));
}

代码示例来源:origin: io.prestosql/presto-parser

@Override
protected R visitQuerySpecification(QuerySpecification node, C context)
{
  process(node.getSelect(), context);
  if (node.getFrom().isPresent()) {
    process(node.getFrom().get(), context);
  }
  if (node.getWhere().isPresent()) {
    process(node.getWhere().get(), context);
  }
  if (node.getGroupBy().isPresent()) {
    process(node.getGroupBy().get(), context);
  }
  if (node.getHaving().isPresent()) {
    process(node.getHaving().get(), context);
  }
  if (node.getOrderBy().isPresent()) {
    process(node.getOrderBy().get(), context);
  }
  return null;
}

代码示例来源:origin: io.prestosql/presto-parser

if (node.getOrderBy().isPresent()) {
  process(node.getOrderBy().get(), indent);

代码示例来源:origin: prestosql/presto

if (node.getOrderBy().isPresent()) {
  process(node.getOrderBy().get(), indent);

代码示例来源:origin: prestosql/presto

@Override
protected R visitQuerySpecification(QuerySpecification node, C context)
{
  process(node.getSelect(), context);
  if (node.getFrom().isPresent()) {
    process(node.getFrom().get(), context);
  }
  if (node.getWhere().isPresent()) {
    process(node.getWhere().get(), context);
  }
  if (node.getGroupBy().isPresent()) {
    process(node.getGroupBy().get(), context);
  }
  if (node.getHaving().isPresent()) {
    process(node.getHaving().get(), context);
  }
  if (node.getOrderBy().isPresent()) {
    process(node.getOrderBy().get(), context);
  }
  return null;
}

代码示例来源:origin: prestosql/presto

if (node.getOrderBy().isPresent()) {
  orderByScope = Optional.of(computeAndAssignOrderByScope(node.getOrderBy().get(), sourceScope, outputScope));
  orderByExpressions = analyzeOrderBy(node, orderByScope.get(), outputExpressions);
analyzeWindowFunctions(node, outputExpressions, orderByExpressions);
if (analysis.isAggregation(node) && node.getOrderBy().isPresent()) {
  computeAndAssignOrderByScopeWithAggregation(node.getOrderBy().get(), sourceScope, outputScope, orderByAggregations, groupByExpressions, orderByGroupingOperations);

代码示例来源:origin: prestosql/presto

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

代码示例来源:origin: prestosql/presto

private void validateShowStatsSubquery(ShowStats node, Query query, QuerySpecification querySpecification, Plan plan)
{
  // The following properties of SELECT subquery are required:
  //  - only one relation in FROM
  //  - only predicates that can be pushed down can be in the where clause
  //  - no group by
  //  - no having
  //  - no set quantifier
  Optional<FilterNode> filterNode = searchFrom(plan.getRoot())
      .where(FilterNode.class::isInstance)
      .findSingle();
  check(!filterNode.isPresent(), node, "Only predicates that can be pushed down are supported in the SHOW STATS WHERE clause");
  check(querySpecification.getFrom().isPresent(), node, "There must be exactly one table in query passed to SHOW STATS SELECT clause");
  check(querySpecification.getFrom().get() instanceof Table, node, "There must be exactly one table in query passed to SHOW STATS SELECT clause");
  check(!query.getWith().isPresent(), node, "WITH is not supported by SHOW STATS SELECT clause");
  check(!querySpecification.getOrderBy().isPresent(), node, "ORDER BY is not supported in SHOW STATS SELECT clause");
  check(!querySpecification.getLimit().isPresent(), node, "LIMIT is not supported by SHOW STATS SELECT clause");
  check(!querySpecification.getHaving().isPresent(), node, "HAVING is not supported in SHOW STATS SELECT clause");
  check(!querySpecification.getGroupBy().isPresent(), node, "GROUP BY is not supported in SHOW STATS SELECT clause");
  check(!querySpecification.getSelect().isDistinct(), node, "DISTINCT is not supported by SHOW STATS SELECT clause");
  List<SelectItem> selectItems = querySpecification.getSelect().getSelectItems();
  check(selectItems.size() == 1 && selectItems.get(0) instanceof AllColumns, node, "Only SELECT * is supported in SHOW STATS SELECT clause");
}

代码示例来源:origin: io.prestosql/presto-main

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

代码示例来源:origin: io.prestosql/presto-main

private void validateShowStatsSubquery(ShowStats node, Query query, QuerySpecification querySpecification, Plan plan)
{
  // The following properties of SELECT subquery are required:
  //  - only one relation in FROM
  //  - only predicates that can be pushed down can be in the where clause
  //  - no group by
  //  - no having
  //  - no set quantifier
  Optional<FilterNode> filterNode = searchFrom(plan.getRoot())
      .where(FilterNode.class::isInstance)
      .findSingle();
  check(!filterNode.isPresent(), node, "Only predicates that can be pushed down are supported in the SHOW STATS WHERE clause");
  check(querySpecification.getFrom().isPresent(), node, "There must be exactly one table in query passed to SHOW STATS SELECT clause");
  check(querySpecification.getFrom().get() instanceof Table, node, "There must be exactly one table in query passed to SHOW STATS SELECT clause");
  check(!query.getWith().isPresent(), node, "WITH is not supported by SHOW STATS SELECT clause");
  check(!querySpecification.getOrderBy().isPresent(), node, "ORDER BY is not supported in SHOW STATS SELECT clause");
  check(!querySpecification.getLimit().isPresent(), node, "LIMIT is not supported by SHOW STATS SELECT clause");
  check(!querySpecification.getHaving().isPresent(), node, "HAVING is not supported in SHOW STATS SELECT clause");
  check(!querySpecification.getGroupBy().isPresent(), node, "GROUP BY is not supported in SHOW STATS SELECT clause");
  check(!querySpecification.getSelect().isDistinct(), node, "DISTINCT is not supported by SHOW STATS SELECT clause");
  List<SelectItem> selectItems = querySpecification.getSelect().getSelectItems();
  check(selectItems.size() == 1 && selectItems.get(0) instanceof AllColumns, node, "Only SELECT * is supported in SHOW STATS SELECT clause");
}

代码示例来源:origin: prestosql/presto

builder = handleSubqueries(builder, node, outputs);
if (node.getOrderBy().isPresent()) {
  if (!analysis.isAggregation(node)) {
    builder = planBuilderFor(builder, analysis.getScope(node.getOrderBy().get()));
    List<Expression> orderByAggregates = analysis.getOrderByAggregates(node.getOrderBy().get());
    builder = project(builder, Iterables.concat(outputs, orderByAggregates));
    outputs = toSymbolReferences(computeOutputs(builder, outputs));
        .filter(expression -> !analysis.isColumnReference(expression))
        .collect(toImmutableList());
    builder = planBuilderFor(builder, analysis.getScope(node.getOrderBy().get()), complexOrderByAggregatesToRemap);
  builder = window(builder, node.getOrderBy().get());

相关文章