com.clickhouse.client.api.insert.InsertResponse Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of client-v2 Show documentation
Show all versions of client-v2 Show documentation
New client api for ClickHouse
package com.clickhouse.client.api.insert;
import com.clickhouse.client.ClickHouseClient;
import com.clickhouse.client.ClickHouseResponse;
import com.clickhouse.client.api.internal.ClientStatisticsHolder;
import com.clickhouse.client.api.internal.ClientV1AdaptorHelper;
import com.clickhouse.client.api.metrics.OperationMetrics;
import com.clickhouse.client.api.metrics.ServerMetrics;
public class InsertResponse implements AutoCloseable {
private final ClickHouseResponse responseRef;
private OperationMetrics operationMetrics;
public InsertResponse(ClickHouseResponse responseRef,
ClientStatisticsHolder clientStatisticsHolder) {
this.responseRef = responseRef;
this.operationMetrics = new OperationMetrics(clientStatisticsHolder);
this.operationMetrics.operationComplete();
this.operationMetrics.setQueryId(responseRef.getSummary().getQueryId());
ClientV1AdaptorHelper.setServerStats(responseRef.getSummary().getProgress(), this.operationMetrics);
}
public InsertResponse(OperationMetrics metrics) {
this.responseRef = null;
this.operationMetrics = metrics;
}
@Override
public void close() {
if (responseRef != null) {
responseRef.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();
}
/**
* Alias for {@link OperationMetrics#getQueryId()}
* @return number of returned bytes
*/
public String getQueryId() {
return operationMetrics.getQueryId();
}
}