Skip to content

Commit bbb9742

Browse files
authored
Merge pull request #1707 from ClickHouse/feat_draft_transport_skeleton
[client-v2] New http implementation
2 parents f499762 + 599ccd2 commit bbb9742

File tree

19 files changed

+614
-131
lines changed

19 files changed

+614
-131
lines changed

clickhouse-http-client/src/main/java/com/clickhouse/client/http/ApacheHttpConnectionImpl.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,23 +113,22 @@ private ClickHouseHttpResponse buildResponse(ClickHouseConfig config, CloseableH
113113
// X-ClickHouse-Timezone: UTC
114114
// X-ClickHouse-Summary:
115115
// {"read_rows":"0","read_bytes":"0","written_rows":"0","written_bytes":"0","total_rows_to_read":"0"}
116-
String displayName = getResponseHeader(response, "X-ClickHouse-Server-Display-Name", server.getHost());
117-
String queryId = getResponseHeader(response, "X-ClickHouse-Query-Id", "");
118-
Header hSum = response.getLastHeader("X-ClickHouse-Summary");
119-
String summary = hSum == null ? "{}" : hSum.getValue(); // getResponseHeader(response, "X-ClickHouse-Summary", "{}");
116+
String displayName = getResponseHeader(response, ClickHouseHttpProto.HEADER_SRV_DISPLAY_NAME, server.getHost());
117+
String queryId = getResponseHeader(response, ClickHouseHttpProto.HEADER_QUERY_ID, "");
118+
String summary= getResponseHeader(response, ClickHouseHttpProto.HEADER_SRV_SUMMARY, "{}");
120119

121120
ClickHouseFormat format = config.getFormat();
122121
TimeZone timeZone = config.getServerTimeZone();
123122
boolean hasCustomOutput = output != null && output.getUnderlyingStream().hasOutput();
124123
boolean hasQueryResult = false;
125124
// queryId, format and timeZone are only available for queries
126125
if (!ClickHouseChecker.isNullOrEmpty(queryId)) {
127-
String value = getResponseHeader(response, "X-ClickHouse-Format", "");
126+
String value = getResponseHeader(response, ClickHouseHttpProto.HEADER_FORMAT, "");
128127
if (!ClickHouseChecker.isNullOrEmpty(value)) {
129128
format = ClickHouseFormat.valueOf(value);
130129
hasQueryResult = true;
131130
}
132-
value = getResponseHeader(response, "X-ClickHouse-Timezone", "");
131+
value = getResponseHeader(response, ClickHouseHttpProto.HEADER_TIMEZONE, "");
133132
timeZone = !ClickHouseChecker.isNullOrEmpty(value) ? TimeZone.getTimeZone(value)
134133
: timeZone;
135134
}
@@ -179,8 +178,8 @@ private void checkResponse(ClickHouseConfig config, CloseableHttpResponse respon
179178
return;
180179
}
181180

182-
final Header errorCode = response.getFirstHeader("X-ClickHouse-Exception-Code");
183-
final Header serverName = response.getFirstHeader("X-ClickHouse-Server-Display-Name");
181+
final Header errorCode = response.getFirstHeader(ClickHouseHttpProto.HEADER_EXCEPTION_CODE);
182+
final Header serverName = response.getFirstHeader(ClickHouseHttpProto.HEADER_SRV_DISPLAY_NAME);
184183
if (response.getEntity() == null) {
185184
throw new ConnectException(
186185
ClickHouseUtils.format("HTTP response %d %s(code %s returned from server %s)",
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.clickhouse.client.http;
2+
3+
public class ClickHouseHttpProto {
4+
5+
public static final String HEADER_SRV_DISPLAY_NAME = "X-ClickHouse-Server-Display-Name";
6+
7+
public static final String HEADER_QUERY_ID = "X-ClickHouse-Query-Id";
8+
9+
public static final String HEADER_SRV_SUMMARY = "X-ClickHouse-Summary";
10+
11+
public static final String HEADER_FORMAT = "X-ClickHouse-Format";
12+
13+
public static final String HEADER_TIMEZONE = "X-ClickHouse-Timezone";
14+
15+
public static final String HEADER_EXCEPTION_CODE = "X-ClickHouse-Exception-Code";
16+
17+
public static final String QPARAM_QUERY_ID = "query_id";
18+
19+
}

client-v2/pom.xml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@
4242
<artifactId>httpcore5</artifactId>
4343
<version>${apache.httpclient.version}</version>
4444
</dependency>
45-
<dependency>
46-
<groupId>org.apache.httpcomponents.core5</groupId>
47-
<artifactId>httpcore5-h2</artifactId>
48-
<version>${apache.httpclient.version}</version>
49-
</dependency>
5045
<dependency>
5146
<groupId>com.github.luben</groupId>
5247
<artifactId>zstd-jni</artifactId>
@@ -57,6 +52,14 @@
5752
<artifactId>lz4-pure-java</artifactId>
5853
<optional>true</optional>
5954
</dependency>
55+
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
56+
<dependency>
57+
<groupId>com.fasterxml.jackson.core</groupId>
58+
<artifactId>jackson-core</artifactId>
59+
<version>2.17.2</version>
60+
</dependency>
61+
62+
<!-- Test Dependencies -->
6063
<dependency>
6164
<groupId>com.google.code.gson</groupId>
6265
<artifactId>gson</artifactId>
@@ -68,7 +71,7 @@
6871
<groupId>com.fasterxml.jackson.core</groupId>
6972
<artifactId>jackson-databind</artifactId>
7073
<scope>test</scope>
71-
<version>2.17.0</version>
74+
<version>2.17.2</version>
7275
</dependency>
7376
<dependency>
7477
<groupId>org.apache.commons</groupId>

0 commit comments

Comments
 (0)