Skip to content

Commit 0418232

Browse files
committed
Merge branch 'main' into v2_jwt_auth
2 parents 8353689 + 14e0b54 commit 0418232

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1789
-738
lines changed

clickhouse-jdbc/pom.xml

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,15 @@
4040
<groupId>${project.parent.groupId}</groupId>
4141
<artifactId>clickhouse-http-client</artifactId>
4242
<version>${revision}</version>
43-
<optional>true</optional>
4443
</dependency>
4544
<dependency>
4645
<groupId>org.apache.commons</groupId>
4746
<artifactId>commons-compress</artifactId>
48-
<optional>true</optional>
4947
</dependency>
5048

5149
<dependency>
5250
<groupId>org.lz4</groupId>
5351
<artifactId>lz4-pure-java</artifactId>
54-
<optional>true</optional>
5552
</dependency>
5653
<dependency>
5754
<groupId>com.google.code.gson</groupId>
@@ -100,7 +97,13 @@
10097
<artifactId>zstd-jni</artifactId>
10198
<scope>provided</scope>
10299
</dependency>
100+
<dependency>
101+
<groupId>org.slf4j</groupId>
102+
<artifactId>slf4j-api</artifactId>
103+
<version>${slf4j.version}</version>
104+
</dependency>
103105

106+
<!-- Test Dependencies -->
104107
<dependency>
105108
<groupId>${project.parent.groupId}</groupId>
106109
<artifactId>clickhouse-client</artifactId>
@@ -530,6 +533,76 @@
530533
</filters>
531534
</configuration>
532535
</execution>
536+
537+
538+
<execution>
539+
<id>shade-all-v2</id>
540+
<phase>package</phase>
541+
<goals>
542+
<goal>shade</goal>
543+
</goals>
544+
<configuration>
545+
<shadedArtifactAttached>true</shadedArtifactAttached>
546+
<createDependencyReducedPom>true</createDependencyReducedPom>
547+
<createSourcesJar>true</createSourcesJar>
548+
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
549+
<shadedClassifierName>shaded-all</shadedClassifierName>
550+
<relocations>
551+
<relocation>
552+
<pattern>com.google</pattern>
553+
<shadedPattern>${shade.base}.google</shadedPattern>
554+
</relocation>
555+
<relocation>
556+
<pattern>io.opencensus</pattern>
557+
<shadedPattern>${shade.base}.opencensus</shadedPattern>
558+
</relocation>
559+
<relocation>
560+
<pattern>io.perfmark</pattern>
561+
<shadedPattern>${shade.base}.perfmark</shadedPattern>
562+
</relocation>
563+
<relocation>
564+
<pattern>net.jpountz</pattern>
565+
<shadedPattern>${shade.base}.jpountz</shadedPattern>
566+
</relocation>
567+
<relocation>
568+
<pattern>okio</pattern>
569+
<shadedPattern>${shade.base}.okio</shadedPattern>
570+
</relocation>
571+
<relocation>
572+
<pattern>org.apache</pattern>
573+
<shadedPattern>${shade.base}.apache</shadedPattern>
574+
</relocation>
575+
</relocations>
576+
<transformers>
577+
<transformer
578+
implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer" />
579+
<transformer
580+
implementation="org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer" />
581+
<transformer
582+
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
583+
<transformer
584+
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
585+
<manifestEntries>
586+
<Automatic-Module-Name>${project.groupId}.jdbc</Automatic-Module-Name>
587+
<Main-Class>${mainClass}</Main-Class>
588+
<Specification-Title>${spec.title}</Specification-Title>
589+
<Specification-Version>${spec.version}</Specification-Version>
590+
</manifestEntries>
591+
</transformer>
592+
</transformers>
593+
<filters>
594+
<filter>
595+
<artifact>*:*</artifact>
596+
<excludes>
597+
<exclude>google/**</exclude>
598+
<exclude>org/checkerframework/**</exclude>
599+
<exclude>org/codehaus/**</exclude>
600+
<exclude>**/module-info.class</exclude>
601+
</excludes>
602+
</filter>
603+
</filters>
604+
</configuration>
605+
</execution>
533606
</executions>
534607
</plugin>
535608
<plugin>

client-v2/pom.xml

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
<properties>
2020
<apache.httpclient.version>5.3.1</apache.httpclient.version>
21+
<shade.base>${project.groupId}.shaded</shade.base>
2122
</properties>
2223

