Skip to content

Commit 8fdeb8e

Browse files
authored
Merge pull request #2406 from ClickHouse/jdbc_fix_unknow_type_problem
[jdbc, client] Fix tests for unknown type
2 parents 3045b4e + f33a89f commit 8fdeb8e

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

clickhouse-data/src/main/java/com/clickhouse/data/ClickHouseDataType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.time.Duration;
88
import java.time.LocalDate;
99
import java.time.LocalDateTime;
10+
import java.time.LocalTime;
1011
import java.time.Period;
1112
import java.time.ZonedDateTime;
1213
import java.time.temporal.ChronoUnit;

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import lombok.AllArgsConstructor;
1616
import lombok.Data;
1717
import lombok.NoArgsConstructor;
18+
import org.apache.commons.lang3.StringUtils;
1819
import org.testng.Assert;
1920
import org.testng.annotations.AfterMethod;
2021
import org.testng.annotations.BeforeMethod;
@@ -33,8 +34,10 @@
3334
import java.util.Arrays;
3435
import java.util.Collections;
3536
import java.util.HashMap;
37+
import java.util.HashSet;
3638
import java.util.List;
3739
import java.util.Map;
40+
import java.util.Set;
3841
import java.util.concurrent.atomic.AtomicInteger;
3942
import java.util.function.BiConsumer;
4043

@@ -603,6 +606,29 @@ public static class DTOForDynamicPrimitivesTests {
603606
private Object field;
604607
}
605608

609+
@Test(groups = {"integration"})
610+
public void testAllDataTypesKnown() {
611+
List<GenericRecord> dbTypes = client.queryAll("SELECT * FROM system.data_type_families");
612+
Set<String> unknowTypes = new HashSet<>();
613+
for (GenericRecord dbType : dbTypes) {
614+
String aliasFor = dbType.getString("alias_to");
615+
String typeToCheck;
616+
if (StringUtils.isNoneBlank(aliasFor)) {
617+
typeToCheck = aliasFor;
618+
} else {
619+
typeToCheck = dbType.getString("name");
620+
}
621+
622+
try {
623+
ClickHouseDataType.valueOf(typeToCheck);
624+
} catch (Exception e) {
625+
unknowTypes.add(typeToCheck);
626+
}
627+
}
628+
629+
Assert.assertTrue(unknowTypes.isEmpty(), "There are some unknown types: " + unknowTypes);
630+
}
631+
606632
private void testDynamicWith(String withWhat, Object[] values, String[] expectedStrValues) throws Exception {
607633
if (isVersionMatch("(,24.8]")) {
608634
return;

jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ private static Map<ClickHouseDataType, Class<?>> getDataTypeClassMap() {
124124

125125
public static SQLType convertToSqlType(ClickHouseDataType clickhouseType) {
126126
if (clickhouseType == null) {
127-
return JDBCType.NULL;
127+
return JDBCType.OTHER;
128128
}
129129

130130
return CLICKHOUSE_TO_SQL_TYPE_MAP.getOrDefault(clickhouseType, JDBCType.OTHER);

jdbc-v2/src/test/java/com/clickhouse/jdbc/metadata/DatabaseMetaDataTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public void testGetTypeInfo() throws Exception {
258258
}
259259
assertEquals(rs.getInt("SEARCHABLE"), DatabaseMetaData.typeSearchable);
260260
assertEquals(rs.getBoolean("UNSIGNED_ATTRIBUTE"), !dataType.isSigned());
261-
assertEquals(rs.getBoolean("FIXED_PREC_SCALE"), false);
261+
assertFalse(rs.getBoolean("FIXED_PREC_SCALE"));
262262
assertFalse(rs.getBoolean("AUTO_INCREMENT"));
263263
assertEquals(rs.getString("LOCAL_TYPE_NAME"), dataType.name());
264264
assertEquals(rs.getInt("MINIMUM_SCALE"), dataType.getMinScale());

0 commit comments

Comments
 (0)