Skip to content

Commit

Permalink
added alias methods for server stats
Browse files Browse the repository at this point in the history
  • Loading branch information
chernser committed Jun 6, 2024
1 parent 455d51f commit 9685e5f
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> DATASET_COLUMNS = Arrays.asList(
Expand Down

0 comments on commit 9685e5f

Please sign in to comment.