Search in sources :

Example 41 with KsqlStatementException

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

Example 42 with KsqlStatementException

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

Example 43 with KsqlStatementException

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

Example 44 with KsqlStatementException

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

Example 45 with KsqlStatementException

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

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