Skip to content

Commit e009d12

Browse files
committed
Merge branch 'main' into dependabot/maven/org.apache.commons-commons-compress-1.26.0
2 parents 4ecee68 + 27e3168 commit e009d12

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseException.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class ClickHouseException extends Exception {
2424
public static final int ERROR_POCO = 1000;
2525
public static final int ERROR_TIMEOUT = 159;
2626
public static final int ERROR_UNKNOWN = 1002;
27+
public static final int ERROR_SUSPICIOUS_TYPE_FOR_LOW_CARDINALITY = 455;
2728

2829
static final String MSG_CODE = "Code: ";
2930
static final String MSG_CONNECT_TIMED_OUT = "connect timed out";

clickhouse-client/src/test/java/com/clickhouse/client/ClientIntegrationTest.java

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.clickhouse.client.ClickHouseClientBuilder.Agent;
44
import com.clickhouse.client.ClickHouseTransaction.XID;
55
import com.clickhouse.client.config.ClickHouseClientOption;
6-
import com.clickhouse.client.config.ClickHouseSslMode;
76
import com.clickhouse.config.ClickHouseBufferingMode;
87
import com.clickhouse.config.ClickHouseOption;
98
import com.clickhouse.config.ClickHouseRenameMethod;
@@ -44,7 +43,6 @@
4443
import com.clickhouse.data.value.UnsignedShort;
4544

4645
import org.apache.commons.compress.compressors.lz4.FramedLZ4CompressorInputStream;
47-
import org.testcontainers.shaded.org.apache.commons.lang3.StringUtils;
4846
import org.testng.Assert;
4947
import org.testng.SkipException;
5048
import org.testng.annotations.DataProvider;
@@ -294,7 +292,12 @@ protected Object[][] getPrimitiveArrayMatrix() {
294292
UnsignedLong.valueOf(5L) } },
295293
{ "Nullable(Float32)", new Float[] { null, -2F, 3F, -4F, 5F } },
296294
{ "Nullable(Float64)", new Double[] { 1D, null, 3D, -4D, 5D } },
295+
};
296+
}
297297

298+
@DataProvider(name = "primitiveArrayLowCardinalityMatrix")
299+
protected Object[][] getPrimitiveArrayLowCardinalityMatrix() {
300+
return new Object[][]{
298301
{ "LowCardinality(Int8)", new int[] { -1, 2, -3, 4, -5 } },
299302
{ "LowCardinality(UInt8)", new int[] { 1, 2, 3, 4, 5 } },
300303
{ "LowCardinality(Int16)", new int[] { -1, 2, -3, 4, -5 } },
@@ -710,6 +713,41 @@ public void testPrimitiveArray(String baseType, Object expectedValues) throws Cl
710713
ClickHouseColumn.of("", baseType)).newArrayValue(server.config).update(expectedValues)
711714
.toSqlExpression()));
712715

716+
checkPrimitiveArrayValues(server, tableName, tableColumns, baseType, expectedValues);
717+
}
718+
719+
@Test(dataProvider = "primitiveArrayLowCardinalityMatrix", groups = "integration")
720+
public void testPrimitiveArrayWithLowCardinality(String baseType, Object expectedValues) throws ClickHouseException {
721+
ClickHouseNode server = getServer();
722+
723+
String tableName = "test_primitive_array_"
724+
+ baseType.replace('(', '_').replace(')', ' ').trim().toLowerCase();
725+
String tableColumns = String.format("a1 Array(%1$s), a2 Array(Array(%1$s)), a3 Array(Array(Array(%1$s)))",
726+
baseType);
727+
try {
728+
sendAndWait(server, "drop table if exists " + tableName,
729+
"create table " + tableName + " (" + tableColumns + ")engine=Memory",
730+
"insert into " + tableName + String.format(
731+
" values(%2$s, [[123],[],[4], %2$s], [[[12],[3],[],[4,5]],[[123],[],[4], %2$s]])", baseType,
732+
ClickHouseColumn.of("", ClickHouseDataType.Array, false,
733+
ClickHouseColumn.of("", baseType)).newArrayValue(server.config).update(expectedValues)
734+
.toSqlExpression()));
735+
} catch (ClickHouseException e) {
736+
try (ClickHouseClient client = getClient()) {
737+
if (e.getErrorCode() == ClickHouseException.ERROR_SUSPICIOUS_TYPE_FOR_LOW_CARDINALITY &&
738+
checkServerVersion(client, server, "[24.2,)")) {
739+
return;
740+
}
741+
} catch ( Exception e1) {
742+
Assert.fail("Failed to check server version", e1);
743+
}
744+
745+
Assert.fail("Exception code is " + e.getErrorCode(), e);
746+
}
747+
checkPrimitiveArrayValues(server, tableName, tableColumns, baseType, expectedValues);
748+
}
749+
750+
private void checkPrimitiveArrayValues(ClickHouseNode server, String tableName, String tableColumns, String baseType, Object expectedValues) throws ClickHouseException {
713751
try (ClickHouseClient client = getClient()) {
714752
ClickHouseRequest<?> request = newRequest(client, server)
715753
.format(ClickHouseFormat.RowBinaryWithNamesAndTypes);
@@ -762,6 +800,7 @@ public void testPrimitiveArray(String baseType, Object expectedValues) throws Cl
762800
}
763801
}
764802

803+
765804
@Test(groups = { "integration" })
766805
public void testQueryWithNoResult() throws ExecutionException, InterruptedException {
767806
String sql = "select * from system.numbers limit 0";

clickhouse-client/src/test/resources/containers/clickhouse-server/config.d/custom_config.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@
3939
</openSSL>
4040

4141
<custom_settings_prefixes>custom_</custom_settings_prefixes>
42-
42+
4343
<!-- single node cluster: single_node_cluster_localhost -->
4444
<keeper_server>
4545
<force_recovery>1</force_recovery>
4646
<tcp_port>9181</tcp_port>
4747
<server_id>1</server_id>
48+
<enable_ipv6>false</enable_ipv6> <!-- disable ipv6 for docker environment -->
4849

4950
<log_storage_path>/var/lib/clickhouse/coordination/log</log_storage_path>
5051
<snapshot_storage_path>/var/lib/clickhouse/coordination/snapshots</snapshot_storage_path>

0 commit comments

Comments
 (0)