Search in sources :

Example 6 with ErrorMessageEntity

use of io.confluent.ksql.rest.entity.ErrorMessageEntity in project ksql by confluentinc.

the class KsqlResourceTest method shouldFailForIncorrectDropTableStatement.

@Test
public void shouldFailForIncorrectDropTableStatement() throws Exception {
    KsqlResource testResource = TestKsqlResourceUtil.get(ksqlEngine, ksqlRestConfig);
    final String ksqlString = "DROP STREAM test_table;";
    Response response = testResource.handleKsqlStatements(new KsqlRequest(ksqlString, Collections.emptyMap()));
    KsqlEntityList result = (KsqlEntityList) response.getEntity();
    assertThat("Incorrect drop statement.", result.size(), equalTo(1));
    assertThat(result.get(0), instanceOf(ErrorMessageEntity.class));
    ErrorMessageEntity errorMessageEntity = (ErrorMessageEntity) result.get(0);
    assertTrue(errorMessageEntity.getErrorMessage().getMessage().equalsIgnoreCase("Incompatible data source type" + " is TABLE, but statement was DROP STREAM"));
}
Also used : Response(javax.ws.rs.core.Response) KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) KsqlRequest(io.confluent.ksql.rest.entity.KsqlRequest) ErrorMessageEntity(io.confluent.ksql.rest.entity.ErrorMessageEntity) Test(org.junit.Test)

Example 7 with ErrorMessageEntity

use of io.confluent.ksql.rest.entity.ErrorMessageEntity in project ksql by confluentinc.

the class ConsoleTest method testPrintKSqlEntityList.

@Test
public void testPrintKSqlEntityList() throws IOException {
    Map<String, Object> properties = new HashMap<>();
    properties.put("k1", 1);
    properties.put("k2", "v2");
    properties.put("k3", true);
    List<Queries.RunningQuery> queries = new ArrayList<>();
    queries.add(new Queries.RunningQuery("select * from t1", "TestTopic", new QueryId("0")));
    for (int i = 0; i < 5; i++) {
        KsqlEntityList entityList = new KsqlEntityList(Arrays.asList(new CommandStatusEntity("e", "topic/1/create", "SUCCESS", "Success Message"), new ErrorMessageEntity("e", new FakeException()), new PropertiesList("e", properties), new Queries("e", queries), new SourceDescription("e", "TestSource", Collections.EMPTY_LIST, Collections.EMPTY_LIST, buildTestSchema(i), DataSource.DataSourceType.KTABLE.getKqlType(), "key", "2000-01-01", "stats", "errors", false, "avro", "kadka-topic", "topology", "executionPlan", 1, 1), new TopicDescription("e", "TestTopic", "TestKafkaTopic", "AVRO", "schemaString"), new StreamsList("e", Arrays.asList(new SourceInfo.Stream("TestStream", "TestTopic", "AVRO"))), new TablesList("e", Arrays.asList(new SourceInfo.Table("TestTable", "TestTopic", "JSON", false))), new KsqlTopicsList("e", Arrays.asList(new KsqlTopicInfo("TestTopic", "TestKafkaTopic", DataSource.DataSourceSerDe.JSON))), new KafkaTopicsList("e", Arrays.asList(new KafkaTopicInfo("TestKafkaTopic", true, ImmutableList.of(1), 1, 1))), new ExecutionPlan("Test Execution Plan")));
        terminal.printKsqlEntityList(entityList);
    }
}
Also used : KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) Queries(io.confluent.ksql.rest.entity.Queries) HashMap(java.util.HashMap) KafkaTopicsList(io.confluent.ksql.rest.entity.KafkaTopicsList) ArrayList(java.util.ArrayList) CommandStatusEntity(io.confluent.ksql.rest.entity.CommandStatusEntity) ExecutionPlan(io.confluent.ksql.rest.entity.ExecutionPlan) StreamsList(io.confluent.ksql.rest.entity.StreamsList) QueryId(io.confluent.ksql.query.QueryId) KsqlTopicInfo(io.confluent.ksql.rest.entity.KsqlTopicInfo) ErrorMessageEntity(io.confluent.ksql.rest.entity.ErrorMessageEntity) PropertiesList(io.confluent.ksql.rest.entity.PropertiesList) TablesList(io.confluent.ksql.rest.entity.TablesList) FakeException(io.confluent.ksql.FakeException) KafkaTopicInfo(io.confluent.ksql.rest.entity.KafkaTopicInfo) TopicDescription(io.confluent.ksql.rest.entity.TopicDescription) KsqlTopicsList(io.confluent.ksql.rest.entity.KsqlTopicsList) SourceDescription(io.confluent.ksql.rest.entity.SourceDescription) Test(org.junit.Test)

Example 8 with ErrorMessageEntity

use of io.confluent.ksql.rest.entity.ErrorMessageEntity in project ksql by confluentinc.

the class KsqlResourceTest method shouldFailForIncorrectCTASStatementResultType.

@Test
public void shouldFailForIncorrectCTASStatementResultType() throws Exception {
    KsqlResource testResource = TestKsqlResourceUtil.get(ksqlEngine, ksqlRestConfig);
    final String ksqlString = "CREATE TABLE s1 AS SELECT * FROM test_stream;";
    Response response = testResource.handleKsqlStatements(new KsqlRequest(ksqlString, Collections.emptyMap()));
    KsqlEntityList result = (KsqlEntityList) response.getEntity();
    assertThat("Incorrect response size.", result.size(), equalTo(1));
    assertThat(result.get(0), instanceOf(ErrorMessageEntity.class));
    ErrorMessageEntity errorMessageEntity = (ErrorMessageEntity) result.get(0);
    assertTrue(errorMessageEntity.getErrorMessage().getMessage().contains("Invalid result type. Your " + "SELECT query produces a STREAM. Please use CREATE STREAM AS SELECT statement instead."));
}
Also used : Response(javax.ws.rs.core.Response) KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) KsqlRequest(io.confluent.ksql.rest.entity.KsqlRequest) ErrorMessageEntity(io.confluent.ksql.rest.entity.ErrorMessageEntity) Test(org.junit.Test)

Aggregations

ErrorMessageEntity (io.confluent.ksql.rest.entity.ErrorMessageEntity)8 KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)8 Test (org.junit.Test)5 KsqlRequest (io.confluent.ksql.rest.entity.KsqlRequest)4 Response (javax.ws.rs.core.Response)4 CommandStatusEntity (io.confluent.ksql.rest.entity.CommandStatusEntity)3 ExecutionPlan (io.confluent.ksql.rest.entity.ExecutionPlan)2 KafkaTopicInfo (io.confluent.ksql.rest.entity.KafkaTopicInfo)2 KafkaTopicsList (io.confluent.ksql.rest.entity.KafkaTopicsList)2 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)2 KsqlTopicInfo (io.confluent.ksql.rest.entity.KsqlTopicInfo)2 KsqlTopicsList (io.confluent.ksql.rest.entity.KsqlTopicsList)2 PropertiesList (io.confluent.ksql.rest.entity.PropertiesList)2 Queries (io.confluent.ksql.rest.entity.Queries)2 SourceDescription (io.confluent.ksql.rest.entity.SourceDescription)2 StreamsList (io.confluent.ksql.rest.entity.StreamsList)2 TablesList (io.confluent.ksql.rest.entity.TablesList)2 TopicDescription (io.confluent.ksql.rest.entity.TopicDescription)2 ArrayList (java.util.ArrayList)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1