Skip to content

Commit c30c346

Browse files
authored
Merge pull request #1699 from ClickHouse/add-query-id-summary
Adding query_id to V1 client
2 parents a593b52 + b061b48 commit c30c346

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseResponseSummary.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class ClickHouseResponseSummary implements Serializable {
2020
public static final class Progress implements Serializable {
2121
private static final long serialVersionUID = -1447066780591278108L;
2222

23-
static final Progress EMPTY = new Progress(0L, 0L, 0L, 0L, 0L, 0L, 0L);
23+
static final Progress EMPTY = new Progress(0L, 0L, 0L, 0L, 0L, 0L, 0L, "");
2424

2525
private final long read_rows;
2626
private final long read_bytes;
@@ -29,6 +29,7 @@ public static final class Progress implements Serializable {
2929
private final long written_bytes;
3030
private final long elapsed_time;
3131
private final long result_rows;
32+
private final String query_id;
3233

3334
/**
3435
* Default constructor.
@@ -39,16 +40,34 @@ public static final class Progress implements Serializable {
3940
* @param written_rows Number of rows written
4041
* @param written_bytes Volume of data written in bytes
4142
* @param elapsed_time Query processing time in (ns)
43+
* @param result_rows Number of rows in the result
4244
*/
4345
public Progress(long read_rows, long read_bytes, long total_rows_to_read, long written_rows,
44-
long written_bytes, long elapsed_time, long result_rows) {
46+
long written_bytes, long elapsed_time, long result_rows) {
47+
this(read_rows, read_bytes, total_rows_to_read, written_rows, written_bytes, elapsed_time, result_rows, "");
48+
}
49+
/**
50+
* Default constructor.
51+
*
52+
* @param read_rows Number of rows read
53+
* @param read_bytes Volume of data read in bytes
54+
* @param total_rows_to_read Total number of rows to be read
55+
* @param written_rows Number of rows written
56+
* @param written_bytes Volume of data written in bytes
57+
* @param elapsed_time Query processing time in (ns)
58+
* @param result_rows Number of rows in the result
59+
* @param query_id Query ID
60+
*/
61+
public Progress(long read_rows, long read_bytes, long total_rows_to_read, long written_rows,
62+
long written_bytes, long elapsed_time, long result_rows, String query_id) {
4563
this.read_rows = read_rows;
4664
this.read_bytes = read_bytes;
4765
this.total_rows_to_read = total_rows_to_read;
4866
this.written_rows = written_rows;
4967
this.written_bytes = written_bytes;
5068
this.elapsed_time = elapsed_time;
5169
this.result_rows = result_rows;
70+
this.query_id = query_id;
5271
}
5372

5473
public long getReadRows() {
@@ -78,6 +97,10 @@ public long getElapsedTime() {
7897
public long getResultRows() {
7998
return result_rows;
8099
}
100+
101+
public String getQueryId() {
102+
return query_id;
103+
}
81104
public Progress add(Progress progress) {
82105
if (progress == null) {
83106
return this;
@@ -86,7 +109,7 @@ public Progress add(Progress progress) {
86109
return new Progress(read_rows + progress.read_rows, read_bytes + progress.read_bytes,
87110
total_rows_to_read + progress.total_rows_to_read, written_rows + progress.written_rows,
88111
written_bytes + progress.written_bytes,elapsed_time + progress.elapsed_time,
89-
result_rows + progress.result_rows);
112+
result_rows + progress.result_rows, query_id + ", " + progress.query_id);
90113
}
91114

92115
public boolean isEmpty() {
@@ -322,6 +345,10 @@ public long getResultRows() {
322345
return progress.get().getResultRows();
323346
}
324347

348+
public String getQueryId() {
349+
return progress.get().getQueryId();
350+
}
351+
325352
public boolean isEmpty() {
326353
return progress.get().isEmpty() && stats.get().isEmpty();
327354
}

clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseResponseSummaryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
public class ClickHouseResponseSummaryTest {
1010
@Test(groups = { "unit" })
11-
public void testConsutrctor() {
11+
public void testConstructor() {
1212
ClickHouseResponseSummary summary = new ClickHouseResponseSummary(null, null);
1313
Assert.assertNotNull(summary.getProgress());
1414
Assert.assertNotNull(summary.getStatistics());

clickhouse-http-client/src/main/java/com/clickhouse/client/http/ClickHouseHttpResponse.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.clickhouse.data.ClickHouseFormat;
1515
import com.clickhouse.data.ClickHouseInputStream;
1616
import com.clickhouse.data.ClickHouseUtils;
17+
import com.clickhouse.logging.Logger;
1718

1819
public class ClickHouseHttpResponse {
1920
private static long getLongValue(Map<String, String> map, String key) {
@@ -70,7 +71,7 @@ public ClickHouseHttpResponse(ClickHouseHttpConnection connection, ClickHouseInp
7071
new ClickHouseResponseSummary.Progress(getLongValue(map, "read_rows"), getLongValue(map, "read_bytes"),
7172
getLongValue(map, "total_rows_to_read"), getLongValue(map, "written_rows"),
7273
getLongValue(map, "written_bytes"), getLongValue(map, "elapsed_ns"),
73-
getLongValue(map, "result_rows")),
74+
getLongValue(map, "result_rows"), this.queryId),
7475
null);
7576

7677
this.format = format != null ? format : connection.config.getFormat();

clickhouse-http-client/src/test/java/com/clickhouse/client/http/ClickHouseHttpClientTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,21 @@ public void testPost() throws ClickHouseException {
414414
}
415415
}
416416

417+
@Test(groups = {"integration"})
418+
public void testQueryId() throws ClickHouseException {
419+
ClickHouseNode server = getServer(ClickHouseProtocol.HTTP);
420+
String uuid = UUID.randomUUID().toString();
421+
422+
try (ClickHouseClient client = ClickHouseClient.builder().options(getClientOptions())
423+
.defaultCredentials(ClickHouseCredentials.fromUserAndPassword("foo", "bar")).build()) {
424+
try (ClickHouseResponse resp = newRequest(client, server).compressServerResponse(false)
425+
.format(ClickHouseFormat.RowBinaryWithNamesAndTypes)
426+
.query("select 1,2", uuid).executeAndWait()) {
427+
Assert.assertEquals(resp.getSummary().getQueryId(), uuid);
428+
}
429+
}
430+
}
431+
417432
@Test(groups = {"integration"})
418433
public void testProxyConnection() throws ClickHouseException, IOException {
419434
ToxiproxyContainer toxiproxy = null;

0 commit comments

Comments
 (0)