Skip to content

Commit

Permalink
Fix NPE on V1 when table has array(nested) field (#497)
Browse files Browse the repository at this point in the history
Closes #496
  • Loading branch information
ArtDu authored Feb 9, 2025
1 parent 0e49af7 commit a95f74b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 1.2.8
* Fix NPE on V1 client when Clickhouse has table with Array(Nested...) field

# 1.2.7
* Bump clickhouse-java to 0.8.0
* Fix for handling of nullable fields in tuples ClickHouse data type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ public static Column extractColumn(String name, String valueType, boolean isNull
.build();
} else if (valueType.startsWith("Array")) {
Column arrayType = extractColumn(name, valueType.substring("Array".length() + 1, valueType.length() - 1), false, isSubColumn, hasDefaultValue, arrayDepth + 1);
if (arrayType == null) {
return null;
}

Column array = builder.type(Type.ARRAY)
.arrayType(arrayType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,16 @@ protected ClickHouseHelperClient createClient(Map<String,String> props, boolean
String password = csc.getPassword();
boolean sslEnabled = csc.isSslEnabled();
int timeout = csc.getTimeout();

String clientVersion = csc.getClientVersion();
boolean useClientV2 = clientVersion.equals("V1") ? false : true;
ClickHouseHelperClient tmpChc = new ClickHouseHelperClient.ClickHouseClientBuilder(hostname, port, csc.getProxyType(), csc.getProxyHost(), csc.getProxyPort())
.setDatabase(database)
.setUsername(username)
.setPassword(password)
.sslEnable(sslEnabled)
.setTimeout(timeout)
.setRetry(csc.getRetry())
.useClientV2(useClientV2)
.build();

if (withDatabase) {
Expand All @@ -98,6 +100,7 @@ protected ClickHouseHelperClient createClient(Map<String,String> props, boolean
.sslEnable(sslEnabled)
.setTimeout(timeout)
.setRetry(csc.getRetry())
.useClientV2(useClientV2)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ public void describeNestedFlattenedTable() {
}
}

@Test
public void ignoreArrayWithNestedTable() {
String topic = createTopicName("nested_table_test");
ClickHouseTestHelpers.createTable(chc, topic,
"CREATE TABLE %s ( `num` String, " +
"`nested` Array(Nested (innerInt Int32, innerString String))) " +
"Engine = MergeTree ORDER BY num");

try {
Table table = chc.describeTable(chc.getDatabase(), topic);
Assertions.assertNull(table);
} finally {
ClickHouseTestHelpers.dropTable(chc, topic);
}
}

@Test
@SinceClickHouseVersion("24.1")
public void describeNestedUnFlattenedTable() {
Expand Down

0 comments on commit a95f74b

Please sign in to comment.