Skip to content

Commit cf863d4

Browse files
committed
Merge branch 'main' into jdbc_fix_cte_parse
2 parents 6372e4e + 67e8a2b commit cf863d4

File tree

22 files changed

+693
-119
lines changed

22 files changed

+693
-119
lines changed

clickhouse-data/src/main/java/com/clickhouse/data/ClickHouseDataType.java

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
package com.clickhouse.data;
22

3+
import com.clickhouse.data.value.ClickHouseGeoMultiPolygonValue;
4+
import com.clickhouse.data.value.ClickHouseGeoPointValue;
5+
import com.clickhouse.data.value.ClickHouseGeoPolygonValue;
6+
import com.clickhouse.data.value.ClickHouseGeoRingValue;
7+
import com.clickhouse.data.value.UnsignedByte;
8+
import com.clickhouse.data.value.UnsignedInteger;
9+
import com.clickhouse.data.value.UnsignedLong;
10+
import com.clickhouse.data.value.UnsignedShort;
11+
312
import java.math.BigDecimal;
413
import java.math.BigInteger;
514
import java.net.Inet4Address;
@@ -9,7 +18,6 @@
918
import java.time.Instant;
1019
import java.time.LocalDate;
1120
import java.time.LocalDateTime;
12-
import java.time.LocalTime;
1321
import java.time.Period;
1422
import java.time.ZonedDateTime;
1523
import java.time.temporal.ChronoUnit;
@@ -29,15 +37,6 @@
2937
import java.util.UUID;
3038
import java.util.stream.Collectors;
3139

32-
import com.clickhouse.data.value.ClickHouseGeoMultiPolygonValue;
33-
import com.clickhouse.data.value.ClickHouseGeoPointValue;
34-
import com.clickhouse.data.value.ClickHouseGeoPolygonValue;
35-
import com.clickhouse.data.value.ClickHouseGeoRingValue;
36-
import com.clickhouse.data.value.UnsignedByte;
37-
import com.clickhouse.data.value.UnsignedInteger;
38-
import com.clickhouse.data.value.UnsignedLong;
39-
import com.clickhouse.data.value.UnsignedShort;
40-
4140
/**
4241
* Basic ClickHouse data types.
4342
*
@@ -101,12 +100,12 @@ public enum ClickHouseDataType implements SQLType {
101100
IPv4(Inet4Address.class, false, true, false, 4, 10, 0, 0, 0, false, 0x28, "INET4"),
102101
IPv6(Inet6Address.class, false, true, false, 16, 39, 0, 0, 0, false, 0x29, "INET6"),
103102
UUID(UUID.class, false, true, false, 16, 69, 0, 0, 0, false, 0x1D),
104-
Point(Object.class, false, true, true, 33, 0, 0, 0, 0, true, 0x2C), // same as Tuple(Float64, Float64)
105-
Polygon(Object.class, false, true, true, 0, 0, 0, 0, 0, true, 0x2C), // same as Array(Ring)
106-
MultiPolygon(Object.class, false, true, true, 0, 0, 0, 0, 0, true, 0x2C), // same as Array(Polygon)
107-
Ring(Object.class, false, true, true, 0, 0, 0, 0, 0, true, 0x2C), // same as Array(Point)
108-
LineString( Object.class, false, true, true, 0, 0, 0, 0, 0, true, 0x2C), // same as Array(Point)
109-
MultiLineString(Object.class, false, true, true, 0, 0, 0, 0, 0, true, 0x2C), // same as Array(Ring)
103+
Point(Object.class, false, true, true, 33, 0, 0, 0, 0, true), // same as Tuple(Float64, Float64)
104+
Polygon(Object.class, false, true, true, 0, 0, 0, 0, 0, true), // same as Array(Ring)
105+
MultiPolygon(Object.class, false, true, true, 0, 0, 0, 0, 0, true), // same as Array(Polygon)
106+
Ring(Object.class, false, true, true, 0, 0, 0, 0, 0, true), // same as Array(Point)
107+
LineString( Object.class, false, true, true, 0, 0, 0, 0, 0, true), // same as Array(Point)
108+
MultiLineString(Object.class, false, true, true, 0, 0, 0, 0, 0, true), // same as Array(Ring)
110109

111110
JSON(Object.class, false, false, false, 0, 0, 0, 0, 0, true, 0x30),
112111
@Deprecated
@@ -372,11 +371,11 @@ public byte getTag() {
372371
allAliases = Collections.unmodifiableSet(set);
373372
name2type = Collections.unmodifiableMap(map);
374373

375-
Map<Byte, ClickHouseDataType> tmpbinTag2Type = new HashMap<>();
374+
Map<Byte, ClickHouseDataType> tmpBinTag2Type = new HashMap<>();
376375
for (ClickHouseDataType type : ClickHouseDataType.values()) {
377-
tmpbinTag2Type.put((byte) type.getBinTag(), type);
376+
tmpBinTag2Type.put(type.getBinTag(), type);
378377
}
379-
binTag2Type = Collections.unmodifiableMap(tmpbinTag2Type);
378+
binTag2Type = Collections.unmodifiableMap(tmpBinTag2Type);
380379

381380
Map<Byte, ClickHouseDataType> tmpIntervalKind2Type = new HashMap<>();
382381
Map<ClickHouseDataType, ClickHouseDataType.IntervalKind > tmpIntervalType2Kind = new HashMap<>();

client-v2/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
<groupId>com.fasterxml.jackson.core</groupId>
9090
<artifactId>jackson-databind</artifactId>
9191
<scope>test</scope>
92-
<version>2.17.2</version>
92+
<version>${jackson.version}</version>
9393
</dependency>
9494
<dependency>
9595
<groupId>${project.parent.groupId}</groupId>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,7 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec
16051605
if (httpResponse.getCode() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
16061606
LOG.warn("Failed to get response. Server returned {}. Retrying. (Duration: {})", System.nanoTime() - startTime, httpResponse.getCode());
16071607
selectedEndpoint = getNextAliveNode();
1608+
HttpAPIClientHelper.closeQuietly(httpResponse);
16081609
continue;
16091610
}
16101611

@@ -1625,7 +1626,7 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec
16251626
return new QueryResponse(httpResponse, responseFormat, requestSettings, metrics);
16261627

16271628
} catch (Exception e) {
1628-
httpClientHelper.closeQuietly(httpResponse);
1629+
HttpAPIClientHelper.closeQuietly(httpResponse);
16291630
lastException = httpClientHelper.wrapException(String.format("Query request failed (Attempt: %s/%s - Duration: %s)",
16301631
(i + 1), (retries + 1), System.nanoTime() - startTime), e);
16311632
if (httpClientHelper.shouldRetry(e, requestSettings.getAllSettings())) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public enum ClientConfigProperties {
7575

7676
SOCKET_TCP_NO_DELAY_OPT("socket_tcp_nodelay", Boolean.class),
7777

78-
SOCKET_LINGER_OPT("socket_linger", Boolean.class),
78+
SOCKET_LINGER_OPT("socket_linger", Integer.class),
7979

8080
DATABASE("database", String.class, "default"),
8181

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,20 @@ public interface ClickHouseBinaryFormatReader extends AutoCloseable {
293293
*/
294294
boolean[] getBooleanArray(String colName);
295295

