Skip to content

Commit b7ce67c

Browse files
authored
Merge pull request #2486 from ClickHouse/fix_head_build
[client-v2] Fix the build
2 parents 3397eb2 + 064f3cc commit b7ce67c

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

client-v2/src/main/java/com/clickhouse/client/api/Client.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,7 @@ public CompletableFuture<InsertResponse> insert(String tableName, List<?> data,
11971197
Integer retry = (Integer) configuration.get(ClientConfigProperties.RETRY_ON_FAILURE.getKey());
11981198
final int maxRetries = retry == null ? 0 : retry;
11991199

1200-
settings.setOption(ClientConfigProperties.INPUT_OUTPUT_FORMAT.getKey(), format.name());
1200+
settings.setOption(ClientConfigProperties.INPUT_OUTPUT_FORMAT.getKey(), format);
12011201
final InsertSettings finalSettings = new InsertSettings(buildRequestSettings(settings.getAllSettings()));
12021202
Supplier<InsertResponse> supplier = () -> {
12031203
long startTime = System.nanoTime();
@@ -1400,7 +1400,7 @@ public CompletableFuture<InsertResponse> insert(String tableName,
14001400
throw new IllegalArgumentException("Buffer size must be greater than 0");
14011401
}
14021402

1403-
settings.setOption(ClientConfigProperties.INPUT_OUTPUT_FORMAT.getKey(), format.name());
1403+
settings.setOption(ClientConfigProperties.INPUT_OUTPUT_FORMAT.getKey(), format);
14041404
final InsertSettings finalSettings = new InsertSettings(buildRequestSettings(settings.getAllSettings()));
14051405

14061406
StringBuilder sqlStmt = new StringBuilder("INSERT INTO ").append(tableName);

client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.clickhouse.client.api.enums.ProxyType;
1515
import com.clickhouse.client.api.http.ClickHouseHttpProto;
1616
import com.clickhouse.client.api.transport.Endpoint;
17+
import com.clickhouse.data.ClickHouseFormat;
1718
import net.jpountz.lz4.LZ4Factory;
1819
import org.apache.hc.client5.http.ConnectTimeoutException;
1920
import org.apache.hc.client5.http.classic.methods.HttpPost;
@@ -64,6 +65,7 @@
6465
import java.io.IOException;
6566
import java.io.InputStream;
6667
import java.io.OutputStream;
68+
import java.io.UnsupportedEncodingException;
6769
import java.lang.reflect.Method;
6870
import java.net.ConnectException;
6971
import java.net.InetSocketAddress;
@@ -449,13 +451,13 @@ private void addHeaders(HttpPost req, Map<String, Object> requestConfig) {
449451
addHeader(
450452
req,
451453
ClickHouseHttpProto.HEADER_FORMAT,
452-
requestConfig.get(ClientConfigProperties.INPUT_OUTPUT_FORMAT.getKey()));
454+
((ClickHouseFormat) requestConfig.get(ClientConfigProperties.INPUT_OUTPUT_FORMAT.getKey())).name());
453455
}
454456
if (requestConfig.containsKey(ClientConfigProperties.QUERY_ID.getKey())) {
455457
addHeader(
456458
req,
457459
ClickHouseHttpProto.HEADER_QUERY_ID,
458-
requestConfig.get(ClientConfigProperties.QUERY_ID.getKey()));
460+
(String) requestConfig.get(ClientConfigProperties.QUERY_ID.getKey()));
459461
}
460462
addHeader(
461463
req,
@@ -757,21 +759,25 @@ public void close() {
757759
}
758760

759761
private static <T> void addHeader(HttpRequest req, String headerName,
760-
T value)
762+
String value)
761763
{
762764
if (value == null) {
763765
return;
764766
}
765-
String tString = value.toString();
766-
if (tString.isBlank()) {
767+
768+
if (value.trim().isEmpty()) {
767769
return;
768770
}
769-
if (PATTERN_HEADER_VALUE_ASCII.matcher(tString).matches()) {
770-
req.addHeader(headerName, tString);
771+
if (PATTERN_HEADER_VALUE_ASCII.matcher(value).matches()) {
772+
req.addHeader(headerName, value);
771773
} else {
772-
req.addHeader(
773-
headerName + "*",
774-
"UTF-8''" + URLEncoder.encode(tString, StandardCharsets.UTF_8));
774+
try {
775+
req.addHeader(
776+
headerName + "*",
777+
"UTF-8''" + URLEncoder.encode(value, StandardCharsets.UTF_8.name()));
778+
} catch (UnsupportedEncodingException e) {
779+
throw new ClientException("Failed to convert string to UTF8" , e);
780+
}
775781
}
776782
}
777783

0 commit comments

Comments
 (0)