Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix integration tests against LATEST to address suspicious low cardinality array check. #1562

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading