Search in sources :

Example 11 with KsqlStatementException

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

the class KsqlEngineTest method shouldFailDropStreamWhenAnInsertQueryIsReadingTheStream.

@Test
public void shouldFailDropStreamWhenAnInsertQueryIsReadingTheStream() {
    // Given:
    KsqlEngineTestUtil.execute(serviceContext, ksqlEngine, "create stream bar as select * from test1;" + "create stream foo as select * from test1;" + "insert into foo select * from bar;", ksqlConfig, Collections.emptyMap());
    // When:
    final KsqlStatementException e = assertThrows(KsqlStatementException.class, () -> KsqlEngineTestUtil.execute(serviceContext, ksqlEngine, "drop stream bar;", ksqlConfig, Collections.emptyMap()));
    // Then:
    assertThat(e, rawMessage(is("Cannot drop BAR.\n" + "The following queries read from this source: [INSERTQUERY_2].\n" + "The following queries write into this source: [].\n" + "You need to terminate them before dropping BAR.")));
    assertThat(e, statementText(is("drop stream bar;")));
}
Also used : KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) Test(org.junit.Test)

Example 12 with KsqlStatementException

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

Example 13 with KsqlStatementException

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

the class KsqlEngineTest method shouldFailDropStreamWhenMultipleStreamsAreReadingTheTable.

@Test
public void shouldFailDropStreamWhenMultipleStreamsAreReadingTheTable() {
    // Given:
    KsqlEngineTestUtil.execute(serviceContext, ksqlEngine, "create stream bar as select * from test1;" + "create stream foo as select * from bar;" + "create stream foo2 as select * from bar;", ksqlConfig, Collections.emptyMap());
    // When:
    final KsqlStatementException e = assertThrows(KsqlStatementException.class, () -> KsqlEngineTestUtil.execute(serviceContext, ksqlEngine, "drop stream bar;", ksqlConfig, Collections.emptyMap()));
    // Then:
    assertThat(e, rawMessage(is("Cannot drop BAR.\n" + "The following streams and/or tables read from this source: [FOO, FOO2].\n" + "You need to drop them before dropping BAR.")));
    assertThat(e, statementText(is("drop stream bar;")));
}
Also used : KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) Test(org.junit.Test)

Example 14 with KsqlStatementException

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

the class KsqlEngineTest method shouldThrowIfSchemaNotPresent.

@Test
public void shouldThrowIfSchemaNotPresent() {
    // Given:
    givenTopicsExist("bar");
    // When:
    final KsqlStatementException e = assertThrows(KsqlStatementException.class, () -> execute(serviceContext, ksqlEngine, "create stream bar with (key_format='kafka', value_format='avro', kafka_topic='bar');", ksqlConfig, emptyMap()));
    // Then:
    assertThat(e, rawMessage(containsString("The statement does not define any columns.")));
    assertThat(e, statementText(is("create stream bar with (key_format='kafka', value_format='avro', kafka_topic='bar');")));
}
Also used : KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) Test(org.junit.Test)

Example 15 with KsqlStatementException

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

the class KsqlEngineTest method shouldThrowOnInsertIntoWithKeyMismatch.

@Test
public void shouldThrowOnInsertIntoWithKeyMismatch() {
    execute(serviceContext, ksqlEngine, "create stream bar as select * from orders;", ksqlConfig, emptyMap());
    // When:
    final KsqlStatementException e = assertThrows(KsqlStatementException.class, () -> KsqlEngineTestUtil.execute(serviceContext, ksqlEngine, "insert into bar select * from orders partition by orderid;", ksqlConfig, Collections.emptyMap()));
    // Then:
    assertThat(e, rawMessage(containsString("Incompatible schema between results and sink.")));
    assertThat(e, rawMessage(containsString("Result schema is `ORDERID` BIGINT KEY, ")));
    assertThat(e, rawMessage(containsString("Sink schema is `ORDERTIME` BIGINT KEY, ")));
    assertThat(e, statementText(is("insert into bar select * from orders partition by orderid;")));
}
Also used : 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