Skip to content

Commit 0c8f485

Browse files
author
Paultagoras
committed
Adjusting to add version checking
1 parent 4a405f8 commit 0c8f485

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

client-v2/src/test/java/com/clickhouse/client/datatypes/RowBinaryFormatWriterTest.java

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.clickhouse.client.api.metadata.TableSchema;
1616
import com.clickhouse.client.api.query.GenericRecord;
1717
import com.clickhouse.data.ClickHouseFormat;
18+
import com.clickhouse.data.ClickHouseVersion;
1819
import org.testcontainers.shaded.org.apache.commons.lang3.RandomStringUtils;
1920
import org.testng.annotations.BeforeMethod;
2021
import org.testng.annotations.Test;
@@ -65,24 +66,45 @@ public void setUp() throws IOException {
6566
protected Client.Builder newClient() {
6667
ClickHouseNode node = getServer(ClickHouseProtocol.HTTP);
6768
boolean isSecure = isCloud();
68-
return new Client.Builder()
69+
Client.Builder builder = new Client.Builder()
6970
.addEndpoint(Protocol.HTTP, node.getHost(), node.getPort(), isSecure)
7071
.setUsername("default")
7172
.setPassword(ClickHouseServerForTest.getPassword())
7273
.setDefaultDatabase(ClickHouseServerForTest.getDatabase())
73-
.serverSetting(ServerSettings.INPUT_FORMAT_BINARY_READ_JSON_AS_STRING, "1")
7474
.serverSetting(ServerSettings.ASYNC_INSERT, "0")
7575
.serverSetting(ServerSettings.WAIT_END_OF_QUERY, "1");
76+
77+
if (isVersionMatch("[24.10,)")) {
78+
builder.serverSetting(ServerSettings.INPUT_FORMAT_BINARY_READ_JSON_AS_STRING, "1");
79+
}
80+
81+
return builder;
82+
}
83+
84+
protected boolean isVersionMatch(String versionExpression) {
85+
ClickHouseNode node = getServer(ClickHouseProtocol.HTTP);
86+
boolean isSecure = isCloud();
87+
try(Client client = new Client.Builder()
88+
.addEndpoint(Protocol.HTTP, node.getHost(), node.getPort(), isSecure)
89+
.setUsername("default")
90+
.setPassword(ClickHouseServerForTest.getPassword())
91+
.setDefaultDatabase(ClickHouseServerForTest.getDatabase())
92+
.build()) {
93+
List<GenericRecord> serverVersion = client.queryAll("SELECT version()");
94+
return ClickHouseVersion.of(serverVersion.get(0).getString(1)).check(versionExpression);
95+
}
7696
}
7797

7898
protected void initTable(String tableName, String createTableSQL, CommandSettings settings) throws Exception {
7999
if (settings == null) {
80100
settings = new CommandSettings();
81101
}
82102

83-
settings.serverSetting("allow_experimental_dynamic_type", "1");
84-
settings.serverSetting("allow_experimental_json_type", "1");
85-
settings.serverSetting("allow_experimental_variant_type", "1");
103+
if (isVersionMatch("[24.8,)")) {
104+
settings.serverSetting("allow_experimental_variant_type", "1")
105+
.serverSetting("allow_experimental_dynamic_type", "1")
106+
.serverSetting("allow_experimental_json_type", "1");
107+
}
86108

87109
client.execute("DROP TABLE IF EXISTS " + tableName, settings).get(EXECUTE_CMD_TIMEOUT, TimeUnit.SECONDS);
88110
client.execute(createTableSQL, settings).get(EXECUTE_CMD_TIMEOUT, TimeUnit.SECONDS);
@@ -634,6 +656,11 @@ public void writeDynamicTests() throws Exception {
634656
//TODO: Currently experimental
635657
@Test (groups = { "integration" })
636658
public void writeJsonTests() throws Exception {
659+
if (!isVersionMatch("[24.10,)")) {
660+
System.out.println("Skipping test: ClickHouse version is not compatible with JSON type");
661+
return;
662+
}
663+
637664
String tableName = "rowBinaryFormatWriterTest_writeJsonTests_" + UUID.randomUUID().toString().replace('-', '_');
638665
String tableCreate = "CREATE TABLE \"" + tableName + "\" " +
639666
" (id Int32, " +

0 commit comments

Comments
 (0)