Search in sources :

Example 1 with KsqlRequest

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

the class KsqlRestClient method makePrintTopicRequest.

public RestResponse<InputStream> makePrintTopicRequest(String ksql) {
    RestResponse<InputStream> result;
    KsqlRequest jsonRequest = new KsqlRequest(ksql, localProperties);
    Response response = makePostRequest("query", jsonRequest);
    if (response.getStatus() == Response.Status.OK.getStatusCode()) {
        result = RestResponse.successful((InputStream) response.getEntity());
    } else {
        result = RestResponse.erroneous(response.readEntity(ErrorMessage.class));
    }
    return result;
}
Also used : Response(javax.ws.rs.core.Response) KsqlRequest(io.confluent.ksql.rest.entity.KsqlRequest) InputStream(java.io.InputStream)

Example 2 with KsqlRequest

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

the class KsqlRestClient method makeQueryRequest.

public RestResponse<QueryStream> makeQueryRequest(String ksql) {
    KsqlRequest jsonRequest = new KsqlRequest(ksql, localProperties);
    Response response = makePostRequest("query", jsonRequest);
    if (response.getStatus() == Response.Status.OK.getStatusCode()) {
        return RestResponse.successful(new QueryStream(response));
    } else {
        return RestResponse.erroneous(response.readEntity(ErrorMessage.class));
    }
}
Also used : Response(javax.ws.rs.core.Response) KsqlRequest(io.confluent.ksql.rest.entity.KsqlRequest) ErrorMessage(io.confluent.ksql.rest.entity.ErrorMessage)

Example 3 with KsqlRequest

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

the class KsqlResourceTest method shouldFailForIncorrectCSASStatementResultType.

@Test
public void shouldFailForIncorrectCSASStatementResultType() throws Exception {
    KsqlResource testResource = TestKsqlResourceUtil.get(ksqlEngine, ksqlRestConfig);
    String ksqlString1 = "CREATE STREAM s1 AS SELECT * FROM test_table;";
    Response response1 = testResource.handleKsqlStatements(new KsqlRequest(ksqlString1, Collections.emptyMap()));
    KsqlEntityList result1 = (KsqlEntityList) response1.getEntity();
    assertTrue("Incorrect response size.", result1.size() == 1);
    assertThat(result1.get(0), instanceOf(ErrorMessageEntity.class));
    ErrorMessageEntity errorMessageEntity1 = (ErrorMessageEntity) result1.get(0);
    assertThat("", errorMessageEntity1.getErrorMessage().getMessage(), equalTo("Invalid result type. Your SELECT query produces a TABLE. Please use CREATE TABLE AS SELECT statement instead."));
    String ksqlString2 = "CREATE STREAM s2 AS SELECT S2_F1 , count(S2_F1) FROM test_stream group by " + "s2_f1;";
    Response response2 = testResource.handleKsqlStatements(new KsqlRequest(ksqlString2, Collections.emptyMap()));
    KsqlEntityList result2 = (KsqlEntityList) response2.getEntity();
    assertThat("Incorrect response size.", result2.size(), equalTo(1));
    assertThat(result2.get(0), instanceOf(ErrorMessageEntity.class));
    ErrorMessageEntity errorMessageEntity2 = (ErrorMessageEntity) result2.get(0);
    assertThat("", errorMessageEntity2.getErrorMessage().getMessage(), equalTo("Invalid " + "result type. Your SELECT query produces a TABLE. Please use CREATE TABLE 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 4 with KsqlRequest

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

the class KsqlResourceTest method makeSingleRequest.

private <R extends KsqlEntity> R makeSingleRequest(KsqlResource testResource, String ksqlString, Statement ksqlStatement, Map<String, Object> streamsProperties, Class<R> responseClass) throws Exception {
    Object responseEntity = testResource.handleKsqlStatements(new KsqlRequest(ksqlString, streamsProperties)).getEntity();
    assertThat(responseEntity, instanceOf(List.class));
    List responseList = (List) responseEntity;
    assertEquals(1, responseList.size());
    Object responseElement = responseList.get(0);
    assertThat(responseElement, instanceOf(responseClass));
    return responseClass.cast(responseElement);
}
Also used : KsqlRequest(io.confluent.ksql.rest.entity.KsqlRequest) StreamsList(io.confluent.ksql.rest.entity.StreamsList) List(java.util.List) KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) TablesList(io.confluent.ksql.rest.entity.TablesList) KsqlTopicsList(io.confluent.ksql.rest.entity.KsqlTopicsList)

Example 5 with KsqlRequest

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

the class KsqlResourceTest method shouldFailForIncorrectDropStreamStatement.

@Test
public void shouldFailForIncorrectDropStreamStatement() throws Exception {
    KsqlResource testResource = TestKsqlResourceUtil.get(ksqlEngine, ksqlRestConfig);
    final String ksqlString = "DROP TABLE test_stream;";
    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 STREAM, but statement was DROP TABLE"));
}
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

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