Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ public CompletableFuture<InsertResponse> insert(String tableName, List<?> data,
Integer retry = (Integer) configuration.get(ClientConfigProperties.RETRY_ON_FAILURE.getKey());
final int maxRetries = retry == null ? 0 : retry;

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

settings.setOption(ClientConfigProperties.INPUT_OUTPUT_FORMAT.getKey(), format.name());
settings.setOption(ClientConfigProperties.INPUT_OUTPUT_FORMAT.getKey(), format);
final InsertSettings finalSettings = new InsertSettings(buildRequestSettings(settings.getAllSettings()));

StringBuilder sqlStmt = new StringBuilder("INSERT INTO ").append(tableName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.clickhouse.client.api.enums.ProxyType;
import com.clickhouse.client.api.http.ClickHouseHttpProto;
import com.clickhouse.client.api.transport.Endpoint;
import com.clickhouse.data.ClickHouseFormat;
import net.jpountz.lz4.LZ4Factory;
import org.apache.hc.client5.http.ConnectTimeoutException;
import org.apache.hc.client5.http.classic.methods.HttpPost;
Expand Down Expand Up @@ -64,6 +65,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.net.ConnectException;
import java.net.InetSocketAddress;
Expand Down Expand Up @@ -449,13 +451,13 @@ private void addHeaders(HttpPost req, Map<String, Object> requestConfig) {
addHeader(
req,
ClickHouseHttpProto.HEADER_FORMAT,
requestConfig.get(ClientConfigProperties.INPUT_OUTPUT_FORMAT.getKey()));
((ClickHouseFormat) requestConfig.get(ClientConfigProperties.INPUT_OUTPUT_FORMAT.getKey())).name());
}
if (requestConfig.containsKey(ClientConfigProperties.QUERY_ID.getKey())) {
addHeader(
req,
ClickHouseHttpProto.HEADER_QUERY_ID,
requestConfig.get(ClientConfigProperties.QUERY_ID.getKey()));
(String) requestConfig.get(ClientConfigProperties.QUERY_ID.getKey()));
}
addHeader(
req,
Expand Down Expand Up @@ -757,21 +759,25 @@ public void close() {
}

private static <T> void addHeader(HttpRequest req, String headerName,
T value)
String value)
{
if (value == null) {
return;
}
String tString = value.toString();
if (tString.isBlank()) {

if (value.trim().isEmpty()) {
return;
}
if (PATTERN_HEADER_VALUE_ASCII.matcher(tString).matches()) {
req.addHeader(headerName, tString);
if (PATTERN_HEADER_VALUE_ASCII.matcher(value).matches()) {
req.addHeader(headerName, value);
} else {
req.addHeader(
headerName + "*",
"UTF-8''" + URLEncoder.encode(tString, StandardCharsets.UTF_8));
try {
req.addHeader(
headerName + "*",
"UTF-8''" + URLEncoder.encode(value, StandardCharsets.UTF_8.name()));
} catch (UnsupportedEncodingException e) {
throw new ClientException("Failed to convert string to UTF8" , e);
}
}
}

Expand Down
Loading