Skip to content

Commit 9685e5f

Browse files
committed
added alias methods for server stats
1 parent 455d51f commit 9685e5f

File tree

4 files changed

+111
-0
lines changed

4 files changed

+111
-0
lines changed

client-v2/src/main/java/com/clickhouse/client/api/insert/InsertResponse.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.clickhouse.client.ClickHouseResponse;
55
import com.clickhouse.client.api.internal.ClientStatisticsHolder;
66
import com.clickhouse.client.api.metrics.OperationMetrics;
7+
import com.clickhouse.client.api.metrics.ServerMetrics;
78

89
public class InsertResponse implements AutoCloseable {
910
private final ClickHouseResponse responseRef;
@@ -28,7 +29,60 @@ public void close() {
2829
}
2930
}
3031

32+
/**
33+
* Returns the metrics of this operation.
34+
*
35+
* @return metrics of this operation
36+
*/
3137
public OperationMetrics getMetrics() {
3238
return operationMetrics;
3339
}
40+
41+
/**
42+
* Alias for {@link ServerMetrics#NUM_ROWS_READ}
43+
* @return number of rows read by server from the storage
44+
*/
45+
public long getReadRows() {
46+
return operationMetrics.getMetric(ServerMetrics.NUM_ROWS_READ).getLong();
47+
}
48+
49+
/**
50+
* Alias for {@link ServerMetrics#NUM_BYTES_READ}
51+
* @return number of bytes read by server from the storage
52+
*/
53+
public long getReadBytes() {
54+
return operationMetrics.getMetric(ServerMetrics.NUM_BYTES_READ).getLong();
55+
}
56+
57+
/**
58+
* Alias for {@link ServerMetrics#NUM_ROWS_WRITTEN}
59+
* @return number of rows written by server to the storage
60+
*/
61+
public long getWrittenRows() {
62+
return operationMetrics.getMetric(ServerMetrics.NUM_ROWS_WRITTEN).getLong();
63+
}
64+
65+
/**
66+
* Alias for {@link ServerMetrics#NUM_BYTES_WRITTEN}
67+
* @return number of bytes written by server to the storage
68+
*/
69+
public long getWrittenBytes() {
70+
return operationMetrics.getMetric(ServerMetrics.NUM_BYTES_WRITTEN).getLong();
71+
}
72+
73+
/**
74+
* Alias for {@link ServerMetrics#ELAPSED_TIME}
75+
* @return elapsed time in nanoseconds
76+
*/
77+
public long getServerTime() {
78+
return operationMetrics.getMetric(ServerMetrics.ELAPSED_TIME).getLong();
79+
}
80+
81+
/**
82+
* Alias for {@link ServerMetrics#RESULT_ROWS}
83+
* @return number of returned rows
84+
*/
85+
public long getResultRows() {
86+
return operationMetrics.getMetric(ServerMetrics.RESULT_ROWS).getLong();
87+
}
3488
}

client-v2/src/main/java/com/clickhouse/client/api/query/QueryResponse.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.clickhouse.client.api.ClientException;
66
import com.clickhouse.client.api.internal.ClientStatisticsHolder;
77
import com.clickhouse.client.api.metrics.OperationMetrics;
8+
import com.clickhouse.client.api.metrics.ServerMetrics;
89
import com.clickhouse.data.ClickHouseFormat;
910
import com.clickhouse.data.ClickHouseInputStream;
1011

@@ -94,8 +95,61 @@ public ClickHouseFormat getFormat() {
9495
return format;
9596
}
9697

98+
/**
99+
* Returns the metrics of this operation.
100+
*
101+
* @return metrics of this operation
102+
*/
97103
public OperationMetrics getMetrics() {
98104
ensureDone();
99105
return operationMetrics;
100106
}
107+
108+
/**
109+
* Alias for {@link ServerMetrics#NUM_ROWS_READ}
110+
* @return number of rows read by server from the storage
111+
*/
112+
public long getReadRows() {
113+
return operationMetrics.getMetric(ServerMetrics.NUM_ROWS_READ).getLong();
114+
}
115+
116+
/**
117+
* Alias for {@link ServerMetrics#NUM_BYTES_READ}
118+
* @return number of bytes read by server from the storage
119+
*/
120+
public long getReadBytes() {
121+
return operationMetrics.getMetric(ServerMetrics.NUM_BYTES_READ).getLong();
122+
}
123+
124+
/**
125+
* Alias for {@link ServerMetrics#NUM_ROWS_WRITTEN}
126+
* @return number of rows written by server to the storage
127+
*/
128+
public long getWrittenRows() {
129+
return operationMetrics.getMetric(ServerMetrics.NUM_ROWS_WRITTEN).getLong();
130+
}
131+
132+
/**
133+
* Alias for {@link ServerMetrics#NUM_BYTES_WRITTEN}
134+
* @return number of bytes written by server to the storage
135+
*/
136+
public long getWrittenBytes() {
137+
return operationMetrics.getMetric(ServerMetrics.NUM_BYTES_WRITTEN).getLong();
138+
}
139+
140+
/**
141+
* Alias for {@link ServerMetrics#ELAPSED_TIME}
142+
* @return elapsed time in nanoseconds
143+
*/
144+
public long getServerTime() {
145+
return operationMetrics.getMetric(ServerMetrics.ELAPSED_TIME).getLong();
146+
}
147+
148+
/**
149+
* Alias for {@link ServerMetrics#RESULT_ROWS}
150+
* @return number of returned rows
151+
*/
152+
public long getResultRows() {
153+
return operationMetrics.getMetric(ServerMetrics.RESULT_ROWS).getLong();
154+
}
101155
}

client-v2/src/test/java/com/clickhouse/client/insert/InsertTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public void insertSimplePOJOs() throws Exception {
6868

6969
OperationMetrics metrics = response.getMetrics();
7070
assertEquals(simplePOJOs.size(), metrics.getMetric(ServerMetrics.NUM_ROWS_WRITTEN).getLong());
71+
assertEquals(simplePOJOs.size(), response.getWrittenRows());
7172
assertTrue(metrics.getMetric(ClientMetrics.OP_DURATION).getLong() > 0);
7273
assertTrue(metrics.getMetric(ClientMetrics.OP_SERIALIZATION).getLong() > 0);
7374
}

client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,9 @@ public void testQueryMetrics() throws Exception {
924924

925925
Assert.assertEquals(metrics.getMetric(ServerMetrics.NUM_ROWS_READ).getLong(), rowsToInsert); // 10 rows in the table
926926
Assert.assertEquals(metrics.getMetric(ServerMetrics.RESULT_ROWS).getLong(), rowsToInsert);
927+
Assert.assertEquals(response.getReadRows(), rowsToInsert);
927928
Assert.assertTrue(metrics.getMetric(ClientMetrics.OP_DURATION).getLong() > 0);
929+
928930
}
929931

930932
private final static List<String> DATASET_COLUMNS = Arrays.asList(

0 commit comments

Comments
 (0)