use of io.confluent.ksql.rest.entity.KsqlEntityList in project ksql by confluentinc.
the class Cli method printKsqlResponse.
private void printKsqlResponse(RestResponse<KsqlEntityList> response) throws IOException {
if (response.isSuccessful()) {
KsqlEntityList ksqlEntities = response.getResponse();
boolean noErrorFromServer = true;
for (KsqlEntity entity : ksqlEntities) {
if (entity instanceof ErrorMessageEntity) {
ErrorMessageEntity errorMsg = (ErrorMessageEntity) entity;
terminal.printErrorMessage(errorMsg.getErrorMessage());
LOGGER.error(errorMsg.getErrorMessage().getMessage());
noErrorFromServer = false;
} else if (entity instanceof CommandStatusEntity && (((CommandStatusEntity) entity).getCommandStatus().getStatus() == CommandStatus.Status.ERROR)) {
String fullMessage = ((CommandStatusEntity) entity).getCommandStatus().getMessage();
terminal.printError(fullMessage.split("\n")[0], fullMessage);
noErrorFromServer = false;
}
}
if (noErrorFromServer) {
terminal.printKsqlEntityList(response.getResponse());
}
} else {
terminal.printErrorMessage(response.getErrorMessage());
}
}
use of io.confluent.ksql.rest.entity.KsqlEntityList in project ksql by confluentinc.
the class Cli method listProperties.
private void listProperties(String statementText) throws IOException {
KsqlEntityList ksqlEntityList = restClient.makeKsqlRequest(statementText).getResponse();
PropertiesList propertiesList = (PropertiesList) ksqlEntityList.get(0);
propertiesList.getProperties().putAll(restClient.getLocalProperties());
terminal.printKsqlEntityList(Collections.singletonList(propertiesList));
}
use of io.confluent.ksql.rest.entity.KsqlEntityList in project ksql by confluentinc.
the class KsqlResource method handleKsqlStatements.
@POST
public Response handleKsqlStatements(KsqlRequest request) throws Exception {
KsqlEntityList result = new KsqlEntityList();
try {
List<Statement> parsedStatements = ksqlEngine.getStatements(request.getKsql());
List<String> statementStrings = getStatementStrings(request.getKsql());
Map<String, Object> streamsProperties = request.getStreamsProperties();
if (parsedStatements.size() != statementStrings.size()) {
throw new Exception(String.format("Size of parsed statements and statement strings differ; %d vs. %d, respectively", parsedStatements.size(), statementStrings.size()));
}
for (int i = 0; i < parsedStatements.size(); i++) {
String statementText = statementStrings.get(i);
result.add(executeStatement(statementText, parsedStatements.get(i), streamsProperties));
}
} catch (Exception exception) {
log.error("Failed to handle POST:" + request, exception);
result.add(new ErrorMessageEntity(request.getKsql(), exception));
}
return Response.ok(result).build();
}
use of io.confluent.ksql.rest.entity.KsqlEntityList in project ksql by confluentinc.
the class MockKsqlResources method handleKsqlStatements.
@POST
public Response handleKsqlStatements(KsqlRequest request) throws Exception {
KsqlEntityList result = new KsqlEntityList();
result.add(new ExecutionPlan("TestExecution plan"));
return Response.ok(result).build();
}
use of io.confluent.ksql.rest.entity.KsqlEntityList 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."));
}
Aggregations