io.prestosql.sql.tree.Query类的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(402)

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

Query介绍

暂无

代码示例

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

public static Query query(QueryBody body)
  {
    return new Query(
        Optional.empty(),
        body,
        Optional.empty(),
        Optional.empty());
  }
}

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

@Override
public Node visitQuery(SqlBaseParser.QueryContext context)
{
  Query body = (Query) visit(context.queryNoWith());
  return new Query(
      getLocation(context),
      visitIfPresent(context.with(), With.class),
      body.getQueryBody(),
      body.getOrderBy(),
      body.getLimit());
}

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

@Override
protected R visitQuery(Query node, C context)
{
  if (node.getWith().isPresent()) {
    process(node.getWith().get(), context);
  }
  process(node.getQueryBody(), context);
  if (node.getOrderBy().isPresent()) {
    process(node.getOrderBy().get(), context);
  }
  return null;
}

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

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

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

@Override
protected Void visitQuery(Query node, Integer indentLevel)
{
  print(indentLevel, "Query ");
  indentLevel++;
  print(indentLevel, "QueryBody");
  process(node.getQueryBody(), indentLevel);
  if (node.getOrderBy().isPresent()) {
    print(indentLevel, "OrderBy");
    process(node.getOrderBy().get(), indentLevel + 1);
  }
  if (node.getLimit().isPresent()) {
    print(indentLevel, "Limit: " + node.getLimit().get());
  }
  return null;
}

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

QueryBody innerQuery = createSelectClause.getQueryBody();
io.prestosql.sql.tree.Query zeroRowsQuery;
if (innerQuery instanceof QuerySpecification) {
      Optional.of("0"));
  zeroRowsQuery = new io.prestosql.sql.tree.Query(createSelectClause.getWith(), innerQuery, Optional.empty(), Optional.empty());
  zeroRowsQuery = new io.prestosql.sql.tree.Query(createSelectClause.getWith(), innerQuery, Optional.empty(), Optional.of("0"));

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

