Search in sources :

Example 1 with KsqlEntityList

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());
    }
}
Also used : KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) ErrorMessageEntity(io.confluent.ksql.rest.entity.ErrorMessageEntity) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) CommandStatusEntity(io.confluent.ksql.rest.entity.CommandStatusEntity)

Example 2 with KsqlEntityList

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));
}
Also used : KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) PropertiesList(io.confluent.ksql.rest.entity.PropertiesList)

Example 3 with KsqlEntityList

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();
}
Also used : KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) AbstractStreamCreateStatement(io.confluent.ksql.parser.tree.AbstractStreamCreateStatement) Statement(io.confluent.ksql.parser.tree.Statement) DdlStatement(io.confluent.ksql.parser.tree.DdlStatement) ErrorMessageEntity(io.confluent.ksql.rest.entity.ErrorMessageEntity) TimeoutException(java.util.concurrent.TimeoutException) KsqlException(io.confluent.ksql.util.KsqlException) POST(javax.ws.rs.POST)

Example 4 with KsqlEntityList

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();
}
Also used : KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) ExecutionPlan(io.confluent.ksql.rest.entity.ExecutionPlan) POST(javax.ws.rs.POST)

Example 5 with KsqlEntityList

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

KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)13 ErrorMessageEntity (io.confluent.ksql.rest.entity.ErrorMessageEntity)8 Test (org.junit.Test)8 KsqlRequest (io.confluent.ksql.rest.entity.KsqlRequest)7 Response (javax.ws.rs.core.Response)7 CommandStatusEntity (io.confluent.ksql.rest.entity.CommandStatusEntity)3 ExecutionPlan (io.confluent.ksql.rest.entity.ExecutionPlan)3 HashMap (java.util.HashMap)3 PropertiesList (io.confluent.ksql.rest.entity.PropertiesList)2 POST (javax.ws.rs.POST)2 FakeException (io.confluent.ksql.FakeException)1 AbstractStreamCreateStatement (io.confluent.ksql.parser.tree.AbstractStreamCreateStatement)1 DdlStatement (io.confluent.ksql.parser.tree.DdlStatement)1 Statement (io.confluent.ksql.parser.tree.Statement)1 QueryId (io.confluent.ksql.query.QueryId)1 KafkaTopicInfo (io.confluent.ksql.rest.entity.KafkaTopicInfo)1 KafkaTopicsList (io.confluent.ksql.rest.entity.KafkaTopicsList)1 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)1 KsqlTopicInfo (io.confluent.ksql.rest.entity.KsqlTopicInfo)1 KsqlTopicsList (io.confluent.ksql.rest.entity.KsqlTopicsList)1