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;
}
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));
}
}
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."));
}
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);
}
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"));
}
Aggregations