use of io.confluent.ksql.KsqlExecutionContext.ExecuteResult in project ksql by confluentinc.
the class KsqlEngineTest method shouldNotThrowWhenExecutingDuplicateStreamWithIfNotExists.
@Test
public void shouldNotThrowWhenExecutingDuplicateStreamWithIfNotExists() {
// Given:
final List<ParsedStatement> parsed = ksqlEngine.parse("CREATE STREAM FOO WITH (KAFKA_TOPIC='BAR') AS SELECT * FROM ORDERS; " + "CREATE STREAM IF NOT EXISTS FOO WITH (KAFKA_TOPIC='BAR') AS SELECT * FROM ORDERS;");
givenStatementAlreadyExecuted(parsed.get(0));
final PreparedStatement<?> prepared = prepare(parsed.get(1));
// When:
ExecuteResult executeResult = ksqlEngine.execute(serviceContext, ConfiguredStatement.of(prepared, SessionConfig.of(ksqlConfig, new HashMap<>())));
// Then:
assertThat(executeResult.getQuery(), is(Optional.empty()));
assertThat(executeResult.getCommandResult(), is(Optional.of("Cannot add stream `FOO`: A stream with the same name already exists.")));
}
use of io.confluent.ksql.KsqlExecutionContext.ExecuteResult in project ksql by confluentinc.
the class KsqlEngineTest method shouldNotThrowWhenExecutingDuplicateTableWithCreateOrReplaceOnSandbox.
@Test
public void shouldNotThrowWhenExecutingDuplicateTableWithCreateOrReplaceOnSandbox() {
// Given:
final ConfiguredStatement<?> oldQuery = configuredStatement("CREATE TABLE FOO AS SELECT * FROM TEST2;");
final ConfiguredStatement<?> newQuery = configuredStatement("CREATE OR REPLACE TABLE FOO AS SELECT * FROM TEST2;");
final QueryId oldQueryId = ksqlEngine.execute(serviceContext, oldQuery).getQuery().get().getQueryId();
sandbox = ksqlEngine.createSandbox(serviceContext);
// When:
ExecuteResult executeResult = sandbox.execute(sandboxServiceContext, newQuery);
// Then:
assertThat(executeResult.getQuery().get().getQueryId(), is(oldQueryId));
}
use of io.confluent.ksql.KsqlExecutionContext.ExecuteResult in project ksql by confluentinc.
the class KsqlEngineTest method shouldHandleMultipleStatements.
@SuppressWarnings("unchecked")
@Test
public void shouldHandleMultipleStatements() {
// Given:
final String sql = "" + "-- single line comment\n" + "/*\n" + " Multi-line comment\n" + "*/\n" + "CREATE STREAM S0 (a INT, b VARCHAR) " + " WITH (kafka_topic='s0_topic', value_format='DELIMITED', key_format='KAFKA');\n" + "\n" + "CREATE TABLE T1 (f0 BIGINT PRIMARY KEY, f1 DOUBLE) " + " WITH (kafka_topic='t1_topic', value_format='JSON', key_format='KAFKA');\n" + "\n" + "CREATE STREAM S1 AS SELECT * FROM S0;\n" + "\n" + "CREATE STREAM S2 AS SELECT * FROM S0;\n" + "\n" + "DROP TABLE T1;";
givenTopicsExist("s0_topic", "t1_topic");
final List<QueryMetadata> queries = new ArrayList<>();
// When:
final List<PreparedStatement<?>> preparedStatements = ksqlEngine.parse(sql).stream().map(stmt -> {
final PreparedStatement<?> prepared = ksqlEngine.prepare(stmt);
final ExecuteResult result = ksqlEngine.execute(serviceContext, ConfiguredStatement.of(prepared, SessionConfig.of(ksqlConfig, new HashMap<>())));
result.getQuery().ifPresent(queries::add);
return prepared;
}).collect(Collectors.toList());
// Then:
final List<?> statements = preparedStatements.stream().map(PreparedStatement::getStatement).collect(Collectors.toList());
assertThat(statements, contains(instanceOf(CreateStream.class), instanceOf(CreateTable.class), instanceOf(CreateStreamAsSelect.class), instanceOf(CreateStreamAsSelect.class), instanceOf(DropTable.class)));
assertThat(queries, hasSize(2));
}
use of io.confluent.ksql.KsqlExecutionContext.ExecuteResult in project ksql by confluentinc.
the class KsqlEngineTest method shouldNotThrowWhenExecutingDuplicateTableWithCreateOrReplace.
@Test
public void shouldNotThrowWhenExecutingDuplicateTableWithCreateOrReplace() {
// Given:
final ConfiguredStatement<?> oldQuery = configuredStatement("CREATE TABLE FOO AS SELECT * FROM TEST2;");
final ConfiguredStatement<?> newQuery = configuredStatement("CREATE OR REPLACE TABLE FOO AS SELECT * FROM TEST2;");
final QueryId oldQueryId = ksqlEngine.execute(serviceContext, oldQuery).getQuery().get().getQueryId();
// When:
ExecuteResult executeResult = ksqlEngine.execute(sandboxServiceContext, newQuery);
// Then:
assertThat(executeResult.getQuery().get().getQueryId(), is(oldQueryId));
}
use of io.confluent.ksql.KsqlExecutionContext.ExecuteResult in project ksql by confluentinc.
the class KsqlEngineTest method shouldExecuteInsertIntoStreamOnSandBox.
@Test
public void shouldExecuteInsertIntoStreamOnSandBox() {
// Given:
final List<ParsedStatement> statements = parse("create stream bar as select * from orders;" + "insert into bar select * from orders;");
givenStatementAlreadyExecuted(statements.get(0));
// When:
final ExecuteResult result = sandbox.execute(sandboxServiceContext, ConfiguredStatement.of(sandbox.prepare(statements.get(1)), SessionConfig.of(ksqlConfig, Collections.emptyMap())));
// Then:
assertThat(result.getQuery(), is(not(Optional.empty())));
}
Aggregations