Search in sources :

Example 1 with HandlerR2

use of io.confluent.ksql.util.HandlerMaps.HandlerR2 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());
    }
}
Also used : StreamPublisher(io.confluent.ksql.rest.client.StreamPublisher) VertxException(io.vertx.core.VertxException) DefineVariableContext(io.confluent.ksql.parser.SqlBaseParser.DefineVariableContext) WelcomeMsgUtils(io.confluent.ksql.util.WelcomeMsgUtils) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) KsqlParser(io.confluent.ksql.parser.KsqlParser) CliCommandRegisterUtil(io.confluent.ksql.cli.console.cmd.CliCommandRegisterUtil) RestResponse(io.confluent.ksql.rest.client.RestResponse) Context(io.vertx.core.Context) Map(java.util.Map) CreateConnectorContext(io.confluent.ksql.parser.SqlBaseParser.CreateConnectorContext) UndefineVariableContext(io.confluent.ksql.parser.SqlBaseParser.UndefineVariableContext) ParserUtil(io.confluent.ksql.util.ParserUtil) AppInfo(io.confluent.ksql.util.AppInfo) PrintWriter(java.io.PrintWriter) ListConnectorPluginsContext(io.confluent.ksql.parser.SqlBaseParser.ListConnectorPluginsContext) Console(io.confluent.ksql.cli.console.Console) CommandStatus(io.confluent.ksql.rest.entity.CommandStatus) Errors(io.confluent.ksql.rest.Errors) RemoteServerSpecificCommand(io.confluent.ksql.cli.console.cmd.RemoteServerSpecificCommand) StatusClosable(io.confluent.ksql.cli.console.KsqlTerminal.StatusClosable) ListConnectorsContext(io.confluent.ksql.parser.SqlBaseParser.ListConnectorsContext) Handler2(io.confluent.ksql.util.HandlerMaps.Handler2) ClassHandlerMap2(io.confluent.ksql.util.HandlerMaps.ClassHandlerMap2) KsqlConfig(io.confluent.ksql.util.KsqlConfig) UnsetPropertyContext(io.confluent.ksql.parser.SqlBaseParser.UnsetPropertyContext) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) ErrorMessageUtil(io.confluent.ksql.util.ErrorMessageUtil) Objects(java.util.Objects) BaseSubscriber(io.confluent.ksql.reactive.BaseSubscriber) List(java.util.List) KsqlRestClientException(io.confluent.ksql.rest.client.exception.KsqlRestClientException) KsqlVersion(io.confluent.ksql.util.KsqlVersion) EndOfFileException(org.jline.reader.EndOfFileException) Optional(java.util.Optional) VariableSubstitutor(io.confluent.ksql.parser.VariableSubstitutor) ClassHandlerMapR2(io.confluent.ksql.util.HandlerMaps.ClassHandlerMapR2) HandlerR2(io.confluent.ksql.util.HandlerMaps.HandlerR2) StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ListVariablesContext(io.confluent.ksql.parser.SqlBaseParser.ListVariablesContext) Supplier(java.util.function.Supplier) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) ServerInfo(io.confluent.ksql.rest.entity.ServerInfo) KsqlRestClient(io.confluent.ksql.rest.client.KsqlRestClient) VersionType(io.confluent.ksql.util.KsqlVersion.VersionType) DefaultKsqlParser(io.confluent.ksql.parser.DefaultKsqlParser) ParsedStatement(io.confluent.ksql.parser.KsqlParser.ParsedStatement) SetPropertyContext(io.confluent.ksql.parser.SqlBaseParser.SetPropertyContext) Terminal(org.jline.terminal.Terminal) VariablesList(io.confluent.ksql.rest.entity.VariablesList) OutputFormat(io.confluent.ksql.cli.console.OutputFormat) Logger(org.slf4j.Logger) Files(java.nio.file.Files) DropConnectorContext(io.confluent.ksql.parser.SqlBaseParser.DropConnectorContext) CommandStatusEntity(io.confluent.ksql.rest.entity.CommandStatusEntity) RequestPipeliningCommand(io.confluent.ksql.cli.console.cmd.RequestPipeliningCommand) QueryStatementContext(io.confluent.ksql.parser.SqlBaseParser.QueryStatementContext) StatementContext(io.confluent.ksql.parser.SqlBaseParser.StatementContext) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) PrintTopicContext(io.confluent.ksql.parser.SqlBaseParser.PrintTopicContext) TreeMap(java.util.TreeMap) KsqlUnsupportedServerException(io.confluent.ksql.rest.client.exception.KsqlUnsupportedServerException) Paths(java.nio.file.Paths) KsqlMissingCredentialsException(io.confluent.ksql.rest.client.exception.KsqlMissingCredentialsException) Closeable(java.io.Closeable) UserInterruptException(org.jline.reader.UserInterruptException) Subscription(org.reactivestreams.Subscription) HandlerMaps(io.confluent.ksql.util.HandlerMaps) DescribeConnectorContext(io.confluent.ksql.parser.SqlBaseParser.DescribeConnectorContext) Collections(java.util.Collections) SqlBaseParser(io.confluent.ksql.parser.SqlBaseParser) Optional(java.util.Optional) ParsedStatement(io.confluent.ksql.parser.KsqlParser.ParsedStatement) QueryStatementContext(io.confluent.ksql.parser.SqlBaseParser.QueryStatementContext) StatementContext(io.confluent.ksql.parser.SqlBaseParser.StatementContext)

Aggregations

Console (io.confluent.ksql.cli.console.Console)1 StatusClosable (io.confluent.ksql.cli.console.KsqlTerminal.StatusClosable)1 OutputFormat (io.confluent.ksql.cli.console.OutputFormat)1 CliCommandRegisterUtil (io.confluent.ksql.cli.console.cmd.CliCommandRegisterUtil)1 RemoteServerSpecificCommand (io.confluent.ksql.cli.console.cmd.RemoteServerSpecificCommand)1 RequestPipeliningCommand (io.confluent.ksql.cli.console.cmd.RequestPipeliningCommand)1 DefaultKsqlParser (io.confluent.ksql.parser.DefaultKsqlParser)1 KsqlParser (io.confluent.ksql.parser.KsqlParser)1 ParsedStatement (io.confluent.ksql.parser.KsqlParser.ParsedStatement)1 SqlBaseParser (io.confluent.ksql.parser.SqlBaseParser)1 CreateConnectorContext (io.confluent.ksql.parser.SqlBaseParser.CreateConnectorContext)1 DefineVariableContext (io.confluent.ksql.parser.SqlBaseParser.DefineVariableContext)1 DescribeConnectorContext (io.confluent.ksql.parser.SqlBaseParser.DescribeConnectorContext)1 DropConnectorContext (io.confluent.ksql.parser.SqlBaseParser.DropConnectorContext)1 ListConnectorPluginsContext (io.confluent.ksql.parser.SqlBaseParser.ListConnectorPluginsContext)1 ListConnectorsContext (io.confluent.ksql.parser.SqlBaseParser.ListConnectorsContext)1 ListVariablesContext (io.confluent.ksql.parser.SqlBaseParser.ListVariablesContext)1 PrintTopicContext (io.confluent.ksql.parser.SqlBaseParser.PrintTopicContext)1 QueryStatementContext (io.confluent.ksql.parser.SqlBaseParser.QueryStatementContext)1 SetPropertyContext (io.confluent.ksql.parser.SqlBaseParser.SetPropertyContext)1