Search in sources :

Example 6 with KsqlRequest

use of io.confluent.ksql.rest.entity.KsqlRequest 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 KsqlRequest

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

the class KsqlRestClient method makeKsqlRequest.

public RestResponse<KsqlEntityList> makeKsqlRequest(String ksql) {
    KsqlRequest jsonRequest = new KsqlRequest(ksql, localProperties);
    Response response = makePostRequest("ksql", jsonRequest);
    KsqlEntityList result = response.readEntity(KsqlEntityList.class);
    response.close();
    return RestResponse.successful(result);
}
Also used : Response(javax.ws.rs.core.Response) KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) KsqlRequest(io.confluent.ksql.rest.entity.KsqlRequest)

Example 8 with KsqlRequest

use of io.confluent.ksql.rest.entity.KsqlRequest 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)

Example 9 with KsqlRequest

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

the class KsqlResourceTest method shouldFailCreateTableWithInferenceWithIncorrectKey.

@Test
public void shouldFailCreateTableWithInferenceWithIncorrectKey() throws Exception {
    KsqlResource testResource = TestKsqlResourceUtil.get(ksqlEngine, ksqlRestConfig);
    final String ksqlString = "CREATE TABLE orders WITH (KAFKA_TOPIC='orders-topic', " + "VALUE_FORMAT = 'avro', KEY = 'orderid1');";
    Response response = testResource.handleKsqlStatements(new KsqlRequest(ksqlString, new HashMap<>()));
    KsqlEntityList result = (KsqlEntityList) response.getEntity();
    assertThat("Incorrect response.", result.size(), equalTo(1));
    assertThat(result.get(0), instanceOf(ErrorMessageEntity.class));
}
Also used : Response(javax.ws.rs.core.Response) KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) KsqlRequest(io.confluent.ksql.rest.entity.KsqlRequest) HashMap(java.util.HashMap) ErrorMessageEntity(io.confluent.ksql.rest.entity.ErrorMessageEntity) Test(org.junit.Test)

Example 10 with KsqlRequest

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

the class KsqlResourceTest method shouldCreateTableWithInference.

@Test
public void shouldCreateTableWithInference() throws Exception {
    KsqlResource testResource = TestKsqlResourceUtil.get(ksqlEngine, ksqlRestConfig);
    final String ksqlString = "CREATE TABLE orders WITH (KAFKA_TOPIC='orders-topic', " + "VALUE_FORMAT = 'avro', KEY = 'orderid');";
    Response response = testResource.handleKsqlStatements(new KsqlRequest(ksqlString, new HashMap<>()));
    KsqlEntityList result = (KsqlEntityList) response.getEntity();
    assertThat("Incorrect response.", result.size(), equalTo(1));
    assertTrue(result.get(0) instanceof CommandStatusEntity);
    CommandStatusEntity commandStatusEntity = (CommandStatusEntity) result.get(0);
    assertTrue(commandStatusEntity.getCommandId().getType().name().equalsIgnoreCase("TABLE"));
}
Also used : Response(javax.ws.rs.core.Response) KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) KsqlRequest(io.confluent.ksql.rest.entity.KsqlRequest) HashMap(java.util.HashMap) CommandStatusEntity(io.confluent.ksql.rest.entity.CommandStatusEntity) Test(org.junit.Test)

Aggregations

KsqlRequest (io.confluent.ksql.rest.entity.KsqlRequest)11 Response (javax.ws.rs.core.Response)10 KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)8 Test (org.junit.Test)7 ErrorMessageEntity (io.confluent.ksql.rest.entity.ErrorMessageEntity)5 HashMap (java.util.HashMap)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 GenericRow (io.confluent.ksql.GenericRow)1 KsqlEngine (io.confluent.ksql.KsqlEngine)1 Query (io.confluent.ksql.parser.tree.Query)1 OutputNode (io.confluent.ksql.planner.plan.OutputNode)1 CommandStatusEntity (io.confluent.ksql.rest.entity.CommandStatusEntity)1 ErrorMessage (io.confluent.ksql.rest.entity.ErrorMessage)1 KsqlTopicsList (io.confluent.ksql.rest.entity.KsqlTopicsList)1 StreamedRow (io.confluent.ksql.rest.entity.StreamedRow)1 StreamsList (io.confluent.ksql.rest.entity.StreamsList)1 TablesList (io.confluent.ksql.rest.entity.TablesList)1 StatementParser (io.confluent.ksql.rest.server.StatementParser)1 StreamedQueryResource (io.confluent.ksql.rest.server.resources.streaming.StreamedQueryResource)1 DataSource (io.confluent.ksql.serde.DataSource)1