296+
/**
297+
*
298+
* @param colName
299+
* @return
300+
*/
301+
short[] getShortArray(String colName);
302+
303+
/**
304+
*
305+
* @param colName
306+
* @return
307+
*/
308+
String[] getStringArray(String colName);
309+
296310
/**
297311
* Reads column with name `colName` as a string.
298312
*
@@ -517,6 +531,10 @@ public interface ClickHouseBinaryFormatReader extends AutoCloseable {
517531

518532
boolean[] getBooleanArray(int index);
519533

534+
short [] getShortArray(int index);
535+
536+
String[] getStringArray(int index);
537+
520538
Object[] getTuple(int index);
521539

522540
Object[] getTuple(String colName);

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,32 @@ public boolean[] getBooleanArray(String colName) {
588588
}
589589
}
590590

591+
@Override
592+
public short[] getShortArray(String colName) {
593+
try {
594+
return getPrimitiveArray(colName, short.class);
595+
} catch (ClassCastException | IllegalArgumentException e) {
596+
throw new ClientException("Value cannot be converted to an array of primitives", e);
597+
}
598+
}
599+
600+
@Override
601+
public String[] getStringArray(String colName) {
602+
Object value = readValue(colName);
603+
if (value instanceof BinaryStreamReader.ArrayValue) {
604+
BinaryStreamReader.ArrayValue array = (BinaryStreamReader.ArrayValue) value;
605+
int length = array.length;
606+
if (!array.itemType.equals(String.class))
607+
throw new ClientException("Not A String type.");
608+
String [] values = new String[length];
609+
for (int i = 0; i < length; i++) {
610+
values[i] = (String)((BinaryStreamReader.ArrayValue) value).get(i);
611+
}
612+
return values;
613+
}
614+
throw new ClientException("Not ArrayValue type.");
615+
}
616+
591617
@Override
592618
public boolean hasValue(int colIndex) {
593619
return currentRecord[colIndex - 1] != null;
@@ -733,6 +759,16 @@ public boolean[] getBooleanArray(int index) {
733759
return getBooleanArray(schema.columnIndexToName(index));
734760
}
735761

762+
@Override
763+
public short[] getShortArray(int index) {
764+
return getShortArray(schema.columnIndexToName(index));
765+
}
766+
767+
@Override
768+
public String[] getStringArray(int index) {
769+
return getStringArray(schema.columnIndexToName(index));
770+
}
771+
736772
@Override
737773
public Object[] getTuple(int index) {
738774
return readValue(index);

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@ public boolean[] getBooleanArray(String colName) {
165165
return reader.getBooleanArray(colName);
166166
}
167167

168+
@Override
169+
public short[] getShortArray(String colName) {
170+
return reader.getShortArray(colName);
171+
}
172+
173+
@Override
174+
public String[] getStringArray(String colName) {
175+
return reader.getStringArray(colName);
176+
}
177+
168178
@Override
169179
public String getString(int index) {
170180
return reader.getString(index);
@@ -315,6 +325,16 @@ public boolean[] getBooleanArray(int index) {
315325
return reader.getBooleanArray(index);
316326
}
317327

328+
@Override
329+
public short[] getShortArray(int index) {
330+
return reader.getShortArray(index);
331+
}
332+
333+
@Override
334+
public String[] getStringArray(int index) {
335+
return reader.getStringArray(index);
336+
}
337+
318338
@Override
319339
public Object[] getTuple(int index) {
320340
return reader.getTuple(index);

0 commit comments

Comments
 (0)