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

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

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

QueryUtil介绍

暂无

代码示例

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

@Override
protected Node visitShowCatalogs(ShowCatalogs node, Void context)
{
  List<Expression> rows = listCatalogs(session, metadata, accessControl).keySet().stream()
      .map(name -> row(new StringLiteral(name)))
      .collect(toList());
  Optional<Expression> predicate = Optional.empty();
  Optional<String> likePattern = node.getLikePattern();
  if (likePattern.isPresent()) {
    predicate = Optional.of(new LikePredicate(identifier("Catalog"), new StringLiteral(likePattern.get()), Optional.empty()));
  }
  return simpleQuery(
      selectList(new AllColumns()),
      aliased(new Values(rows), "catalogs", ImmutableList.of("Catalog")),
      predicate,
      Optional.of(ordering(ascending("Catalog"))));
}

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

public static Query singleValueQuery(String columnName, boolean value)
{
  Relation values = values(row(value ? TRUE_LITERAL : FALSE_LITERAL));
  return simpleQuery(
      selectList(new AllColumns()),
      aliased(values, "t", ImmutableList.of(columnName)));
}

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

public static Query simpleQuery(Select select, Relation from, Optional<Expression> where, Optional<GroupBy> groupBy, Optional<Expression> having, Optional<OrderBy> orderBy, Optional<String> limit)
{
  return query(new QuerySpecification(
      select,
      Optional.of(from),
      where,
      groupBy,
      having,
      orderBy,
      limit));
}

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

@Override
protected Node visitShowColumns(ShowColumns showColumns, Void context)
{
  QualifiedObjectName tableName = createQualifiedObjectName(session, showColumns, showColumns.getTable());
  if (!metadata.getView(session, tableName).isPresent() &&
      !metadata.getTableHandle(session, tableName).isPresent()) {
    throw new SemanticException(MISSING_TABLE, showColumns, "Table '%s' does not exist", tableName);
  }
  return simpleQuery(
      selectList(
          aliasedName("column_name", "Column"),
          aliasedName("data_type", "Type"),
          aliasedNullToEmpty("extra_info", "Extra"),
          aliasedNullToEmpty("comment", "Comment")),
      from(tableName.getCatalogName(), TABLE_COLUMNS),
      logicalAnd(
          equal(identifier("table_schema"), new StringLiteral(tableName.getSchemaName())),
          equal(identifier("table_name"), new StringLiteral(tableName.getObjectName()))),
      ordering(ascending("ordinal_position")));
}

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

@Test
public void testPrepare()
{
  Query query = simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("foo")));
  String sqlString = "PREPARE my_query FROM SELECT * FROM foo";
  Map<String, String> statements = executePrepare("my_query", query, sqlString, TEST_SESSION);
  assertEquals(statements, ImmutableMap.of("my_query", "SELECT *\nFROM\n  foo\n"));
}

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

@Test
public void testQuantifiedComparison()
{
  assertExpression("col1 < ANY (SELECT col2 FROM table1)",
      new QuantifiedComparisonExpression(
          LESS_THAN,
          QuantifiedComparisonExpression.Quantifier.ANY,
          identifier("col1"),
          new SubqueryExpression(simpleQuery(selectList(new SingleColumn(identifier("col2"))), table(QualifiedName.of("table1"))))));
  assertExpression("col1 = ALL (VALUES ROW(1), ROW(2))",
      new QuantifiedComparisonExpression(
          ComparisonExpression.Operator.EQUAL,
          QuantifiedComparisonExpression.Quantifier.ALL,
          identifier("col1"),
          new SubqueryExpression(query(values(row(new LongLiteral("1")), row(new LongLiteral("2")))))));
  assertExpression("col1 >= SOME (SELECT 10)",
      new QuantifiedComparisonExpression(
          ComparisonExpression.Operator.GREATER_THAN_OR_EQUAL,
          QuantifiedComparisonExpression.Quantifier.SOME,
          identifier("col1"),
          new SubqueryExpression(simpleQuery(selectList(new LongLiteral("10"))))));
}

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

@Test
public void testInsertInto()
{
  QualifiedName table = QualifiedName.of("a");
  Query query = simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t")));
  assertStatement("INSERT INTO a SELECT * FROM t",
      new Insert(table, Optional.empty(), query));
  assertStatement("INSERT INTO a (c1, c2) SELECT * FROM t",
      new Insert(table, Optional.of(ImmutableList.of(identifier("c1"), identifier("c2"))), query));
}

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