2324
<dependencies>
@@ -157,29 +158,54 @@
157158
<artifactId>maven-shade-plugin</artifactId>
158159
<executions>
159160
<execution>
160-
<id>shade</id>
161+
<id>shade-all</id>
161162
<phase>package</phase>
162163
<goals>
163164
<goal>shade</goal>
164165
</goals>
165166
<configuration>
166167
<shadedArtifactAttached>true</shadedArtifactAttached>
167-
<shadedClassifierName>shaded</shadedClassifierName>
168+
<shadedClassifierName>all</shadedClassifierName>
168169
<createDependencyReducedPom>true</createDependencyReducedPom>
169170
<createSourcesJar>true</createSourcesJar>
170171
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
171-
<artifactSet>
172-
<includes>
173-
<include>com.clickhouse:clickhouse-data</include>
174-
<include>com.clickhouse:clickhouse-client</include>
175-
<include>org.lz4:lz4-pure-java</include>
176-
</includes>
177-
</artifactSet>
178172
<relocations>
179173
<relocation>
174+
<pattern>org.slf4j</pattern>
175+
<shadedPattern>${shade.base}.org.slf4j</shadedPattern>
176+
</relocation>
177+
178+
<relocation>
179+
<pattern>org.apache</pattern>
180+
<shadedPattern>${shade.base}.org.apache</shadedPattern>
181+
</relocation>
182+
183+
<relocation>
184+
<!-- lz4 -->
180185
<pattern>net.jpountz</pattern>
181-
<shadedPattern>${shade.base}.jpountz</shadedPattern>
186+
<shadedPattern>${shade.base}.net.jpountz.lz4</shadedPattern>
187+
</relocation>
188+
189+
<relocation>
190+
<pattern>org.ow2</pattern>
191+
<shadedPattern>${shade.base}.org.ow2</shadedPattern>
192+
</relocation>
193+
194+
<relocation>
195+
<pattern>com.fasterxml</pattern>
196+
<shadedPattern>${shade.base}.com.fasterxml</shadedPattern>
197+
</relocation>
198+
199+
<relocation>
200+
<pattern>org.roaringbitmap</pattern>
201+
<shadedPattern>${shade.base}.org.roaringbitmap</shadedPattern>
182202
</relocation>
203+
204+
<relocation>
205+
<pattern>org.objectweb</pattern>
206+
<shadedPattern>${shade.base}.org.objectweb</shadedPattern>
207+
</relocation>
208+
183209
</relocations>
184210
<transformers>
185211
<transformer
@@ -199,6 +225,7 @@
199225
</filters>
200226
</configuration>
201227
</execution>
228+
202229
</executions>
203230
</plugin>
204231
<plugin>

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ public void close() {
210210
if (oldClient != null) {
211211
oldClient.close();
212212
}
213+
214+
if (httpClientHelper != null) {
215+
httpClientHelper.close();
216+
}
213217
}
214218

215219
public static class Builder {
@@ -293,7 +297,7 @@ public Builder addEndpoint(String endpoint) {
293297
throw new IllegalArgumentException("Only HTTP and HTTPS protocols are supported");
294298
}
295299
} catch (java.net.MalformedURLException e) {
296-
throw new IllegalArgumentException("Endpoint should be a valid URL string", e);
300+
throw new IllegalArgumentException("Endpoint should be a valid URL string, but was " + endpoint, e);
297301
}
298302
return this;
299303
}
@@ -943,6 +947,16 @@ public Builder setClientName(String clientName) {
943947
return this;
944948
}
945949

950+
/**
951+
* Sets client options from provided map. Values are copied as is
952+
* @param options - map of client options
953+
* @return same instance of the builder
954+
*/
955+
public Builder setOptions(Map<String, String> options) {
956+
this.configuration.putAll(options);
957+
return this;
958+
}
959+
946960
/**
947961
* Specifies whether to use Bearer Authentication and what token to use.
948962
* The token will be sent as is, so it should be encoded before passing to this method.
@@ -1545,7 +1559,7 @@ public CompletableFuture<InsertResponse> insert(String tableName,
15451559

15461560
byte[] buffer = new byte[writeBufferSize];
15471561
int bytesRead;
1548-
while ((bytesRead = data.read(buffer)) != -1) {
1562+
while ((bytesRead = data.read(buffer)) > 0) {
15491563
out.write(buffer, 0, bytesRead);
15501564
}
15511565
out.close();
@@ -2149,6 +2163,10 @@ public Set<String> getEndpoints() {
21492163
return Collections.unmodifiableSet(endpoints);
21502164
}
21512165

2166+
public String getUser() {
2167+
return this.configuration.get(ClientConfigProperties.USER.getKey());
2168+
}
2169+
21522170
/**
21532171
* Sets list of DB roles that should be applied to each query.
21542172
*

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ public enum ClientConfigProperties {
1717

1818
HTTP_USE_BASIC_AUTH("http_use_basic_auth"),
1919

20-
USER("user"),
20+
USER("user", "default"),
2121

22-
PASSWORD("password"),
22+
PASSWORD("password", ""),
2323

2424
/**
2525
* Maximum number of active connection in internal connection pool.
2626
*/
27-
HTTP_MAX_OPEN_CONNECTIONS("max_open_connections"),
27+
HTTP_MAX_OPEN_CONNECTIONS("max_open_connections", "10"),
2828

