use of io.confluent.ksql.util.KsqlStatementException in project ksql by confluentinc.
the class KsqlEngineTest method shouldThrowWhenTryExecuteCsasThatCreatesTable.
@Test
public void shouldThrowWhenTryExecuteCsasThatCreatesTable() {
// Given:
final PreparedStatement<?> statement = prepare(parse("CREATE STREAM FOO AS SELECT ORDERID, COUNT(ORDERID) FROM ORDERS GROUP BY ORDERID;").get(0));
// When:
final KsqlStatementException e = assertThrows(KsqlStatementException.class, () -> sandbox.execute(serviceContext, ConfiguredStatement.of(statement, SessionConfig.of(ksqlConfig, new HashMap<>()))));
// Then:
assertThat(e, rawMessage(containsString("Invalid result type. Your SELECT query produces a TABLE. " + "Please use CREATE TABLE AS SELECT statement instead.")));
assertThat(e, statementText(is("CREATE STREAM FOO AS SELECT ORDERID, COUNT(ORDERID) FROM ORDERS GROUP BY ORDERID;")));
}
use of io.confluent.ksql.util.KsqlStatementException in project ksql by confluentinc.
the class KsqlEngineTest method shouldThrowWhenExecutingQueriesIfCtasCreatesStream.
@Test
public void shouldThrowWhenExecutingQueriesIfCtasCreatesStream() {
// When:
final KsqlStatementException e = assertThrows(KsqlStatementException.class, () -> KsqlEngineTestUtil.execute(serviceContext, ksqlEngine, "CREATE TABLE FOO AS SELECT * FROM ORDERS;", ksqlConfig, Collections.emptyMap()));
// Then:
assertThat(e, rawMessage(containsString("Invalid result type. Your SELECT query produces a STREAM. " + "Please use CREATE STREAM AS SELECT statement instead.")));
assertThat(e, statementText(is("CREATE TABLE FOO AS SELECT * FROM ORDERS;")));
}
use of io.confluent.ksql.util.KsqlStatementException in project ksql by confluentinc.
the class KsqlEngineTest method shouldThrowWhenInsertIntoSchemaDoesNotMatch.
@Test
public void shouldThrowWhenInsertIntoSchemaDoesNotMatch() {
// Given:
execute(serviceContext, ksqlEngine, "create stream bar as select * from orders;", ksqlConfig, emptyMap());
// When:
final KsqlStatementException e = assertThrows(KsqlStatementException.class, () -> execute(serviceContext, ksqlEngine, "insert into bar select orderTime, itemid from orders;", ksqlConfig, emptyMap()));
// Then:
assertThat(e, rawMessage(containsString("Incompatible schema between results and sink.")));
assertThat(e, statementText(is("insert into bar select orderTime, itemid from orders;")));
}
use of io.confluent.ksql.util.KsqlStatementException in project ksql by confluentinc.
the class KsqlEngineTest method shouldThrowOnNoneExecutableDdlStatement.
@Test
public void shouldThrowOnNoneExecutableDdlStatement() {
// When:
final KsqlStatementException e = assertThrows(KsqlStatementException.class, () -> KsqlEngineTestUtil.execute(serviceContext, ksqlEngine, "SHOW STREAMS;", ksqlConfig, Collections.emptyMap()));
// Then:
assertThat(e, rawMessage(is("Statement not executable")));
assertThat(e, statementText(is("SHOW STREAMS;")));
}
use of io.confluent.ksql.util.KsqlStatementException in project ksql by confluentinc.
the class KsqlEngineTestUtil method executeQuery.
public static TransientQueryMetadata executeQuery(final ServiceContext serviceContext, final KsqlEngine engine, final String sql, final KsqlConfig ksqlConfig, final Map<String, Object> overriddenProperties) {
final ParsedStatement stmt = engine.parse(sql).get(0);
final PreparedStatement<?> prepared = engine.prepare(stmt);
final ConfiguredStatement<Query> configured = ConfiguredStatement.of(prepared, SessionConfig.of(ksqlConfig, overriddenProperties)).cast();
try {
return engine.executeTransientQuery(serviceContext, configured, false);
} catch (final KsqlStatementException e) {
// can easily check that the failed statement is the input statement
throw new KsqlStatementException(e.getRawMessage(), stmt.getStatementText(), e.getCause());
}
}
Aggregations