Skip to content

Commit da03749

Browse files
committed
Merge branch 'main' into v2_jwt_auth
2 parents cb4c32d + 19172f6 commit da03749

File tree

20 files changed

+865
-318
lines changed

20 files changed

+865
-318
lines changed

.github/pull_request_template.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
## Checklist
55
Delete items not relevant to your PR:
6+
- [ ] Closes issue <!-- Link to an issue to close on merge. -->
67
- [ ] Unit and integration tests covering the common scenarios were added
78
- [ ] A human-readable description of the changes was provided to include in CHANGELOG
89
- [ ] For significant changes, documentation in https://github.com/ClickHouse/clickhouse-docs was updated with further explanations or tutorials

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
### New Features
44
- Added basic auth support for proxies. Now you can specify username/password when connecting via a proxy that requires it with HttpURLConnection and Apache HttpClient.
55

6+
### Bug Fixes
7+
- Fix for retrying on `ConnectTimeoutException`
8+
69
## 0.7.1-patch1
710

811
### Bug Fixes

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import java.io.InputStream;
6464
import java.lang.reflect.InvocationTargetException;
6565
import java.lang.reflect.Method;
66+
import java.net.ConnectException;
6667
import java.net.URL;
6768
import java.nio.charset.StandardCharsets;
6869
import java.time.Duration;
@@ -1426,7 +1427,7 @@ public CompletableFuture<InsertResponse> insert(String tableName, List<?> data,
14261427
metrics.operationComplete();
14271428
metrics.setQueryId(queryId);
14281429
return new InsertResponse(metrics);
1429-
} catch ( NoHttpResponseException | ConnectionRequestTimeoutException | ConnectTimeoutException e) {
1430+
} catch (NoHttpResponseException | ConnectionRequestTimeoutException | ConnectTimeoutException | ConnectException e) {
14301431
lastException = httpClientHelper.wrapException("Insert request initiation failed", e);
14311432
if (httpClientHelper.shouldRetry(e, finalSettings.getAllSettings())) {
14321433
LOG.warn("Retrying", e);
@@ -1554,7 +1555,7 @@ public CompletableFuture<InsertResponse> insert(String tableName,
15541555
metrics.operationComplete();
15551556
metrics.setQueryId(queryId);
15561557
return new InsertResponse(metrics);
1557-
} catch ( NoHttpResponseException | ConnectionRequestTimeoutException | ConnectTimeoutException e) {
1558+
} catch (NoHttpResponseException | ConnectionRequestTimeoutException | ConnectTimeoutException | ConnectException e) {
15581559
lastException = httpClientHelper.wrapException("Insert request initiation failed", e);
15591560
if (httpClientHelper.shouldRetry(e, finalSettings.getAllSettings())) {
15601561
LOG.warn("Retrying", e);
@@ -1720,7 +1721,7 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec
17201721

17211722
return new QueryResponse(httpResponse, finalSettings.getFormat(), finalSettings, metrics);
17221723

1723-
} catch ( NoHttpResponseException | ConnectionRequestTimeoutException | ConnectTimeoutException e) {
1724+
} catch (NoHttpResponseException | ConnectionRequestTimeoutException | ConnectTimeoutException | ConnectException e) {
17241725
lastException = httpClientHelper.wrapException("Query request initiation failed", e);
17251726
if (httpClientHelper.shouldRetry(e, finalSettings.getAllSettings())) {
17261727
LOG.warn("Retrying.", e);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private boolean readBlock() throws IOException {
8686

8787
@Override
8888
public <T> T readValue(int colIndex) {
89-
return (T) currentRecord.get(getSchema().indexToName(colIndex));
89+
return (T) currentRecord.get(getSchema().columnIndexToName(colIndex));
9090
}
9191

9292
@Override

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

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ public <T> T readValue(int colIndex) {
155155
if (colIndex < 1 || colIndex > getSchema().getColumns().size()) {
156156
throw new ClientException("Column index out of bounds: " + colIndex);
157157
}
158-
colIndex = colIndex - 1;
159-
return (T) currentRecord.get(getSchema().indexToName(colIndex));
158+
return (T) currentRecord.get(getSchema().columnIndexToName(colIndex));
160159
}
161160

162161
@Override
@@ -514,7 +513,7 @@ public boolean[] getBooleanArray(String colName) {
514513

515514
@Override
516515
public boolean hasValue(int colIndex) {
517-
return currentRecord.containsKey(getSchema().indexToName(colIndex - 1));
516+
return currentRecord.containsKey(getSchema().columnIndexToName(colIndex));
518517
}
519518

520519
@Override
@@ -525,47 +524,47 @@ public boolean hasValue(String colName) {
525524

526525
@Override
527526
public byte getByte(int index) {
528-
return getByte(schema.indexToName(index - 1 ));
527+
return getByte(schema.columnIndexToName(index));
529528
}
530529

531530
@Override
532531
public short getShort(int index) {
533-
return getShort(schema.indexToName(index - 1));
532+
return getShort(schema.columnIndexToName(index));
534533
}
535534

536535
@Override
537536
public int getInteger(int index) {
538-
return getInteger(schema.indexToName(index - 1));
537+
return getInteger(schema.columnIndexToName(index));
539538
}
540539

541540
@Override
542541
public long getLong(int index) {
543-
return getLong(schema.indexToName(index - 1));
542+
return getLong(schema.columnIndexToName(index));
544543
}
545544

546545
@Override
547546
public float getFloat(int index) {
548-
return getFloat(schema.indexToName(index - 1));
547+
return getFloat(schema.columnIndexToName(index));
549548
}
550549

551550
@Override
552551
public double getDouble(int index) {
553-
return getDouble(schema.indexToName(index - 1));
552+
return getDouble(schema.columnIndexToName(index));
554553
}
555554

556555
@Override
557556
public boolean getBoolean(int index) {
558-
return getBoolean(schema.indexToName(index - 1));
557+
return getBoolean(schema.columnIndexToName(index));
559558
}
560559

561560
@Override
562561
public BigInteger getBigInteger(int index) {
563-
return getBigInteger(schema.indexToName(index - 1));
562+
return getBigInteger(schema.columnIndexToName(index));
564563
}
565564

566565
@Override
567566
public BigDecimal getBigDecimal(int index) {
568-
return getBigDecimal(schema.indexToName(index - 1));
567+
return getBigDecimal(schema.columnIndexToName(index));
569568
}
570569

571570
@Override
@@ -620,37 +619,37 @@ public ClickHouseGeoMultiPolygonValue getGeoMultiPolygon(int index) {
620619

621620
@Override
622621
public <T> List<T> getList(int index) {
623-
return getList(schema.indexToName(index));
622+
return getList(schema.columnIndexToName(index));
624623
}
625624

626625
@Override
627626
public byte[] getByteArray(int index) {
628-
return getPrimitiveArray(schema.indexToName(index));
627+
return getPrimitiveArray(schema.columnIndexToName(index));
629628
}
630629

631630
@Override
632631
public int[] getIntArray(int index) {
633-
return getPrimitiveArray(schema.indexToName(index));
632+
return getPrimitiveArray(schema.columnIndexToName(index));
634633
}
635634

636635
@Override
637636
public long[] getLongArray(int index) {
638-
return getPrimitiveArray(schema.indexToName(index));
637+
return getPrimitiveArray(schema.columnIndexToName(index));
639638
}
640639

641640
@Override
642641
public float[] getFloatArray(int index) {
643-
return getPrimitiveArray(schema.indexToName(index));
642+
return getPrimitiveArray(schema.columnIndexToName(index));
644643
}
645644

646645
@Override
647646
public double[] getDoubleArray(int index) {
648-
return getPrimitiveArray(schema.indexToName(index));
647+
return getPrimitiveArray(schema.columnIndexToName(index));
649648
}
650649

651650
@Override
652651
public boolean[] getBooleanArray(int index) {
653-
return getPrimitiveArray(schema.indexToName(index));
652+
return getPrimitiveArray(schema.columnIndexToName(index));
654653
}
655654

656655
@Override

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ public <T> T readValue(ClickHouseColumn column, Class<?> typeHint) throws IOExce
210210
return (T) readTuple(column);
211211
case Nothing:
212212
return null;
213-
// case SimpleAggregateFunction:
213+
case SimpleAggregateFunction:
214+
return (T) readValue(column.getNestedColumns().get(0));
214215
case AggregateFunction:
215216
return (T) readBitmap( column);
216217
default:

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

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public <T> T readValue(int colIndex) {
3737
if (colIndex < 1 || colIndex > schema.getColumns().size()) {
3838
throw new ClientException("Column index out of bounds: " + colIndex);
3939
}
40-
colIndex = colIndex - 1;
41-
return (T) record.get(schema.indexToName(colIndex));
40+
41+
return (T) record.get(schema.columnIndexToName(colIndex));
4242
}
4343

4444
public <T> T readValue(String colName) {
@@ -133,8 +133,7 @@ public BigDecimal getBigDecimal(String colName) {
133133

134134
@Override
135135
public Instant getInstant(String colName) {
136-
int colIndex = schema.nameToIndex(colName);
137-
ClickHouseColumn column = schema.getColumns().get(colIndex);
136+
ClickHouseColumn column = schema.getColumnByName(colName);
138137
switch (column.getDataType()) {
139138
case Date:
140139
case Date32:
@@ -144,15 +143,13 @@ public Instant getInstant(String colName) {
144143
case DateTime64:
145144
LocalDateTime dateTime = readValue(colName);
146145
return dateTime.toInstant(column.getTimeZone().toZoneId().getRules().getOffset(dateTime));
147-
148146
}
149147
throw new ClientException("Column of type " + column.getDataType() + " cannot be converted to Instant");
150148
}
151149

152150
@Override
153151
public ZonedDateTime getZonedDateTime(String colName) {
154-
int colIndex = schema.nameToIndex(colName);
155-
ClickHouseColumn column = schema.getColumns().get(colIndex);
152+
ClickHouseColumn column = schema.getColumnByName(colName);
156153
switch (column.getDataType()) {
157154
case DateTime:
158155
case DateTime64:
@@ -166,8 +163,7 @@ public ZonedDateTime getZonedDateTime(String colName) {
166163

167164
@Override
168165
public Duration getDuration(String colName) {
169-
int colIndex = schema.nameToIndex(colName);
170-
ClickHouseColumn column = schema.getColumns().get(colIndex);
166+
ClickHouseColumn column = schema.getColumnByName(colName);
171167
BigInteger value = readValue(colName);
172168
try {
173169
switch (column.getDataType()) {
@@ -288,7 +284,7 @@ public boolean[] getBooleanArray(String colName) {
288284

289285
@Override
290286
public boolean hasValue(int colIndex) {
291-
return record.containsKey(schema.indexToName(colIndex));
287+
return record.containsKey(schema.columnIndexToName(colIndex));
292288
}
293289

294290
@Override
@@ -298,37 +294,37 @@ public boolean hasValue(String colName) {
298294

299295
@Override
300296
public byte getByte(int index) {
301-
return getByte(schema.indexToName(index));
297+
return getByte(schema.columnIndexToName(index));
302298
}
303299

304300
@Override
305301
public short getShort(int index) {
306-
return getShort(schema.indexToName(index));
302+
return getShort(schema.columnIndexToName(index));
307303
}
308304

309305
@Override
310306
public int getInteger(int index) {
311-
return getInteger(schema.indexToName(index));
307+
return getInteger(schema.columnIndexToName(index));
312308
}
313309

314310
@Override
315311
public long getLong(int index) {
316-
return getLong(schema.indexToName(index));
312+
return getLong(schema.columnIndexToName(index));
317313
}
318314

319315
@Override
320316
public float getFloat(int index) {
321-
return getFloat(schema.indexToName(index));
317+
return getFloat(schema.columnIndexToName(index));
322318
}
323319

324320
@Override
325321
public double getDouble(int index) {
326-
return getDouble(schema.indexToName(index));
322+
return getDouble(schema.columnIndexToName(index));
327323
}
328324

329325
@Override
330326
public boolean getBoolean(int index) {
331-
return getBoolean(schema.indexToName(index));
327+
return getBoolean(schema.columnIndexToName(index));
332328
}
333329

334330
@Override
@@ -393,37 +389,37 @@ public ClickHouseGeoMultiPolygonValue getGeoMultiPolygon(int index) {
393389

394390
@Override
395391
public <T> List<T> getList(int index) {
396-
return getList(schema.indexToName(index));
392+
return getList(schema.columnIndexToName(index));
397393
}
398394

399395
@Override
400396
public byte[] getByteArray(int index) {
401-
return getPrimitiveArray(schema.indexToName(index));
397+
return getPrimitiveArray(schema.columnIndexToName(index));
402398
}
403399

404400
@Override
405401
public int[] getIntArray(int index) {
406-
return getPrimitiveArray(schema.indexToName(index));
402+
return getPrimitiveArray(schema.columnIndexToName(index));
407403
}
408404

409405
@Override
410406
public long[] getLongArray(int index) {
411-
return getPrimitiveArray(schema.indexToName(index));
407+
return getPrimitiveArray(schema.columnIndexToName(index));
412408
}
413409

414410
@Override
415411
public float[] getFloatArray(int index) {
416-
return getPrimitiveArray(schema.indexToName(index));
412+
return getPrimitiveArray(schema.columnIndexToName(index));
417413
}
418414

419415
@Override
420416
public double[] getDoubleArray(int index) {
421-
return getPrimitiveArray(schema.indexToName(index));
417+
return getPrimitiveArray(schema.columnIndexToName(index));
422418
}
423419

424420
@Override
425421
public boolean[] getBooleanArray(int index) {
426-
return getPrimitiveArray(schema.indexToName(index));
422+
return getPrimitiveArray(schema.columnIndexToName(index));
427423
}
428424

429425
@Override

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ public boolean shouldRetry(Exception ex, Map<String, Object> requestSettings) {
587587
return retryCauses.contains(ClientFaultCause.NoHttpResponse);
588588
}
589589

590-
if (ex instanceof ConnectException) {
590+
if (ex instanceof ConnectException || ex instanceof ConnectTimeoutException) {
591591
return retryCauses.contains(ClientFaultCause.ConnectTimeout);
592592
}
593593

@@ -602,6 +602,7 @@ public boolean shouldRetry(Exception ex, Map<String, Object> requestSettings) {
602602
// ClientException will be also wrapped
603603
public ClientException wrapException(String message, Exception cause) {
604604
if (cause instanceof ConnectionRequestTimeoutException ||
605+
cause instanceof NoHttpResponseException ||
605606
cause instanceof ConnectTimeoutException ||
606607
cause instanceof ConnectException) {
607608
return new ConnectionInitiationException(message, cause);

client-v2/src/main/java/com/clickhouse/client/api/metadata/TableSchema.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ public ClickHouseColumn getColumnByName(String name) {
9191
return columns.get(nameToIndex(name));
9292
}
9393

94+
/**
95+
* Takes absolute index (starting from 0) and returns corresponding column.
96+
*
97+
* @param index - column index starting from 0
98+
* @return - column name
99+
*/
94100
public String indexToName(int index) {
95101
try {
96102
return columns.get(index).getColumnName();
@@ -99,6 +105,17 @@ public String indexToName(int index) {
99105
}
100106
}
101107

108+
/**
109+
* Takes absolute index (starting from 1) and return corresponding column.
110+
* Equals to {@code indexToName(index - 1}.
111+
*
112+
* @param index - column index starting from 1
113+
* @return - column name.
114+
*/
115+
public String columnIndexToName(int index) {
116+
return indexToName(index - 1);
117+
}
118+
102119
public int nameToIndex(String name) {
103120
Integer index = colIndex.get(name);
104121
if (index == null) {

0 commit comments

Comments
 (0)