Skip to content

Commit 4f8de9d

Browse files
committed
fixed tests for ch versions
1 parent dc82be7 commit 4f8de9d

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.clickhouse.client.api.metadata.TableSchema;
1313
import com.clickhouse.client.api.query.GenericRecord;
1414
import com.clickhouse.data.ClickHouseDataType;
15+
import com.clickhouse.data.ClickHouseVersion;
1516
import lombok.AllArgsConstructor;
1617
import lombok.Data;
1718
import lombok.NoArgsConstructor;
@@ -142,6 +143,10 @@ public static String tblCreateSQL(String table) {
142143

143144
@Test(groups = {"integration"})
144145
public void testVariantWithSimpleDataTypes() throws Exception {
146+
if (isVersionMatch("(,24.8]")) {
147+
return;
148+
}
149+
145150
final String table = "test_variant_primitives";
146151
final DataTypesTestingPOJO sample = new DataTypesTestingPOJO();
147152

@@ -383,6 +388,10 @@ public void testVariantWithTuple() throws Exception {
383388
}
384389

385390
private void testVariantWith(String withWhat, String[] fields, Object[] values, String[] expectedStrValues) throws Exception {
391+
if (isVersionMatch("(,24.8]")) {
392+
return;
393+
}
394+
386395
String table = "test_variant_with_" + withWhat;
387396
String[] actualFields = new String[fields.length + 1];
388397
actualFields[0] = "rowId Int32";
@@ -416,4 +425,8 @@ public static String tableDefinition(String table, String... columns) {
416425
return sb.toString();
417426
}
418427

428+
public boolean isVersionMatch(String versionExpression) {
429+
List<GenericRecord> serverVersion = client.queryAll("SELECT version()");
430+
return ClickHouseVersion.of(serverVersion.get(0).getString(1)).check(versionExpression);
431+
}
419432
}

client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,17 +1418,19 @@ private List<Map<String, Object>> prepareDataSet(String table, List<String> colu
14181418
client.execute("DROP TABLE IF EXISTS " + table).get(10, TimeUnit.SECONDS);
14191419

14201420
// Create table
1421+
CommandSettings settings = new CommandSettings();
1422+
if (isVersionMatch("[24.8,)")) {
1423+
settings.serverSetting("enable_dynamic_type", "1")
1424+
.serverSetting("allow_experimental_json_type", "1");
1425+
}
14211426
StringBuilder createStmtBuilder = new StringBuilder();
14221427
createStmtBuilder.append("CREATE TABLE IF NOT EXISTS ").append(table).append(" (");
14231428
for (String column : columns) {
14241429
createStmtBuilder.append(column).append(", ");
14251430
}
14261431
createStmtBuilder.setLength(createStmtBuilder.length() - 2);
14271432
createStmtBuilder.append(") ENGINE = MergeTree ORDER BY tuple()");
1428-
client.execute(createStmtBuilder.toString(), (CommandSettings)
1429-
new CommandSettings().serverSetting("enable_dynamic_type", "1")
1430-
.serverSetting("allow_experimental_json_type", "1"))
1431-
.get(10, TimeUnit.SECONDS);
1433+
client.execute(createStmtBuilder.toString(), settings).get(10, TimeUnit.SECONDS);
14321434

14331435
// Insert data
14341436
StringBuilder insertStmtBuilder = new StringBuilder();
@@ -1787,9 +1789,7 @@ private static Object[][] sessionRoles() {
17871789

17881790
@Test(groups = {"integration"}, dataProvider = "sessionRoles", dataProviderClass = QueryTests.class)
17891791
public void testOperationCustomRoles(String[] roles) throws Exception {
1790-
List<GenericRecord> serverVersion = client.queryAll("SELECT version()");
1791-
if (ClickHouseVersion.of(serverVersion.get(0).getString(1)).check("(,24.3]")) {
1792-
System.out.println("Test is skipped: feature is supported since 24.4");
1792+
if (isVersionMatch("(,24.3]")) {
17931793
return;
17941794
}
17951795

@@ -1825,9 +1825,7 @@ private static Object[][] clientSessionRoles() {
18251825
}
18261826
@Test(groups = {"integration"}, dataProvider = "clientSessionRoles", dataProviderClass = QueryTests.class)
18271827
public void testClientCustomRoles(String[] roles) throws Exception {
1828-
List<GenericRecord> serverVersion = client.queryAll("SELECT version()");
1829-
if (ClickHouseVersion.of(serverVersion.get(0).getString(1)).check("(,24.3]")) {
1830-
System.out.println("Test is skipped: feature is supported since 24.4");
1828+
if (isVersionMatch("(,24.3]")) {
18311829
return;
18321830
}
18331831

@@ -1909,9 +1907,7 @@ public void testReadingJSONValues() throws Exception {
19091907
if (isCloud()) {
19101908
return; // TODO: add support on cloud
19111909
}
1912-
List<GenericRecord> serverVersion = client.queryAll("SELECT version()");
1913-
if (ClickHouseVersion.of(serverVersion.get(0).getString(1)).check("(,24.8]")) {
1914-
System.out.println("Test is skipped: feature is supported since 24.8");
1910+
if (isVersionMatch("(,24.8]")) {
19151911
return;
19161912
}
19171913
CommandSettings commandSettings = new CommandSettings();
@@ -2050,8 +2046,7 @@ public void testLowCardinalityValues() throws Exception {
20502046
@Test(groups = {"integration"})
20512047
public void testGettingRowsBeforeLimit() throws Exception {
20522048
int expectedTotalRowsToRead = 100;
2053-
List<GenericRecord> serverVersion = client.queryAll("SELECT version()");
2054-
if (ClickHouseVersion.of(serverVersion.get(0).getString(1)).check("(,23.8]")) {
2049+
if (isVersionMatch("(,23.8]")) {
20552050
// issue in prev. release.
20562051
expectedTotalRowsToRead = 0;
20572052
}
@@ -2065,6 +2060,10 @@ public void testGettingRowsBeforeLimit() throws Exception {
20652060

20662061
@Test(groups = {"integration"})
20672062
public void testGetDynamicValue() throws Exception {
2063+
if (isVersionMatch("(,24.8]")) {
2064+
return;
2065+
}
2066+
20682067
String table = "test_get_dynamic_values";
20692068

20702069
final AtomicInteger rowId = new AtomicInteger(-1);
@@ -2093,6 +2092,10 @@ public void testGetDynamicValue() throws Exception {
20932092

20942093
@Test(groups = {"integration"})
20952094
public void testGetJSON() throws Exception {
2095+
if (isVersionMatch("(,24.8]")) {
2096+
return;
2097+
}
2098+
20962099
String table = "test_get_json_values";
20972100

20982101
final AtomicInteger rowId = new AtomicInteger(-1);
@@ -2121,4 +2124,9 @@ public void testGetJSON() throws Exception {
21212124
}
21222125
}
21232126
}
2127+
2128+
public boolean isVersionMatch(String versionExpression) {
2129+
List<GenericRecord> serverVersion = client.queryAll("SELECT version()");
2130+
return ClickHouseVersion.of(serverVersion.get(0).getString(1)).check(versionExpression);
2131+
}
21242132
}

0 commit comments

Comments
 (0)