use of io.confluent.ksql.parser.KsqlParser.ParsedStatement in project ksql by confluentinc.
the class KsqlEngineTest method shouldThrowIfStatementMissingTopicConfig.
@Test
public void shouldThrowIfStatementMissingTopicConfig() {
final List<ParsedStatement> parsed = parse("CREATE TABLE FOO (viewtime BIGINT, pageid VARCHAR) WITH (VALUE_FORMAT='AVRO', KEY_FORMAT='KAFKA');" + "CREATE STREAM FOO (viewtime BIGINT, pageid VARCHAR) WITH (VALUE_FORMAT='AVRO', KEY_FORMAT='KAFKA');" + "CREATE TABLE FOO (viewtime BIGINT, pageid VARCHAR) WITH (VALUE_FORMAT='JSON', KEY_FORMAT='KAFKA');" + "CREATE STREAM FOO (viewtime BIGINT, pageid VARCHAR) WITH (VALUE_FORMAT='JSON', KEY_FORMAT='KAFKA');");
for (final ParsedStatement statement : parsed) {
try {
ksqlEngine.prepare(statement);
Assert.fail();
} catch (final KsqlStatementException e) {
assertThat(e.getMessage(), containsString("Missing required property \"KAFKA_TOPIC\" which has no default value."));
}
}
}
use of io.confluent.ksql.parser.KsqlParser.ParsedStatement in project ksql by confluentinc.
the class KsqlEngineTest method shouldNotThrowWhenExecutingDuplicateTableWithIfNotExists.
@Test
public void shouldNotThrowWhenExecutingDuplicateTableWithIfNotExists() {
// Given:
final List<ParsedStatement> parsed = ksqlEngine.parse("CREATE TABLE FOO WITH (KAFKA_TOPIC='BAR') AS SELECT * FROM TEST2; " + "CREATE TABLE IF NOT EXISTS FOO WITH (KAFKA_TOPIC='BAR') AS SELECT * FROM TEST2;");
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 table `FOO`: A table with the same name already exists.")));
}
use of io.confluent.ksql.parser.KsqlParser.ParsedStatement in project ksql by confluentinc.
the class KsqlEngineTest method shouldNotThrowWhenPreparingDuplicateStream.
@Test
public void shouldNotThrowWhenPreparingDuplicateStream() {
// Given:
final ParsedStatement stmt = ksqlEngine.parse("CREATE STREAM FOO AS SELECT * FROM ORDERS; " + "CREATE STREAM FOO WITH (KAFKA_TOPIC='BAR') AS SELECT * FROM ORDERS;").get(0);
// When:
ksqlEngine.prepare(stmt);
// Then: No exception thrown.
}
use of io.confluent.ksql.parser.KsqlParser.ParsedStatement in project ksql by confluentinc.
the class KsqlEngineTest method shouldThrowOnPrepareIfSourcesDoNotExist.
@Test
public void shouldThrowOnPrepareIfSourcesDoNotExist() {
// Given:
final ParsedStatement parsed = ksqlEngine.parse("CREATE STREAM FOO AS SELECT * FROM I_DO_NOT_EXIST;").get(0);
// When:
final Exception e = assertThrows(KsqlException.class, () -> ksqlEngine.prepare(parsed));
// Then:
assertThat(e.getMessage(), containsString("I_DO_NOT_EXIST does not exist"));
}
use of io.confluent.ksql.parser.KsqlParser.ParsedStatement in project ksql by confluentinc.
the class KsqlEngineTest method shouldThrowWhenExecutingDuplicateStream.
@Test
public void shouldThrowWhenExecutingDuplicateStream() {
// Given:
final List<ParsedStatement> parsed = ksqlEngine.parse("CREATE STREAM FOO WITH (KAFKA_TOPIC='BAR') AS SELECT * FROM ORDERS; " + "CREATE STREAM FOO WITH (KAFKA_TOPIC='BAR') AS SELECT * FROM ORDERS;");
givenStatementAlreadyExecuted(parsed.get(0));
final PreparedStatement<?> prepared = ksqlEngine.prepare(parsed.get(1));
// When:
final KsqlStatementException e = assertThrows(KsqlStatementException.class, () -> ksqlEngine.execute(serviceContext, ConfiguredStatement.of(prepared, SessionConfig.of(ksqlConfig, new HashMap<>()))));
// Then:
assertThat(e, rawMessage(is("Cannot add stream 'FOO': A stream with the same name already exists")));
assertThat(e, statementText(is("CREATE STREAM FOO WITH (KAFKA_TOPIC='BAR') AS SELECT * FROM ORDERS;")));
}
Aggregations