Search in sources :

Example 1 with KsqlException

use of io.confluent.ksql.api.client.exception.KsqlException in project ksql by confluentinc.

the class StreamQueryResponseHandler method handleRow.

@Override
protected void handleRow(final Buffer buff) {
    if (queryResult == null) {
        throw new IllegalStateException("handleRow called before metadata processed");
    }
    final Object json = buff.toJson();
    final Row row;
    if (json instanceof JsonArray) {
        row = new RowImpl(queryResult.columnNames(), queryResult.columnTypes(), (JsonArray) json, columnNameToIndex);
        final boolean full = queryResult.accept(row);
        if (full && !paused) {
            recordParser.pause();
            queryResult.drainHandler(this::publisherReceptive);
            paused = true;
        }
    } else if (json instanceof JsonObject) {
        final JsonObject jsonObject = (JsonObject) json;
        // Don't add it to the publisher's buffer since the user should not see it
        if (jsonObject.getMap() != null && jsonObject.getMap().containsKey("consistencyToken")) {
            LOG.info("Response contains consistency vector " + jsonObject);
            serializedConsistencyVector.set((String) ((JsonObject) json).getMap().get("consistencyToken"));
        } else {
            queryResult.handleError(new KsqlException(jsonObject.getString("message")));
        }
    } else {
        throw new RuntimeException("Could not decode JSON: " + json);
    }
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonObject(io.vertx.core.json.JsonObject) JsonObject(io.vertx.core.json.JsonObject) Row(io.confluent.ksql.api.client.Row) KsqlException(io.confluent.ksql.api.client.exception.KsqlException)

Aggregations

Row (io.confluent.ksql.api.client.Row)1 KsqlException (io.confluent.ksql.api.client.exception.KsqlException)1 JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1