|
15 | 15 | import com.clickhouse.client.api.metadata.TableSchema; |
16 | 16 | import com.clickhouse.client.api.query.GenericRecord; |
17 | 17 | import com.clickhouse.data.ClickHouseFormat; |
| 18 | +import com.clickhouse.data.ClickHouseVersion; |
18 | 19 | import org.testcontainers.shaded.org.apache.commons.lang3.RandomStringUtils; |
19 | 20 | import org.testng.annotations.BeforeMethod; |
20 | 21 | import org.testng.annotations.Test; |
@@ -65,24 +66,45 @@ public void setUp() throws IOException { |
65 | 66 | protected Client.Builder newClient() { |
66 | 67 | ClickHouseNode node = getServer(ClickHouseProtocol.HTTP); |
67 | 68 | boolean isSecure = isCloud(); |
68 | | - return new Client.Builder() |
| 69 | + Client.Builder builder = new Client.Builder() |
69 | 70 | .addEndpoint(Protocol.HTTP, node.getHost(), node.getPort(), isSecure) |
70 | 71 | .setUsername("default") |
71 | 72 | .setPassword(ClickHouseServerForTest.getPassword()) |
72 | 73 | .setDefaultDatabase(ClickHouseServerForTest.getDatabase()) |
73 | | - .serverSetting(ServerSettings.INPUT_FORMAT_BINARY_READ_JSON_AS_STRING, "1") |
74 | 74 | .serverSetting(ServerSettings.ASYNC_INSERT, "0") |
75 | 75 | .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 | + } |
76 | 96 | } |
77 | 97 |
|
78 | 98 | protected void initTable(String tableName, String createTableSQL, CommandSettings settings) throws Exception { |
79 | 99 | if (settings == null) { |
80 | 100 | settings = new CommandSettings(); |
81 | 101 | } |
82 | 102 |
|
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 | + } |
86 | 108 |
|
87 | 109 | client.execute("DROP TABLE IF EXISTS " + tableName, settings).get(EXECUTE_CMD_TIMEOUT, TimeUnit.SECONDS); |
88 | 110 | client.execute(createTableSQL, settings).get(EXECUTE_CMD_TIMEOUT, TimeUnit.SECONDS); |
@@ -634,6 +656,11 @@ public void writeDynamicTests() throws Exception { |
634 | 656 | //TODO: Currently experimental |
635 | 657 | @Test (groups = { "integration" }) |
636 | 658 | 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 | + |
637 | 664 | String tableName = "rowBinaryFormatWriterTest_writeJsonTests_" + UUID.randomUUID().toString().replace('-', '_'); |
638 | 665 | String tableCreate = "CREATE TABLE \"" + tableName + "\" " + |
639 | 666 | " (id Int32, " + |
|
0 commit comments