Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions client-v2/src/main/java/com/clickhouse/client/api/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,21 @@
private String dbUser;
private String serverVersion;
private Object metricsRegistry;
private int retries;
private final int retries;
private LZ4Factory lz4Factory = null;
private final Supplier<String> queryIdGenerator;

private Client(Set<String> endpoints, Map<String,String> configuration,
ExecutorService sharedOperationExecutor, ColumnToMethodMatchingStrategy columnToMethodMatchingStrategy) {
this(endpoints, configuration, sharedOperationExecutor, columnToMethodMatchingStrategy, null);
ExecutorService sharedOperationExecutor, ColumnToMethodMatchingStrategy columnToMethodMatchingStrategy, Object metricRegistry, Supplier<String> queryIdGenerator) {
this(endpoints, configuration, sharedOperationExecutor, columnToMethodMatchingStrategy, null, metricRegistry, queryIdGenerator);
}

private Client(Set<String> endpoints, Map<String,String> configuration,
ExecutorService sharedOperationExecutor, ColumnToMethodMatchingStrategy columnToMethodMatchingStrategy, Object metricsRegistry) {
// Simple initialization
ExecutorService sharedOperationExecutor, ColumnToMethodMatchingStrategy columnToMethodMatchingStrategy, Object metricsRegistry, Object metricRegistry, Supplier<String> queryIdGenerator) {

Check warning on line 152 in client-v2/src/main/java/com/clickhouse/client/api/Client.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused method parameter "metricRegistry".

See more on https://sonarcloud.io/project/issues?id=ClickHouse_clickhouse-java&issues=AZrbh08MO_d3IRV7xMhH&open=AZrbh08MO_d3IRV7xMhH&pullRequest=2673
this.configuration = ClientConfigProperties.parseConfigMap(configuration);
this.readOnlyConfig = Collections.unmodifiableMap(configuration);
this.metricsRegistry = metricsRegistry;
this.queryIdGenerator = queryIdGenerator;

// Serialization
this.pojoSerDe = new POJOSerDe(columnToMethodMatchingStrategy);
Expand Down Expand Up @@ -267,6 +268,8 @@
private ExecutorService sharedOperationExecutor = null;
private ColumnToMethodMatchingStrategy columnToMethodMatchingStrategy;
private Object metricRegistry = null;
private Supplier<String> queryIdGenerator;

public Builder() {
this.endpoints = new HashSet<>();
this.configuration = new HashMap<>();
Expand Down Expand Up @@ -1048,6 +1051,16 @@
return this;
}

/**
* Sets query id generator. Will be used when operation settings (InsertSettings, QuerySettings) do not have query id set.
* @param supplier
* @return
*/
public Builder queryIdGenerator(Supplier<String> supplier) {
this.queryIdGenerator = supplier;
return this;
}

public Client build() {
// check if endpoint are empty. so can not initiate client
if (this.endpoints.isEmpty()) {
Expand Down Expand Up @@ -1106,7 +1119,7 @@
}

return new Client(this.endpoints, this.configuration, this.sharedOperationExecutor,
this.columnToMethodMatchingStrategy, this.metricRegistry);
this.columnToMethodMatchingStrategy, this.metricRegistry, this.queryIdGenerator);
}
}

Expand Down Expand Up @@ -1245,6 +1258,9 @@
final int maxRetries = retry == null ? 0 : retry;

requestSettings.setOption(ClientConfigProperties.INPUT_OUTPUT_FORMAT.getKey(), format);
if (requestSettings.getQueryId() == null && queryIdGenerator != null) {
requestSettings.setQueryId(queryIdGenerator.get());
}
Supplier<InsertResponse> supplier = () -> {
long startTime = System.nanoTime();
// Selecting some node
Expand Down Expand Up @@ -1462,6 +1478,9 @@
}
sqlStmt.append(" FORMAT ").append(format.name());
requestSettings.serverSetting(ClickHouseHttpProto.QPARAM_QUERY_STMT, sqlStmt.toString());
if (requestSettings.getQueryId() == null && queryIdGenerator != null) {
requestSettings.setQueryId(queryIdGenerator.get());
}
responseSupplier = () -> {
long startTime = System.nanoTime();
// Selecting some node
Expand Down Expand Up @@ -1587,6 +1606,9 @@
if (queryParams != null) {
requestSettings.setOption(HttpAPIClientHelper.KEY_STATEMENT_PARAMS, queryParams);
}
if (requestSettings.getQueryId() == null && queryIdGenerator != null) {
requestSettings.setQueryId(queryIdGenerator.get());
}
responseSupplier = () -> {
long startTime = System.nanoTime();
// Selecting some node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ public long getResultRows() {
return response.getMetrics().getMetric(ServerMetrics.RESULT_ROWS).getLong();
}

/**
* Returns response query id
* @return query id of the request
*/
public String getQueryId() {
return response.getQueryId();
}

@Override
public void close() throws Exception {
response.close();
Expand Down
Loading