use of io.confluent.ksql.util.HandlerMaps.Handler2 in project ksql by confluentinc.
the class Cli method handleStatements.
private void handleStatements(final String line) {
final List<ParsedStatement> statements = KSQL_PARSER.parse(line);
// validate all before executing any
sandboxedSessionVariables = new HashMap<>(sessionVariables);
statements.stream().map(stmt -> this.substituteVariables(stmt, true)).forEach(parsed -> {
final StatementContext statementContext = parsed.getStatement().statement();
final HandlerR2<StatementContext, Cli, Void, Optional> validator = STATEMENT_VALIDATORS.get(statementContext.getClass());
if (validator != null) {
final Optional<?> validationError = validator.handle(this, null, statementContext);
validationError.map(o -> (RuntimeException) o).ifPresent(error -> {
throw error;
});
}
});
// execute statements
final StringBuilder consecutiveStatements = new StringBuilder();
statements.stream().map(stmt -> this.substituteVariables(stmt, false)).forEach(parsed -> {
final StatementContext statementContext = parsed.getStatement().statement();
final String statementText = parsed.getStatementText();
final Handler2<StatementContext, Cli, String> handler = STATEMENT_HANDLERS.get(statementContext.getClass());
if (handler == null) {
consecutiveStatements.append(statementText);
} else {
makeKsqlRequest(consecutiveStatements.toString());
consecutiveStatements.setLength(0);
handler.handle(this, statementText, statementContext);
}
});
if (consecutiveStatements.length() != 0) {
makeKsqlRequest(consecutiveStatements.toString());
}
}
Aggregations