Search in sources :

Example 6 with ParsedStatement

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

Example 7 with ParsedStatement

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

Example 8 with ParsedStatement

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

Example 9 with ParsedStatement

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"));
}
Also used : ParsedStatement(io.confluent.ksql.parser.KsqlParser.ParsedStatement) RestClientException(io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException) ParseFailedException(io.confluent.ksql.parser.exception.ParseFailedException) KsqlException(io.confluent.ksql.util.KsqlException) IOException(java.io.IOException) ConfigException(org.apache.kafka.common.config.ConfigException) KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) Test(org.junit.Test)

Example 10 with ParsedStatement

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

Aggregations

ParsedStatement (io.confluent.ksql.parser.KsqlParser.ParsedStatement)37 Test (org.junit.Test)22 KsqlStatementException (io.confluent.ksql.util.KsqlStatementException)15 KsqlException (io.confluent.ksql.util.KsqlException)10 CreateStream (io.confluent.ksql.parser.tree.CreateStream)7 ExecuteResult (io.confluent.ksql.KsqlExecutionContext.ExecuteResult)6 KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)6 Optional (java.util.Optional)6 DefaultKsqlParser (io.confluent.ksql.parser.DefaultKsqlParser)5 PreparedStatement (io.confluent.ksql.parser.KsqlParser.PreparedStatement)5 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)5 Injector (io.confluent.ksql.statement.Injector)5 KsqlConfig (io.confluent.ksql.util.KsqlConfig)5 QueryMetadata (io.confluent.ksql.util.QueryMetadata)5 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 KsqlExecutionContext (io.confluent.ksql.KsqlExecutionContext)4 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)4 ServiceContext (io.confluent.ksql.services.ServiceContext)4 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)4