diff --git a/client-v2/src/main/java/com/clickhouse/client/api/insert/InsertResponse.java b/client-v2/src/main/java/com/clickhouse/client/api/insert/InsertResponse.java index 85ff85b1d..72582bb1e 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/insert/InsertResponse.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/insert/InsertResponse.java @@ -4,6 +4,7 @@ import com.clickhouse.client.ClickHouseResponse; import com.clickhouse.client.api.internal.ClientStatisticsHolder; import com.clickhouse.client.api.metrics.OperationMetrics; +import com.clickhouse.client.api.metrics.ServerMetrics; public class InsertResponse implements AutoCloseable { private final ClickHouseResponse responseRef; @@ -28,7 +29,60 @@ public void close() { } } + /** + * Returns the metrics of this operation. + * + * @return metrics of this operation + */ public OperationMetrics getMetrics() { return operationMetrics; } + + /** + * Alias for {@link ServerMetrics#NUM_ROWS_READ} + * @return number of rows read by server from the storage + */ + public long getReadRows() { + return operationMetrics.getMetric(ServerMetrics.NUM_ROWS_READ).getLong(); + } + + /** + * Alias for {@link ServerMetrics#NUM_BYTES_READ} + * @return number of bytes read by server from the storage + */ + public long getReadBytes() { + return operationMetrics.getMetric(ServerMetrics.NUM_BYTES_READ).getLong(); + } + + /** + * Alias for {@link ServerMetrics#NUM_ROWS_WRITTEN} + * @return number of rows written by server to the storage + */ + public long getWrittenRows() { + return operationMetrics.getMetric(ServerMetrics.NUM_ROWS_WRITTEN).getLong(); + } + + /** + * Alias for {@link ServerMetrics#NUM_BYTES_WRITTEN} + * @return number of bytes written by server to the storage + */ + public long getWrittenBytes() { + return operationMetrics.getMetric(ServerMetrics.NUM_BYTES_WRITTEN).getLong(); + } + + /** + * Alias for {@link ServerMetrics#ELAPSED_TIME} + * @return elapsed time in nanoseconds + */ + public long getServerTime() { + return operationMetrics.getMetric(ServerMetrics.ELAPSED_TIME).getLong(); + } + + /** + * Alias for {@link ServerMetrics#RESULT_ROWS} + * @return number of returned rows + */ + public long getResultRows() { + return operationMetrics.getMetric(ServerMetrics.RESULT_ROWS).getLong(); + } } diff --git a/client-v2/src/main/java/com/clickhouse/client/api/query/QueryResponse.java b/client-v2/src/main/java/com/clickhouse/client/api/query/QueryResponse.java index c4056df4e..78dd026e6 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/query/QueryResponse.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/query/QueryResponse.java @@ -5,6 +5,7 @@ import com.clickhouse.client.api.ClientException; import com.clickhouse.client.api.internal.ClientStatisticsHolder; import com.clickhouse.client.api.metrics.OperationMetrics; +import com.clickhouse.client.api.metrics.ServerMetrics; import com.clickhouse.data.ClickHouseFormat; import com.clickhouse.data.ClickHouseInputStream; @@ -94,8 +95,61 @@ public ClickHouseFormat getFormat() { return format; } + /** + * Returns the metrics of this operation. + * + * @return metrics of this operation + */ public OperationMetrics getMetrics() { ensureDone(); return operationMetrics; } + + /** + * Alias for {@link ServerMetrics#NUM_ROWS_READ} + * @return number of rows read by server from the storage + */ + public long getReadRows() { + return operationMetrics.getMetric(ServerMetrics.NUM_ROWS_READ).getLong(); + } + + /** + * Alias for {@link ServerMetrics#NUM_BYTES_READ} + * @return number of bytes read by server from the storage + */ + public long getReadBytes() { + return operationMetrics.getMetric(ServerMetrics.NUM_BYTES_READ).getLong(); + } + + /** + * Alias for {@link ServerMetrics#NUM_ROWS_WRITTEN} + * @return number of rows written by server to the storage + */ + public long getWrittenRows() { + return operationMetrics.getMetric(ServerMetrics.NUM_ROWS_WRITTEN).getLong(); + } + + /** + * Alias for {@link ServerMetrics#NUM_BYTES_WRITTEN} + * @return number of bytes written by server to the storage + */ + public long getWrittenBytes() { + return operationMetrics.getMetric(ServerMetrics.NUM_BYTES_WRITTEN).getLong(); + } + + /** + * Alias for {@link ServerMetrics#ELAPSED_TIME} + * @return elapsed time in nanoseconds + */ + public long getServerTime() { + return operationMetrics.getMetric(ServerMetrics.ELAPSED_TIME).getLong(); + } + + /** + * Alias for {@link ServerMetrics#RESULT_ROWS} + * @return number of returned rows + */ + public long getResultRows() { + return operationMetrics.getMetric(ServerMetrics.RESULT_ROWS).getLong(); + } } diff --git a/client-v2/src/test/java/com/clickhouse/client/insert/InsertTests.java b/client-v2/src/test/java/com/clickhouse/client/insert/InsertTests.java index 691d6bbf8..3d4e63020 100644 --- a/client-v2/src/test/java/com/clickhouse/client/insert/InsertTests.java +++ b/client-v2/src/test/java/com/clickhouse/client/insert/InsertTests.java @@ -68,6 +68,7 @@ public void insertSimplePOJOs() throws Exception { OperationMetrics metrics = response.getMetrics(); assertEquals(simplePOJOs.size(), metrics.getMetric(ServerMetrics.NUM_ROWS_WRITTEN).getLong()); + assertEquals(simplePOJOs.size(), response.getWrittenRows()); assertTrue(metrics.getMetric(ClientMetrics.OP_DURATION).getLong() > 0); assertTrue(metrics.getMetric(ClientMetrics.OP_SERIALIZATION).getLong() > 0); } diff --git a/client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java b/client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java index 2dd27a73d..d70bcf2f4 100644 --- a/client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java +++ b/client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java @@ -924,7 +924,9 @@ public void testQueryMetrics() throws Exception { Assert.assertEquals(metrics.getMetric(ServerMetrics.NUM_ROWS_READ).getLong(), rowsToInsert); // 10 rows in the table Assert.assertEquals(metrics.getMetric(ServerMetrics.RESULT_ROWS).getLong(), rowsToInsert); + Assert.assertEquals(response.getReadRows(), rowsToInsert); Assert.assertTrue(metrics.getMetric(ClientMetrics.OP_DURATION).getLong() > 0); + } private final static List DATASET_COLUMNS = Arrays.asList(