Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/maven/org.apache.commons-commons-…
Browse files Browse the repository at this point in the history
…compress-1.26.0
  • Loading branch information
chernser committed Mar 19, 2024
2 parents 4ecee68 + 27e3168 commit e009d12
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class ClickHouseException extends Exception {
public static final int ERROR_POCO = 1000;
public static final int ERROR_TIMEOUT = 159;
public static final int ERROR_UNKNOWN = 1002;
public static final int ERROR_SUSPICIOUS_TYPE_FOR_LOW_CARDINALITY = 455;

static final String MSG_CODE = "Code: ";
static final String MSG_CONNECT_TIMED_OUT = "connect timed out";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.clickhouse.client.ClickHouseClientBuilder.Agent;
import com.clickhouse.client.ClickHouseTransaction.XID;
import com.clickhouse.client.config.ClickHouseClientOption;
import com.clickhouse.client.config.ClickHouseSslMode;
import com.clickhouse.config.ClickHouseBufferingMode;
import com.clickhouse.config.ClickHouseOption;
import com.clickhouse.config.ClickHouseRenameMethod;
Expand Down Expand Up @@ -44,7 +43,6 @@
import com.clickhouse.data.value.UnsignedShort;

import org.apache.commons.compress.compressors.lz4.FramedLZ4CompressorInputStream;
import org.testcontainers.shaded.org.apache.commons.lang3.StringUtils;
import org.testng.Assert;
import org.testng.SkipException;
import org.testng.annotations.DataProvider;
Expand Down Expand Up @@ -294,7 +292,12 @@ protected Object[][] getPrimitiveArrayMatrix() {
UnsignedLong.valueOf(5L) } },
{ "Nullable(Float32)", new Float[] { null, -2F, 3F, -4F, 5F } },
{ "Nullable(Float64)", new Double[] { 1D, null, 3D, -4D, 5D } },
};
}

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

checkPrimitiveArrayValues(server, tableName, tableColumns, baseType, expectedValues);
}

@Test(dataProvider = "primitiveArrayLowCardinalityMatrix", groups = "integration")
public void testPrimitiveArrayWithLowCardinality(String baseType, Object expectedValues) throws ClickHouseException {
ClickHouseNode server = getServer();

String tableName = "test_primitive_array_"
+ baseType.replace('(', '_').replace(')', ' ').trim().toLowerCase();
String tableColumns = String.format("a1 Array(%1$s), a2 Array(Array(%1$s)), a3 Array(Array(Array(%1$s)))",
baseType);
try {
sendAndWait(server, "drop table if exists " + tableName,
"create table " + tableName + " (" + tableColumns + ")engine=Memory",
"insert into " + tableName + String.format(
" values(%2$s, [[123],[],[4], %2$s], [[[12],[3],[],[4,5]],[[123],[],[4], %2$s]])", baseType,
ClickHouseColumn.of("", ClickHouseDataType.Array, false,
ClickHouseColumn.of("", baseType)).newArrayValue(server.config).update(expectedValues)
.toSqlExpression()));
} catch (ClickHouseException e) {
try (ClickHouseClient client = getClient()) {
if (e.getErrorCode() == ClickHouseException.ERROR_SUSPICIOUS_TYPE_FOR_LOW_CARDINALITY &&
checkServerVersion(client, server, "[24.2,)")) {
return;
}
} catch ( Exception e1) {
Assert.fail("Failed to check server version", e1);
}

Assert.fail("Exception code is " + e.getErrorCode(), e);
}
checkPrimitiveArrayValues(server, tableName, tableColumns, baseType, expectedValues);
}

private void checkPrimitiveArrayValues(ClickHouseNode server, String tableName, String tableColumns, String baseType, Object expectedValues) throws ClickHouseException {
try (ClickHouseClient client = getClient()) {
ClickHouseRequest<?> request = newRequest(client, server)
.format(ClickHouseFormat.RowBinaryWithNamesAndTypes);
Expand Down Expand Up @@ -762,6 +800,7 @@ public void testPrimitiveArray(String baseType, Object expectedValues) throws Cl
}
}


@Test(groups = { "integration" })
public void testQueryWithNoResult() throws ExecutionException, InterruptedException {
String sql = "select * from system.numbers limit 0";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@
</openSSL>

<custom_settings_prefixes>custom_</custom_settings_prefixes>

<!-- single node cluster: single_node_cluster_localhost -->
<keeper_server>
<force_recovery>1</force_recovery>
<tcp_port>9181</tcp_port>
<server_id>1</server_id>
<enable_ipv6>false</enable_ipv6> <!-- disable ipv6 for docker environment -->

<log_storage_path>/var/lib/clickhouse/coordination/log</log_storage_path>
<snapshot_storage_path>/var/lib/clickhouse/coordination/snapshots</snapshot_storage_path>
Expand Down

0 comments on commit e009d12

Please sign in to comment.