Tabnine Logo
QueryUtil.row
Code IndexAdd Tabnine to your IDE (free)

How to use
row
method
in
io.prestosql.sql.QueryUtil

Best Java code snippets using io.prestosql.sql.QueryUtil.row (Showing top 20 results out of 315)

origin: io.prestosql/presto-main

@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

@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: io.prestosql/presto-parser

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: 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 singleValueQuery(String columnName, String value)
{
  Relation values = values(row(new StringLiteral((value))));
  return simpleQuery(
      selectList(new AllColumns()),
      aliased(values, "t", ImmutableList.of(columnName)));
}
origin: io.prestosql/presto-main

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

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: 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: io.prestosql/presto-main

@Override
protected Node visitShowRoleGrants(ShowRoleGrants 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(c -> c.getValue().toLowerCase(ENGLISH)).orElseGet(() -> session.getCatalog().get());
  PrestoPrincipal principal = new PrestoPrincipal(PrincipalType.USER, session.getUser());
  accessControl.checkCanShowRoleGrants(session.getRequiredTransactionId(), session.getIdentity(), catalog);
  List<Expression> rows = metadata.listRoleGrants(session, catalog, principal).stream()
      .map(roleGrant -> row(new StringLiteral(roleGrant.getRoleName())))
      .collect(toList());
  return simpleQuery(
      selectList(new AllColumns()),
      aliased(new Values(rows), "role_grants", ImmutableList.of("Role Grants")),
      ordering(ascending("Role Grants")));
}
origin: prestosql/presto

@Override
protected Node visitShowRoleGrants(ShowRoleGrants 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(c -> c.getValue().toLowerCase(ENGLISH)).orElseGet(() -> session.getCatalog().get());
  PrestoPrincipal principal = new PrestoPrincipal(PrincipalType.USER, session.getUser());
  accessControl.checkCanShowRoleGrants(session.getRequiredTransactionId(), session.getIdentity(), catalog);
  List<Expression> rows = metadata.listRoleGrants(session, catalog, principal).stream()
      .map(roleGrant -> row(new StringLiteral(roleGrant.getRoleName())))
      .collect(toList());
  return simpleQuery(
      selectList(new AllColumns()),
      aliased(new Values(rows), "role_grants", ImmutableList.of("Role Grants")),
      ordering(ascending("Role Grants")));
}
origin: io.prestosql/presto-main

private static Row createDescribeOutputRow(Field field, Analysis analysis)
{
  LongLiteral typeSize = new LongLiteral("0");
  if (field.getType() instanceof FixedWidthType) {
    typeSize = new LongLiteral(String.valueOf(((FixedWidthType) field.getType()).getFixedSize()));
  }
  String columnName;
  if (field.getName().isPresent()) {
    columnName = field.getName().get();
  }
  else {
    int columnIndex = ImmutableList.copyOf(analysis.getOutputDescriptor().getVisibleFields()).indexOf(field);
    columnName = "_col" + columnIndex;
  }
  Optional<QualifiedObjectName> originTable = field.getOriginTable();
  return row(
      new StringLiteral(columnName),
      new StringLiteral(originTable.map(QualifiedObjectName::getCatalogName).orElse("")),
      new StringLiteral(originTable.map(QualifiedObjectName::getSchemaName).orElse("")),
      new StringLiteral(originTable.map(QualifiedObjectName::getObjectName).orElse("")),
      new StringLiteral(field.getType().getDisplayName()),
      typeSize,
      new BooleanLiteral(String.valueOf(field.isAliased())));
}
origin: prestosql/presto

private static Row createDescribeOutputRow(Field field, Analysis analysis)
{
  LongLiteral typeSize = new LongLiteral("0");
  if (field.getType() instanceof FixedWidthType) {
    typeSize = new LongLiteral(String.valueOf(((FixedWidthType) field.getType()).getFixedSize()));
  }
  String columnName;
  if (field.getName().isPresent()) {
    columnName = field.getName().get();
  }
  else {
    int columnIndex = ImmutableList.copyOf(analysis.getOutputDescriptor().getVisibleFields()).indexOf(field);
    columnName = "_col" + columnIndex;
  }
  Optional<QualifiedObjectName> originTable = field.getOriginTable();
  return row(
      new StringLiteral(columnName),
      new StringLiteral(originTable.map(QualifiedObjectName::getCatalogName).orElse("")),
      new StringLiteral(originTable.map(QualifiedObjectName::getSchemaName).orElse("")),
      new StringLiteral(originTable.map(QualifiedObjectName::getObjectName).orElse("")),
      new StringLiteral(field.getType().getDisplayName()),
      typeSize,
      new BooleanLiteral(String.valueOf(field.isAliased())));
}
origin: io.prestosql/presto-main

@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: prestosql/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: 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: io.prestosql/presto-main

if (rows.length == 0) {
  NullLiteral nullLiteral = new NullLiteral();
  rows = new Row[] {row(nullLiteral, nullLiteral, nullLiteral, nullLiteral, nullLiteral, nullLiteral, nullLiteral)};
  limit = Optional.of("0");
origin: prestosql/presto

if (rows.length == 0) {
  NullLiteral nullLiteral = new NullLiteral();
  rows = new Row[] {row(nullLiteral, nullLiteral, nullLiteral, nullLiteral, nullLiteral, nullLiteral, nullLiteral)};
  limit = Optional.of("0");
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));
origin: prestosql/presto

@Test
public void testValues()
{
  Query valuesQuery = query(values(
      row(new StringLiteral("a"), new LongLiteral("1"), new DoubleLiteral("2.2")),
      row(new StringLiteral("b"), new LongLiteral("2"), new DoubleLiteral("3.3"))));
  assertStatement("VALUES ('a', 1, 2.2e0), ('b', 2, 3.3e0)", valuesQuery);
  assertStatement("SELECT * FROM (VALUES ('a', 1, 2.2e0), ('b', 2, 3.3e0))",
      simpleQuery(
          selectList(new AllColumns()),
          subquery(valuesQuery)));
}
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"))))));
}
io.prestosql.sqlQueryUtilrow

Popular methods of QueryUtil

  • identifier
  • selectList
  • simpleQuery
  • table
  • values
  • aliased
  • query
  • aliasedName
  • aliasedNullToEmpty
  • ascending
  • equal
  • functionCall
  • equal,
  • functionCall,
  • logicalAnd,
  • ordering,
  • quotedIdentifier,
  • selectAll,
  • singleValueQuery,
  • subquery

Popular in Java

  • Reading from database using SQL prepared statement
  • onRequestPermissionsResult (Fragment)
  • getApplicationContext (Context)
  • scheduleAtFixedRate (Timer)
  • GridBagLayout (java.awt)
    The GridBagLayout class is a flexible layout manager that aligns components vertically and horizonta
  • SocketTimeoutException (java.net)
    This exception is thrown when a timeout expired on a socket read or accept operation.
  • MessageFormat (java.text)
    Produces concatenated messages in language-neutral way. New code should probably use java.util.Forma
  • Iterator (java.util)
    An iterator over a sequence of objects, such as a collection.If a collection has been changed since
  • ResourceBundle (java.util)
    ResourceBundle is an abstract class which is the superclass of classes which provide Locale-specifi
  • JOptionPane (javax.swing)
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now