Search in sources :

Example 16 with KsqlStatementException

use of io.confluent.ksql.util.KsqlStatementException in project ksql by confluentinc.

the class KsqlEngineTest method shouldThrowFromExecuteIfSourceTopicDoesNotExist.

@Test
public void shouldThrowFromExecuteIfSourceTopicDoesNotExist() {
    // Given:
    final PreparedStatement<?> statement = prepare(parse("CREATE STREAM S1 (COL1 BIGINT) " + "WITH (KAFKA_TOPIC = 'i_do_not_exist', VALUE_FORMAT = 'JSON', KEY_FORMAT = 'KAFKA');").get(0));
    // When:
    final KsqlStatementException e = assertThrows(KsqlStatementException.class, () -> ksqlEngine.execute(serviceContext, ConfiguredStatement.of(statement, SessionConfig.of(ksqlConfig, ImmutableMap.of()))));
    // Then:
    assertThat(e, rawMessage(is("Kafka topic does not exist: i_do_not_exist")));
}
Also used : KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) Test(org.junit.Test)

Example 17 with KsqlStatementException

use of io.confluent.ksql.util.KsqlStatementException in project ksql by confluentinc.

the class KsqlEngineTest method shouldThrowFromSandBoxOnPrepareIfSourceTopicDoesNotExist.

@Test
public void shouldThrowFromSandBoxOnPrepareIfSourceTopicDoesNotExist() {
    // Given:
    final PreparedStatement<?> statement = prepare(parse("CREATE STREAM S1 (COL1 BIGINT) " + "WITH (KAFKA_TOPIC = 'i_do_not_exist', VALUE_FORMAT = 'JSON', KEY_FORMAT = 'KAFKA');").get(0));
    // When:
    final KsqlStatementException e = assertThrows(KsqlStatementException.class, () -> sandbox.execute(sandboxServiceContext, ConfiguredStatement.of(statement, SessionConfig.of(ksqlConfig, ImmutableMap.of()))));
    // Then:
    assertThat(e, rawMessage(is("Kafka topic does not exist: i_do_not_exist")));
    assertThat(e, statementText(is("CREATE STREAM S1 (COL1 BIGINT)" + " WITH (KAFKA_TOPIC = 'i_do_not_exist', VALUE_FORMAT = 'JSON', KEY_FORMAT = 'KAFKA');")));
}
Also used : KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) Test(org.junit.Test)

Example 18 with KsqlStatementException

use of io.confluent.ksql.util.KsqlStatementException 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;")));
}
Also used : HashMap(java.util.HashMap) ParsedStatement(io.confluent.ksql.parser.KsqlParser.ParsedStatement) KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) Test(org.junit.Test)

Example 19 with KsqlStatementException

use of io.confluent.ksql.util.KsqlStatementException in project ksql by confluentinc.

the class KsqlEngineTest method shouldThrowOnTerminateAsNotExecutable.

@Test
public void shouldThrowOnTerminateAsNotExecutable() {
    // Given:
    final PersistentQueryMetadata query = (PersistentQueryMetadata) KsqlEngineTestUtil.execute(serviceContext, ksqlEngine, "create table bar as select * from test2;", ksqlConfig, Collections.emptyMap()).get(0);
    // When:
    final KsqlStatementException e = assertThrows(KsqlStatementException.class, () -> KsqlEngineTestUtil.execute(serviceContext, ksqlEngine, "TERMINATE " + query.getQueryId() + ";", ksqlConfig, Collections.emptyMap()));
    // Then:
    assertThat(e, rawMessage(containsString("Statement not executable")));
    assertThat(e, statementText(is("TERMINATE CTAS_BAR_0;")));
}
Also used : KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) Test(org.junit.Test)

Example 20 with KsqlStatementException

use of io.confluent.ksql.util.KsqlStatementException in project ksql by confluentinc.

the class KsqlEngineTest method shouldThrowWhenExecutingInsertIntoTable.

@Test
public void shouldThrowWhenExecutingInsertIntoTable() {
    KsqlEngineTestUtil.execute(serviceContext, ksqlEngine, "create table bar as select * from test2;", ksqlConfig, Collections.emptyMap());
    final ParsedStatement parsed = ksqlEngine.parse("insert into bar select * from test2;").get(0);
    // When:
    final KsqlStatementException e = assertThrows(KsqlStatementException.class, () -> prepare(parsed));
    // Then:
    assertThat(e, rawMessage(containsString("INSERT INTO can only be used to insert into a stream. BAR is a table.")));
    assertThat(e, statementText(is("insert into bar select * from test2;")));
}
Also used : ParsedStatement(io.confluent.ksql.parser.KsqlParser.ParsedStatement) KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) Test(org.junit.Test)

Aggregations

KsqlStatementException (io.confluent.ksql.util.KsqlStatementException)54 Test (org.junit.Test)28 KsqlException (io.confluent.ksql.util.KsqlException)14 Query (io.confluent.ksql.parser.tree.Query)11 ParsedStatement (io.confluent.ksql.parser.KsqlParser.ParsedStatement)10 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)7 KsqlConfig (io.confluent.ksql.util.KsqlConfig)6 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)6 SessionConfig (io.confluent.ksql.config.SessionConfig)5 Statement (io.confluent.ksql.parser.tree.Statement)5 ServiceContext (io.confluent.ksql.services.ServiceContext)5 HashMap (java.util.HashMap)5 DataSource (io.confluent.ksql.metastore.model.DataSource)4 PreparedStatement (io.confluent.ksql.parser.KsqlParser.PreparedStatement)4 QueryId (io.confluent.ksql.query.QueryId)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ExecuteResult (io.confluent.ksql.KsqlExecutionContext.ExecuteResult)3 ImmutableAnalysis (io.confluent.ksql.analyzer.ImmutableAnalysis)3 DdlCommand (io.confluent.ksql.execution.ddl.commands.DdlCommand)3 CreateAsSelect (io.confluent.ksql.parser.tree.CreateAsSelect)3