Skip to content

Commit 7e4f171

Browse files
committed
added total_rows_to_read to metrics
1 parent 64aa9df commit 7e4f171

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ public long getResultRows() {
133133
return operationMetrics.getMetric(ServerMetrics.RESULT_ROWS).getLong();
134134
}
135135

136+
137+
/**
138+
* Alias for {@link ServerMetrics#TOTAL_ROWS_TO_READ}
139+
* @return estimated number of rows to read
140+
*/
141+
public long getTotalRowsToRead() {
142+
return operationMetrics.getMetric(ServerMetrics.TOTAL_ROWS_TO_READ).getLong();
143+
}
144+
136145
/**
137146
* Alias for {@link OperationMetrics#getQueryId()}
138147
* @return query id of the request

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,4 +2018,12 @@ public void testLowCardinalityValues() throws Exception {
20182018
Assert.assertEquals(record.getString("keyword"), values[rowId]);
20192019
}
20202020
}
2021+
2022+
@Test(groups = {"integration"})
2023+
public void testGettingRowsBeforeLimit() throws Exception {
2024+
try (QueryResponse response = client.query("SELECT number FROM system.numbers LIMIT 100").get()) {
2025+
Assert.assertTrue(response.getResultRows() < 1000);
2026+
Assert.assertEquals(response.getTotalRowsToRead(), 100);
2027+
}
2028+
}
20212029
}

0 commit comments

Comments
 (0)