rows.add(row(
      new StringLiteral(sessionProperty.getFullyQualifiedName()),
      new StringLiteral(nullToEmpty(value)),
rows.add(row(new StringLiteral(""), new StringLiteral(""), new StringLiteral(""), new StringLiteral(""), new StringLiteral(""), FALSE_LITERAL));
return simpleQuery(
    selectList(
        aliasedName("name", "Name"),
        aliasedName("value", "Value"),
        aliasedName("default", "Default"),
        aliasedName("type", "Type"),
        aliasedName("description", "Description")),
    aliased(
        new Values(rows.build()),
        "session",
        ImmutableList.of("name", "value", "default", "type", "description", "include")),
    identifier("include"));

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

rows.add(row(
      new StringLiteral(function.getSignature().getName()),
      new StringLiteral(function.getSignature().getReturnType().toString()),
    .build();
return simpleQuery(
    selectAll(columns.entrySet().stream()
        .map(entry -> aliasedName(entry.getKey(), entry.getValue()))
        .collect(toImmutableList())),
    aliased(new Values(rows.build()), "functions", ImmutableList.copyOf(columns.keySet())),
    ordering(
        new SortItem(
            functionCall("lower", identifier("function_name")),
            SortItem.Ordering.ASCENDING,
            SortItem.NullOrdering.UNDEFINED),
        ascending("return_type"),
        ascending("argument_types"),
        ascending("function_type")));

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

public static SelectItem aliasedName(String name, String alias)
{
  return new SingleColumn(identifier(name), identifier(alias));
}

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

@Test
public void testLimitAll()
{
  Query valuesQuery = query(values(
      row(new LongLiteral("1"), new StringLiteral("1")),
      row(new LongLiteral("2"), new StringLiteral("2"))));
  assertStatement("SELECT * FROM (VALUES (1, '1'), (2, '2')) LIMIT ALL",
      simpleQuery(selectList(new AllColumns()),
          subquery(valuesQuery),
          Optional.empty(),
          Optional.empty(),
          Optional.empty(),
          Optional.empty(),
          Optional.of("ALL")));
}

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

Optional.empty(),
        Optional.empty(),
        Optional.of(new OrderBy(ImmutableList.of(new SortItem(identifier("x"), DESCENDING, UNDEFINED)))),
        false,
        ImmutableList.of(identifier("x"))));
assertStatement("SELECT array_agg(x ORDER BY t.y) FROM t",
    new Query(
        Optional.empty(),
        new QuerySpecification(
            selectList(
                new FunctionCall(
                    QualifiedName.of("array_agg"),
                    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")))),
            Optional.of(table(QualifiedName.of("t"))),
            Optional.empty(),
            Optional.empty(),

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

public static Query simpleQuery(Select select, Relation from, Expression where, OrderBy orderBy)
{
  return simpleQuery(select, from, Optional.of(where), Optional.of(orderBy));
}

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

@Test
public void testImplicitJoin()
{
  assertStatement("SELECT * FROM a, b",
      simpleQuery(selectList(new AllColumns()),
          new Join(Join.Type.IMPLICIT,
              new Table(QualifiedName.of("a")),
              new Table(QualifiedName.of("b")),
              Optional.empty())));
}

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

private Node rewriteShowStats(ShowStats node, Table table, Constraint<ColumnHandle> constraint)
{
  TableHandle tableHandle = getTableHandle(node, table.getName());
  TableStatistics tableStatistics = metadata.getTableStatistics(session, tableHandle, constraint);
  List<String> statsColumnNames = buildColumnsNames();
  List<SelectItem> selectItems = buildSelectItems(statsColumnNames);
  TableMetadata tableMetadata = metadata.getTableMetadata(session, tableHandle);
  Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(session, tableHandle);
  List<Expression> resultRows = buildStatisticsRows(tableMetadata, columnHandles, tableStatistics);
  return simpleQuery(selectAll(selectItems),
      aliased(new Values(resultRows),
          "table_stats_for_" + table.getName(),
          statsColumnNames));
}

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

new WithQuery(identifier("t"),
    query(new Values(ImmutableList.of(new LongLiteral("1")))),
    Optional.of(ImmutableList.of(identifier("x"))))))),
new Table(QualifiedName.of("t")),
Optional.empty(),

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

@Test
public void testDropColumn()
{
  assertStatement("ALTER TABLE foo.t DROP COLUMN c", new DropColumn(QualifiedName.of("foo", "t"), identifier("c")));
  assertStatement("ALTER TABLE \"t x\" DROP COLUMN \"c d\"", new DropColumn(QualifiedName.of("t x"), quotedIdentifier("c d")));
}

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

public static Select selectList(Expression... expressions)
{
  return selectList(asList(expressions));
}

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

private static Row createDescribeInputRow(Parameter parameter, Analysis queryAnalysis)
{
  Type type = queryAnalysis.getCoercion(parameter);
  if (type == null) {
    type = UNKNOWN;
  }
  return row(
      new LongLiteral(Integer.toString(parameter.getPosition())),
      new StringLiteral(type.getTypeSignature().getBase()));
}

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

private static Relation from(String catalog, SchemaTableName table)
{
  return table(QualifiedName.of(catalog, table.getSchemaName(), table.getTableName()));
}

相关文章