@Override
protected Void visitQuery(Query node, Integer indent)
  if (node.getWith().isPresent()) {
    With with = node.getWith().get();
    append(indent, "WITH");
    if (with.isRecursive()) {
  processRelation(node.getQueryBody(), indent);
  if (node.getOrderBy().isPresent()) {
    process(node.getOrderBy().get(), indent);
  if (node.getLimit().isPresent()) {
    append(indent, "LIMIT " + node.getLimit().get())
        .append('\n');

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

@Override
protected Node visitShowStats(ShowStats node, Void context)
{
  checkState(queryExplainer.isPresent(), "Query explainer must be provided for SHOW STATS SELECT");
  if (node.getRelation() instanceof TableSubquery) {
    Query query = ((TableSubquery) node.getRelation()).getQuery();
    QuerySpecification specification = (QuerySpecification) query.getQueryBody();
    Plan plan = queryExplainer.get().getLogicalPlan(session, new Query(Optional.empty(), specification, Optional.empty(), Optional.empty()), parameters, warningCollector);
    validateShowStatsSubquery(node, query, specification, plan);
    Table table = (Table) specification.getFrom().get();
    Constraint<ColumnHandle> constraint = getConstraint(plan);
    return rewriteShowStats(node, table, constraint);
  }
  else if (node.getRelation() instanceof Table) {
    Table table = (Table) node.getRelation();
    return rewriteShowStats(node, table, Constraint.alwaysTrue());
  }
  else {
    throw new IllegalArgumentException("Expected either TableSubquery or Table as relation");
  }
}

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

@Override
protected Scope visitQuery(Query node, Optional<Scope> scope)
{
  Scope withScope = analyzeWith(node, scope);
  Scope queryBodyScope = process(node.getQueryBody(), withScope);
  if (node.getOrderBy().isPresent()) {
    analyzeOrderBy(node, queryBodyScope);
  }
  else {
    analysis.setOrderByExpressions(node, emptyList());
  }
  // Input fields == Output fields
  analysis.setOutputExpressions(node, descriptorToFields(queryBodyScope));
  Scope queryScope = Scope.builder()
      .withParent(withScope)
      .withRelationType(RelationId.of(node), queryBodyScope.getRelationType())
      .build();
  analysis.setScope(node, queryScope);
  return queryScope;
}

代码示例来源: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 PlanBuilder planQueryBody(Query query)
{
  RelationPlan relationPlan = new RelationPlanner(analysis, symbolAllocator, idAllocator, lambdaDeclarationToSymbolMap, metadata, session)
      .process(query.getQueryBody(), null);
  return planBuilderFor(relationPlan);
}

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

private void analyzeOrderBy(Query node, Scope orderByScope)
{
  checkState(node.getOrderBy().isPresent(), "orderBy is absent");
  List<SortItem> sortItems = getSortItemsFromOrderBy(node.getOrderBy());
  analyzeOrderBy(node, sortItems, orderByScope);
}

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

@Override
  public int hashCode()
  {
    return query.hashCode();
  }
}

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

@Override
protected Void visitQuery(Query node, Integer indent)
  if (node.getWith().isPresent()) {
    With with = node.getWith().get();
    append(indent, "WITH");
    if (with.isRecursive()) {
  processRelation(node.getQueryBody(), indent);
  if (node.getOrderBy().isPresent()) {
    process(node.getOrderBy().get(), indent);
  if (node.getLimit().isPresent()) {
    append(indent, "LIMIT " + node.getLimit().get())
        .append('\n');

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

@Override
protected Node visitShowStats(ShowStats node, Void context)
{
  checkState(queryExplainer.isPresent(), "Query explainer must be provided for SHOW STATS SELECT");
  if (node.getRelation() instanceof TableSubquery) {
    Query query = ((TableSubquery) node.getRelation()).getQuery();
    QuerySpecification specification = (QuerySpecification) query.getQueryBody();
    Plan plan = queryExplainer.get().getLogicalPlan(session, new Query(Optional.empty(), specification, Optional.empty(), Optional.empty()), parameters, warningCollector);
    validateShowStatsSubquery(node, query, specification, plan);
    Table table = (Table) specification.getFrom().get();
    Constraint<ColumnHandle> constraint = getConstraint(plan);
    return rewriteShowStats(node, table, constraint);
  }
  else if (node.getRelation() instanceof Table) {
    Table table = (Table) node.getRelation();
    return rewriteShowStats(node, table, Constraint.alwaysTrue());
  }
  else {
    throw new IllegalArgumentException("Expected either TableSubquery or Table as relation");
  }
}

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

@Override
protected Void visitQuery(Query node, Integer indentLevel)
{
  print(indentLevel, "Query ");
  indentLevel++;
  print(indentLevel, "QueryBody");
  process(node.getQueryBody(), indentLevel);
  if (node.getOrderBy().isPresent()) {
    print(indentLevel, "OrderBy");
    process(node.getOrderBy().get(), indentLevel + 1);
  }
  if (node.getLimit().isPresent()) {
    print(indentLevel, "Limit: " + node.getLimit().get());
  }
  return null;
}

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

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

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

@Override
protected Scope visitQuery(Query node, Optional<Scope> scope)
{
  Scope withScope = analyzeWith(node, scope);
  Scope queryBodyScope = process(node.getQueryBody(), withScope);
  if (node.getOrderBy().isPresent()) {
    analyzeOrderBy(node, queryBodyScope);
  }
  else {
    analysis.setOrderByExpressions(node, emptyList());
  }
  // Input fields == Output fields
  analysis.setOutputExpressions(node, descriptorToFields(queryBodyScope));
  Scope queryScope = Scope.builder()
      .withParent(withScope)
      .withRelationType(RelationId.of(node), queryBodyScope.getRelationType())
      .build();
  analysis.setScope(node, queryScope);
  return queryScope;
}

代码示例来源: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

private PlanBuilder planQueryBody(Query query)
{
  RelationPlan relationPlan = new RelationPlanner(analysis, symbolAllocator, idAllocator, lambdaDeclarationToSymbolMap, metadata, session)
      .process(query.getQueryBody(), null);
  return planBuilderFor(relationPlan);
}

相关文章