use of io.confluent.ksql.api.utils.QueryResponse in project ksql by confluentinc.
the class PullQueryMetricsHttp2FunctionalTest method executeQueryWithVariables.
private QueryResponse executeQueryWithVariables(final String sql, final JsonObject variables) {
JsonObject properties = new JsonObject();
JsonObject requestBody = new JsonObject().put("sql", sql).put("properties", properties).put("sessionVariables", variables);
HttpResponse<Buffer> response = sendRequest("/query-stream", requestBody.toBuffer());
return new QueryResponse(response.bodyAsString());
}
use of io.confluent.ksql.api.utils.QueryResponse in project ksql by confluentinc.
the class PullBandwidthThrottleIntegrationTest method pullStreamBandwidthThrottleTest.
@Test
public void pullStreamBandwidthThrottleTest() {
String veryLong = createDataSize(100000);
String sql = "SELECT CONCAT(\'" + veryLong + "\') as placeholder from " + TEST_STREAM + ";";
// the pull query should go through 2 times
for (int i = 0; i < 2; i += 1) {
assertThatEventually(() -> {
QueryResponse queryResponse1 = executeQuery(sql);
return queryResponse1.rows;
}, hasSize(7));
}
// the third try should fail
try {
executeQuery(sql);
} catch (KsqlException e) {
assertEquals(RATE_LIMIT_MESSAGE, e.getMessage());
}
}
use of io.confluent.ksql.api.utils.QueryResponse in project ksql by confluentinc.
the class ApiIntegrationTest method shouldExecutePushQueryFromLatestOffset.
@Test
public void shouldExecutePushQueryFromLatestOffset() {
KsqlEngine engine = (KsqlEngine) REST_APP.getEngine();
// One persistent query for the agg table
assertThatEventually(engine::numberOfLiveQueries, is(1));
// Given:
String sql = "SELECT * from " + TEST_STREAM + " EMIT CHANGES LIMIT 1;";
// Create a write stream to capture the incomplete response
ReceiveStream writeStream = new ReceiveStream(vertx);
// Make the request to stream a query
JsonObject queryProperties = new JsonObject().put("auto.offset.reset", "latest");
JsonObject queryRequestBody = new JsonObject().put("sql", sql).put("properties", queryProperties);
VertxCompletableFuture<HttpResponse<Void>> responseFuture = new VertxCompletableFuture<>();
client.post("/query-stream").as(BodyCodec.pipe(writeStream)).sendJsonObject(queryRequestBody, responseFuture);
assertThatEventually(engine::numberOfLiveQueries, is(2));
// New row to insert
JsonObject row = new JsonObject().put("K", new JsonObject().put("F1", new JsonArray().add("my_key_shouldExecutePushQueryFromLatestOffset"))).put("STR", "Value_shouldExecutePushQueryFromLatestOffset").put("LONG", 2000L).put("DEC", // JsonObject does not accept BigDecimal
12.34).put("BYTES_", new byte[] { 0, 1, 2 }).put("ARRAY", new JsonArray().add("a_shouldExecutePushQueryFromLatestOffset")).put("MAP", new JsonObject().put("k1", "v1_shouldExecutePushQueryFromLatestOffset")).put("STRUCT", new JsonObject().put("F1", 3)).put("COMPLEX", COMPLEX_FIELD_VALUE);
// Insert a new row and wait for it to arrive
assertThatEventually(() -> {
try {
// Attempt the insert multiple times, in case the query hasn't started yet
shouldInsert(row);
Buffer buff = writeStream.getBody();
QueryResponse queryResponse = new QueryResponse(buff.toString());
return queryResponse.rows.size();
} catch (Throwable t) {
return Integer.MAX_VALUE;
}
}, is(1));
// Verify that the received row is the expected one
Buffer buff = writeStream.getBody();
QueryResponse queryResponse = new QueryResponse(buff.toString());
assertThat(queryResponse.rows.get(0).getJsonObject(0), is(new JsonObject().put("F1", new JsonArray().add("my_key_shouldExecutePushQueryFromLatestOffset"))));
assertThat(queryResponse.rows.get(0).getString(1), is("Value_shouldExecutePushQueryFromLatestOffset"));
assertThat(queryResponse.rows.get(0).getLong(2), is(2000L));
assertThat(queryResponse.rows.get(0).getDouble(3), is(12.34));
assertThat(queryResponse.rows.get(0).getBinary(4), is(new byte[] { 0, 1, 2 }));
assertThat(queryResponse.rows.get(0).getJsonArray(5), is(new JsonArray().add("a_shouldExecutePushQueryFromLatestOffset")));
assertThat(queryResponse.rows.get(0).getJsonObject(6), is(new JsonObject().put("k1", "v1_shouldExecutePushQueryFromLatestOffset")));
assertThat(queryResponse.rows.get(0).getJsonObject(7), is(new JsonObject().put("F1", 3)));
assertThat(queryResponse.rows.get(0).getJsonObject(8), is(COMPLEX_FIELD_VALUE));
// Check that query is cleaned up on the server
assertThatEventually(engine::numberOfLiveQueries, is(1));
}
use of io.confluent.ksql.api.utils.QueryResponse in project ksql by confluentinc.
the class ApiIntegrationTest method executeQueryWithVariables.
private QueryResponse executeQueryWithVariables(final String sql, final JsonObject variables) {
JsonObject properties = new JsonObject();
JsonObject requestBody = new JsonObject().put("sql", sql).put("properties", properties).put("sessionVariables", variables);
HttpResponse<Buffer> response = sendRequest("/query-stream", requestBody.toBuffer());
return new QueryResponse(response.bodyAsString());
}
use of io.confluent.ksql.api.utils.QueryResponse in project ksql by confluentinc.
the class ApiIntegrationTest method shouldExecutePullQuery.
@Test
public void shouldExecutePullQuery() {
// Given:
String sql = "SELECT * from " + AGG_TABLE + " WHERE K=" + AN_AGG_KEY + ";";
// When:
// Maybe need to retry as populating agg table is async
AtomicReference<QueryResponse> atomicReference = new AtomicReference<>();
assertThatEventually(() -> {
QueryResponse queryResponse = executeQuery(sql);
atomicReference.set(queryResponse);
return queryResponse.rows;
}, hasSize(1));
QueryResponse response = atomicReference.get();
// Then:
JsonArray expectedColumnNames = new JsonArray().add("K").add("LONG");
JsonArray expectedColumnTypes = new JsonArray().add("STRUCT<`F1` ARRAY<STRING>>").add("BIGINT");
assertThat(response.rows, hasSize(1));
assertThat(response.responseObject.getJsonArray("columnNames"), is(expectedColumnNames));
assertThat(response.responseObject.getJsonArray("columnTypes"), is(expectedColumnTypes));
assertThat(response.responseObject.getString("queryId"), startsWith("query_"));
// rowkey
assertThat(response.rows.get(0).getJsonObject(0).getJsonArray("F1").getString(0), is("a"));
// latest_by_offset(long)
assertThat(response.rows.get(0).getLong(1), is(1L));
}
Aggregations