Skip to content

Commit 02665ed

Browse files
authored
Merge pull request #1683 from ClickHouse/add_metrics_to_recrods
Added metrics to the Records class
2 parents fa65363 + eebce2a commit 02665ed

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.clickhouse.client.api.data_formats.ClickHouseBinaryFormatReader;
55
import com.clickhouse.client.api.data_formats.RowBinaryWithNamesAndTypesFormatReader;
66
import com.clickhouse.client.api.data_formats.internal.BinaryReaderBackedRecord;
7+
import com.clickhouse.client.api.metrics.OperationMetrics;
8+
import com.clickhouse.client.api.metrics.ServerMetrics;
79
import com.clickhouse.data.ClickHouseFormat;
810

911
import java.util.Iterator;
@@ -69,4 +71,61 @@ boolean isEmpty() {
6971
Stream<GenericRecord> stream() {
7072
return StreamSupport.stream(spliterator(), false);
7173
}
74+
75+
/**
76+
* Returns the metrics of this operation.
77+
*
78+
* @return metrics of this operation
79+
*/
80+
public OperationMetrics getMetrics() {
81+
return response.getMetrics();
82+
}
83+
84+
/**
85+
* Alias for {@link ServerMetrics#NUM_ROWS_READ}
86+
* @return number of rows read by server from the storage
87+
*/
88+
public long getReadRows() {
89+
return response.getMetrics().getMetric(ServerMetrics.NUM_ROWS_READ).getLong();
90+
}
91+
92+
/**
93+
* Alias for {@link ServerMetrics#NUM_BYTES_READ}
94+
* @return number of bytes read by server from the storage
95+
*/
96+
public long getReadBytes() {
97+
return response.getMetrics().getMetric(ServerMetrics.NUM_BYTES_READ).getLong();
98+
}
99+
100+
/**
101+
* Alias for {@link ServerMetrics#NUM_ROWS_WRITTEN}
102+
* @return number of rows written by server to the storage
103+
*/
104+
public long getWrittenRows() {
105+
return response.getMetrics().getMetric(ServerMetrics.NUM_ROWS_WRITTEN).getLong();
106+
}
107+
108+
/**
109+
* Alias for {@link ServerMetrics#NUM_BYTES_WRITTEN}
110+
* @return number of bytes written by server to the storage
111+
*/
112+
public long getWrittenBytes() {
113+
return response.getMetrics().getMetric(ServerMetrics.NUM_BYTES_WRITTEN).getLong();
114+
}
115+
116+
/**
117+
* Alias for {@link ServerMetrics#ELAPSED_TIME}
118+
* @return elapsed time in nanoseconds
119+
*/
120+
public long getServerTime() {
121+
return response.getMetrics().getMetric(ServerMetrics.ELAPSED_TIME).getLong();
122+
}
123+
124+
/**
125+
* Alias for {@link ServerMetrics#RESULT_ROWS}
126+
* @return number of returned rows
127+
*/
128+
public long getResultRows() {
129+
return response.getMetrics().getMetric(ServerMetrics.RESULT_ROWS).getLong();
130+
}
72131
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public void testReadRecords() throws Exception {
118118
prepareDataSet(DATASET_TABLE, DATASET_COLUMNS, DATASET_VALUE_GENERATORS, 10);
119119

120120
Records records = client.queryRecords("SELECT * FROM " + DATASET_TABLE).get(3, TimeUnit.SECONDS);
121-
121+
Assert.assertTrue(records.getResultRows() == 10, "Unexpected number of rows");
122122
for (GenericRecord record : records) {
123123
record.getString(3); // string column col3
124124
}

0 commit comments

Comments
 (0)