public static String formatSql(Node root, Function<QualifiedName, String> tableNameMapper, Function<String, String> columnNameMapper, char escapeIdentifier) { StringBuilder builder = new StringBuilder(); new Formatter(builder, tableNameMapper, columnNameMapper, escapeIdentifier).process(root, 0); return builder.toString(); }
public static String formatQuery(Statement query, Function<QualifiedName, String> tableNameMapper, char escapeIdentifier) { StringBuilder builder = new StringBuilder(); new RakamSqlFormatter.Formatter(builder, tableNameMapper, escapeIdentifier).process(query, 1); return builder.toString(); }
public static String formatSql(Node root, Function<QualifiedName, String> tableNameMapper, char escapeIdentifier) { StringBuilder builder = new StringBuilder(); new Formatter(builder, tableNameMapper, null, escapeIdentifier).process(root, 0); return builder.toString(); }
new RakamSqlFormatter.Formatter(builder, name -> queryExecutor.formatTableReference(context.project, name, Optional.empty(), sessionProperties), '"').process(statement, 1);
Query statement = (Query) SqlUtil.parseSql(materializedView.query); new RakamSqlFormatter.Formatter(builder, name -> queryExecutor .formatTableReference(context.project, name, Optional.empty(), new HashMap<String, String>() { @Override
new RakamSqlFormatter.Formatter(builder, qualifiedName -> { String prefix = qualifiedName.getPrefix().get().getPrefix().get().toString(); if (!prefix.equals("external")) {
} else if ((queryStatement instanceof Call)) { StringBuilder builder = new StringBuilder(); new RakamSqlFormatter.Formatter(builder, tableNameMapper, escapeIdentifier) .process(queryStatement, 1); return builder.toString(); new RakamSqlFormatter.Formatter(builder, tableNameMapper, escapeIdentifier) .process(statement, 1);
public CompletableFuture<List<SchemaField>> metadata(RequestContext context, String query) { StringBuilder builder = new StringBuilder(); Query queryStatement; try { queryStatement = (Query) SqlUtil.parseSql(checkNotNull(query, "query is required")); } catch (Exception e) { throw new RakamException("Unable to parse query: " + e.getMessage(), BAD_REQUEST); } Map<String, String> map = new HashMap<>(); new RakamSqlFormatter.Formatter(builder, qualifiedName -> executor.formatTableReference(context.project, qualifiedName, Optional.empty(), map), escapeIdentifier) .process(queryStatement, 1); QueryExecution execution = executor .executeRawQuery(context, builder.toString() + " limit 0", map); CompletableFuture<List<SchemaField>> f = new CompletableFuture<>(); execution.getResult().thenAccept(result -> { if (result.isFailed()) { f.completeExceptionally(new RakamException(result.getError().message, HttpResponseStatus.INTERNAL_SERVER_ERROR)); } else { f.complete(result.getMetadata()); } }); return f; } }
@Override public CompletableFuture<Void> create(RequestContext context, MaterializedView materializedView) { Query statement = (Query) sqlParser.createStatement(materializedView.query, new ParsingOptions()); StringBuilder builder = new StringBuilder(); HashMap<String, String> map = new HashMap<>(); new RakamSqlFormatter.Formatter(builder, qualifiedName -> queryExecutor.formatTableReference(context.project, qualifiedName, Optional.empty(), map), '"') .process(statement, 1); QueryExecution execution = queryExecutor .executeRawStatement(context, format("create table %s as %s limit 0", queryExecutor.formatTableReference(context.project, QualifiedName.of("materialized", materializedView.tableName), Optional.empty(), ImmutableMap.of()), builder.toString(), Optional.empty()), map); return execution.getResult().thenAccept(result -> { try { get(context.project, materializedView.tableName); throw new AlreadyExistsException("Materialized view", BAD_REQUEST); } catch (NotExistsException e) { } if (result.isFailed()) { throw new RakamException(result.getError().message, INTERNAL_SERVER_ERROR); } else { database.createMaterializedView(context.project, materializedView); } }); }
protected CompletableFuture<List<SchemaField>> metadata(RequestContext context, String query) { StringBuilder builder = new StringBuilder(); Query queryStatement = (Query) SqlUtil.parseSql(query); CompletableFuture<List<SchemaField>> f = new CompletableFuture<>(); try { new RakamSqlFormatter.Formatter(builder, qualifiedName -> queryExecutor.formatTableReference(context.project, qualifiedName, Optional.empty(), ImmutableMap.of()), escapeIdentifier) .process(queryStatement, 1); } catch (Exception e) { f.completeExceptionally(e); } QueryExecution execution = queryExecutor.executeRawQuery(context, builder.toString() + " limit 0", ZoneOffset.UTC, ImmutableMap.of()); execution.getResult().thenAccept(result -> { if (result.isFailed()) { f.completeExceptionally(new RakamException(result.getError().message, INTERNAL_SERVER_ERROR)); } else { f.complete(result.getMetadata()); } }); return f; }
static String formatSql(Node root, Function<QualifiedName, String> tableNameMapper, Function<String, String> columnNameMapper, List<String> ctes, char escapeIdentifier) { StringBuilder builder = new StringBuilder(); new Formatter(builder, tableNameMapper, columnNameMapper, ctes, escapeIdentifier).process(root, 0); return builder.toString(); }