use of io.confluent.ksql.parser.KsqlParser.PreparedStatement in project ksql by confluentinc.
the class KsqlParserTest method shouldParseMultiLineWithInlineBracketedComments.
@Test
public void shouldParseMultiLineWithInlineBracketedComments() {
final String statementString = "SHOW /* inline\n" + "comment */\n" + "STREAMS;";
final List<PreparedStatement<?>> statements = KsqlParserTestUtil.buildAst(statementString, metaStore);
assertThat(statements, hasSize(1));
assertThat(statements.get(0).getStatement(), is(instanceOf(ListStreams.class)));
}
use of io.confluent.ksql.parser.KsqlParser.PreparedStatement in project ksql by confluentinc.
the class KsqlResourceTest method shouldSupportTopicInferenceInVerification.
@Test
public void shouldSupportTopicInferenceInVerification() {
// Given:
givenMockEngine();
givenSource(DataSourceType.KSTREAM, "ORDERS1", "ORDERS1", SOME_SCHEMA);
final String sql = "CREATE STREAM orders2 AS SELECT * FROM orders1;";
final String sqlWithTopic = "CREATE STREAM orders2 WITH(kafka_topic='orders2') AS SELECT * FROM orders1;";
final PreparedStatement<?> statementWithTopic = ksqlEngine.prepare(ksqlEngine.parse(sqlWithTopic).get(0), Collections.emptyMap());
final ConfiguredStatement<?> configuredStatement = ConfiguredStatement.of(statementWithTopic, SessionConfig.of(ksqlConfig, ImmutableMap.of()));
when(sandboxTopicInjector.inject(argThat(is(configured(preparedStatementText(sql)))))).thenReturn((ConfiguredStatement<Statement>) configuredStatement);
// When:
makeRequest(sql);
// Then:
verify(sandbox).plan(any(SandboxedServiceContext.class), eq(configuredStatement));
verify(commandStore).enqueueCommand(any(), argThat(is(commandWithStatement(sql))), any(Producer.class));
}
use of io.confluent.ksql.parser.KsqlParser.PreparedStatement in project ksql by confluentinc.
the class KsqlResourceTest method shouldSupportTopicInferenceInExecution.
@Test
public void shouldSupportTopicInferenceInExecution() {
// Given:
givenMockEngine();
givenSource(DataSourceType.KSTREAM, "ORDERS1", "ORDERS1", SOME_SCHEMA);
final String sql = "CREATE STREAM orders2 AS SELECT * FROM orders1;";
final String sqlWithTopic = "CREATE STREAM orders2 WITH(kafka_topic='orders2') AS SELECT * FROM orders1;";
final PreparedStatement<?> statementWithTopic = ksqlEngine.prepare(ksqlEngine.parse(sqlWithTopic).get(0), Collections.emptyMap());
final ConfiguredStatement<?> configured = ConfiguredStatement.of(statementWithTopic, SessionConfig.of(ksqlConfig, ImmutableMap.of()));
when(topicInjector.inject(argThat(is(configured(preparedStatementText(sql)))))).thenReturn((ConfiguredStatement<Statement>) configured);
// When:
makeRequest(sql);
// Then:
verify(commandStore).enqueueCommand(any(), argThat(is(commandWithStatement(sqlWithTopic))), any());
}
use of io.confluent.ksql.parser.KsqlParser.PreparedStatement in project ksql by confluentinc.
the class RequestHandler method executeStatement.
@SuppressWarnings("unchecked")
private <T extends Statement> Optional<KsqlEntity> executeStatement(final KsqlSecurityContext securityContext, final PreparedStatement<T> prepared, final SessionProperties sessionProperties, final KsqlEntityList entities) {
final Class<? extends Statement> statementClass = prepared.getStatement().getClass();
commandQueueSync.waitFor(new KsqlEntityList(entities), statementClass);
final ConfiguredStatement<T> configured = ConfiguredStatement.of(prepared, SessionConfig.of(this.ksqlEngine.getKsqlConfig(), sessionProperties.getMutableScopedProperties()));
FeatureFlagChecker.throwOnDisabledFeatures(configured);
final StatementExecutor<T> executor = (StatementExecutor<T>) customExecutors.getOrDefault(statementClass, (stmt, props, ctx, svcCtx) -> distributor.execute(stmt, ctx, securityContext));
final StatementExecutorResponse response = executor.execute(configured, sessionProperties, ksqlEngine, securityContext.getServiceContext());
if (response.isHandled()) {
return response.getEntity();
} else {
return distributor.execute(configured, ksqlEngine, securityContext).getEntity();
}
}
use of io.confluent.ksql.parser.KsqlParser.PreparedStatement in project ksql by confluentinc.
the class InteractiveStatementExecutor method executeStatement.
@SuppressWarnings("unchecked")
private void executeStatement(final PreparedStatement<?> statement, final CommandId commandId, final Optional<CommandStatusFuture> commandStatusFuture) {
if (statement.getStatement() instanceof TerminateQuery) {
terminateQuery((PreparedStatement<TerminateQuery>) statement);
final String successMessage = "Query terminated.";
final CommandStatus successStatus = new CommandStatus(CommandStatus.Status.SUCCESS, successMessage, Optional.empty());
putFinalStatus(commandId, commandStatusFuture, successStatus);
} else if (statement.getStatement() instanceof ExecutableDdlStatement) {
throwUnsupportedStatementError();
} else if (statement.getStatement() instanceof CreateAsSelect) {
throwUnsupportedStatementError();
} else if (statement.getStatement() instanceof InsertInto) {
throwUnsupportedStatementError();
} else if (statement.getStatement() instanceof AlterSystemProperty) {
final PreparedStatement<AlterSystemProperty> alterSystemQuery = (PreparedStatement<AlterSystemProperty>) statement;
final String propertyName = alterSystemQuery.getStatement().getPropertyName();
final String propertyValue = alterSystemQuery.getStatement().getPropertyValue();
ksqlEngine.alterSystemProperty(propertyName, propertyValue);
ksqlEngine.updateStreamsPropertiesAndRestartRuntime();
final String successMessage = String.format("System property %s was set to %s.", propertyName, propertyValue);
final CommandStatus successStatus = new CommandStatus(CommandStatus.Status.SUCCESS, successMessage, Optional.empty());
putFinalStatus(commandId, commandStatusFuture, successStatus);
} else {
throw new KsqlException(String.format("Unexpected statement type: %s", statement.getClass().getName()));
}
}
Aggregations