2929
/**
3030
* HTTP keep-alive timeout override.
@@ -59,7 +59,7 @@ public enum ClientConfigProperties {
5959

6060
SOCKET_LINGER_OPT("socket_linger"),
6161

62-
DATABASE("database"),
62+
DATABASE("database", "default"),
6363

6464
COMPRESS_SERVER_RESPONSE("compress"), // actually a server setting, but has client effect too
6565

@@ -118,14 +118,37 @@ public enum ClientConfigProperties {
118118

119119
private String key;
120120

121+
private String defaultValue;
122+
123+
private List<String> choices;
124+
125+
121126
ClientConfigProperties(String key) {
127+
this(key, null, Collections.emptyList());
128+
}
129+
130+
ClientConfigProperties(String key, String defaultValue) {
131+
this(key, defaultValue, Collections.emptyList());
132+
}
133+
134+
ClientConfigProperties(String key, String defaultValue, List<String> choices) {
122135
this.key = key;
136+
this.defaultValue = defaultValue;
137+
this.choices = Collections.unmodifiableList(choices);
123138
}
124139

125140
public String getKey() {
126141
return key;
127142
}
128143

144+
public List<String> getChoices() {
145+
return choices;
146+
}
147+
148+
public String getDefaultValue() {
149+
return defaultValue;
150+
}
151+
129152
public static final String HTTP_HEADER_PREFIX = "http_header_";
130153

131154
public static final String SERVER_SETTING_PREFIX = "clickhouse_setting_";

client-v2/src/main/java/com/clickhouse/client/api/data_formats/ClickHouseBinaryFormatReader.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,13 @@ public interface ClickHouseBinaryFormatReader extends AutoCloseable {
281281
*/
282282
double[] getDoubleArray(String colName);
283283

284+
/**
285+
*
286+
* @param colName
287+
* @return
288+
*/
289+
boolean[] getBooleanArray(String colName);
290+
284291
/**
285292
* Reads column with name `colName` as a string.
286293
*
@@ -503,6 +510,8 @@ public interface ClickHouseBinaryFormatReader extends AutoCloseable {
503510
*/
504511
double[] getDoubleArray(int index);
505512

513+
boolean[] getBooleanArray(int index);
514+
506515
Object[] getTuple(int index);
507516

508517
Object[] getTuple(String colName);

client-v2/src/main/java/com/clickhouse/client/api/data_formats/NativeFormatReader.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.clickhouse.client.api.data_formats.internal.BinaryStreamReader;
55
import com.clickhouse.client.api.query.QuerySettings;
66
import com.clickhouse.data.ClickHouseColumn;
7+
import com.clickhouse.data.ClickHouseDataType;
78

89
import java.io.EOFException;
910
import java.io.IOException;
@@ -58,13 +59,24 @@ private boolean readBlock() throws IOException {
5859
for (int i = 0; i < nColumns; i++) {
5960
ClickHouseColumn column = ClickHouseColumn.of(BinaryStreamReader.readString(input),
6061
BinaryStreamReader.readString(input));
62+
6163
names.add(column.getColumnName());
6264
types.add(column.getDataType().name());
6365

6466
List<Object> values = new ArrayList<>(nRows);
65-
for (int j = 0; j < nRows; j++) {
66-
Object value = binaryStreamReader.readValue(column);
67-
values.add(value);
67+
if (column.isArray()) {
68+
int[] sizes = new int[nRows];
69+
for (int j = 0; j < nRows; j++) {
70+
sizes[j] = Math.toIntExact(binaryStreamReader.readLongLE());
71+
}
72+
for (int j = 0; j < nRows; j++) {
73+
values.add(binaryStreamReader.readArrayItem(column.getNestedColumns().get(0), sizes[0]));
74+
}
75+
} else {
76+
for (int j = 0; j < nRows; j++) {
77+
Object value = binaryStreamReader.readValue(column);
78+
values.add(value);
79+
}
6880
}
6981
currentBlock.add(values);
7082
}

0 commit comments

Comments
 (0)