com.facebook.presto.sql.QueryUtil.selectList()方法的使用及代码示例

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

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

QueryUtil.selectList介绍

暂无

代码示例

代码示例来源:origin: prestodb/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: prestodb/presto

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

代码示例来源:origin: prestodb/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: prestodb/presto

@Override
protected Node visitShowSchemas(ShowSchemas node, Void context)
{
  if (!node.getCatalog().isPresent() && !session.getCatalog().isPresent()) {
    throw new SemanticException(CATALOG_NOT_SPECIFIED, node, "Catalog must be specified when session catalog is not set");
  }
  String catalog = node.getCatalog().map(Identifier::getValue).orElseGet(() -> session.getCatalog().get());
  accessControl.checkCanShowSchemas(session.getRequiredTransactionId(), session.getIdentity(), catalog);
  Optional<Expression> predicate = Optional.empty();
  Optional<String> likePattern = node.getLikePattern();
  if (likePattern.isPresent()) {
    predicate = Optional.of(new LikePredicate(
        identifier("schema_name"),
        new StringLiteral(likePattern.get()),
        node.getEscape().map(StringLiteral::new)));
  }
  return simpleQuery(
      selectList(aliasedName("schema_name", "Schema")),
      from(catalog, TABLE_SCHEMATA),
      predicate,
      Optional.of(ordering(ascending("schema_name"))));
}

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

@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: prestodb/presto

@Override
protected Node visitDescribeInput(DescribeInput node, Void context)
    throws SemanticException
{
  String sqlString = session.getPreparedStatement(node.getName().getValue());
  Statement statement = parser.createStatement(sqlString, createParsingOptions(session));
  // create  analysis for the query we are describing.
  Analyzer analyzer = new Analyzer(session, metadata, parser, accessControl, queryExplainer, parameters, warningCollector);
  Analysis analysis = analyzer.analyze(statement, true);
  // get all parameters in query
  List<Parameter> parameters = getParameters(statement);
  // return the positions and types of all parameters
  Row[] rows = parameters.stream().map(parameter -> createDescribeInputRow(parameter, analysis)).toArray(Row[]::new);
  Optional<String> limit = Optional.empty();
  if (rows.length == 0) {
    rows = new Row[] {row(new NullLiteral(), new NullLiteral())};
    limit = Optional.of("0");
  }
  return simpleQuery(
      selectList(identifier("Position"), identifier("Type")),
      aliased(
          values(rows),
          "Parameter Input",
          ImmutableList.of("Position", "Type")),
      Optional.empty(),
      Optional.empty(),
      Optional.empty(),
      Optional.of(ordering(ascending("Position"))),
      limit);
}

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

@Test
public void testDoubleInQuery()
{
  assertStatement("SELECT 123.456E7 FROM DUAL",
      simpleQuery(
          selectList(new DoubleLiteral("123.456E7")),
          table(QualifiedName.of("DUAL"))));
}

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

@Test
public void testSelectStatement()
{
  PreparedQuery preparedQuery = QUERY_PREPARER.prepareQuery(TEST_SESSION, "SELECT * FROM foo");
  assertEquals(preparedQuery.getStatement(),
      simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("foo"))));
}

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

limit = Optional.of("0");
return simpleQuery(
    selectList(
        identifier("Column Name"),
        identifier("Catalog"),

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

@Test
public void testExplainAnalyze()
{
  assertStatement("EXPLAIN ANALYZE SELECT * FROM t",
      new Explain(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), true, false, ImmutableList.of()));
}

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

@Test
public void testExplainAnalyzeVerbose()
{
  assertStatement("EXPLAIN ANALYZE VERBOSE SELECT * FROM t",
      new Explain(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), true, true, ImmutableList.of()));
}

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

@Test
public void testPrepareNameExists()
{
  Session session = testSessionBuilder()
      .addPreparedStatement("my_query", "SELECT bar, baz from foo")
      .build();
  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, session);
  assertEquals(statements, ImmutableMap.of("my_query", "SELECT *\nFROM\n  foo\n"));
}

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

@Test
public void testExplainVerbose()
{
  assertStatement("EXPLAIN VERBOSE SELECT * FROM t",
      new Explain(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), false, true, ImmutableList.of()));
}

代码示例来源:origin: prestodb/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: prestodb/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: prestodb/presto

@Test
public void testExecuteStatement()
{
  Session session = testSessionBuilder()
      .addPreparedStatement("my_query", "SELECT * FROM foo")
      .build();
  PreparedQuery preparedQuery = QUERY_PREPARER.prepareQuery(session, "EXECUTE my_query");
  assertEquals(preparedQuery.getStatement(),
      simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("foo"))));
}

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

@Test
public void testExists()
{
  assertStatement("SELECT EXISTS(SELECT 1)", simpleQuery(selectList(exists(simpleQuery(selectList(new LongLiteral("1")))))));
  assertStatement(
      "SELECT EXISTS(SELECT 1) = EXISTS(SELECT 2)",
      simpleQuery(
          selectList(new ComparisonExpression(
              ComparisonExpression.Operator.EQUAL,
              exists(simpleQuery(selectList(new LongLiteral("1")))),
              exists(simpleQuery(selectList(new LongLiteral("2"))))))));
  assertStatement(
      "SELECT NOT EXISTS(SELECT 1) = EXISTS(SELECT 2)",
      simpleQuery(
          selectList(
              new NotExpression(
                  new ComparisonExpression(
                      ComparisonExpression.Operator.EQUAL,
                      exists(simpleQuery(selectList(new LongLiteral("1")))),
                      exists(simpleQuery(selectList(new LongLiteral("2")))))))));
  assertStatement(
      "SELECT (NOT EXISTS(SELECT 1)) = EXISTS(SELECT 2)",
      simpleQuery(
          selectList(
              new ComparisonExpression(
                  ComparisonExpression.Operator.EQUAL,
                  new NotExpression(exists(simpleQuery(selectList(new LongLiteral("1"))))),
                  exists(simpleQuery(selectList(new LongLiteral("2"))))))));
}

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

@Test
public void testExplainVerboseTypeLogical()
{
  assertStatement("EXPLAIN VERBOSE (type LOGICAL) SELECT * FROM t",
      new Explain(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), false, true, ImmutableList.of(new ExplainType(ExplainType.Type.LOGICAL))));
}

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

@Test
public void testExplainAnalyzeTypeDistributed()
{
  assertStatement("EXPLAIN ANALYZE (type DISTRIBUTED) SELECT * FROM t",
      new Explain(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), true, false, ImmutableList.of(new ExplainType(ExplainType.Type.DISTRIBUTED))));
}

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

@Test
public void testExplainAnalyzeVerboseTypeDistributed()
{
  assertStatement("EXPLAIN ANALYZE VERBOSE (type DISTRIBUTED) SELECT * FROM t",
      new Explain(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), true, true, ImmutableList.of(new ExplainType(ExplainType.Type.DISTRIBUTED))));
}

相关文章