Skip to content

Commit 8159824

Browse files
committed
fixed missing nested types in getTypeInfo resultset
1 parent e6a9f5e commit 8159824

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

jdbc-v2/src/main/java/com/clickhouse/jdbc/metadata/DatabaseMetaDataImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ private static String generateSqlTypeSizes(String columnName) {
897897
SQLType type = JdbcUtils.CLICKHOUSE_TYPE_NAME_TO_SQL_TYPE_MAP.get(typeName);
898898
if (type == null) {
899899
try {
900-
type = JdbcUtils.convertToSqlType(ClickHouseColumn.of("v1", typeName).getDataType());
900+
type = JdbcUtils.convertToSqlType(ClickHouseDataType.valueOf(typeName));
901901
} catch (Exception e) {
902902
log.error("Failed to convert column data type to SQL type: {}", typeName, e);
903903
type = JDBCType.OTHER; // In case of error, return SQL type 0

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
import java.sql.Types;
2020
import java.util.Arrays;
2121
import java.util.Collections;
22+
import java.util.HashSet;
2223
import java.util.List;
2324
import java.util.Properties;
25+
import java.util.Set;
26+
import java.util.stream.Collectors;
2427

2528
import static org.testng.Assert.assertEquals;
2629
import static org.testng.Assert.assertFalse;
@@ -453,6 +456,24 @@ public void testGetTypeInfo() throws Exception {
453456
}
454457
}
455458

459+
@Test(groups = {"integration"})
460+
public void testFindNestedTypes() throws Exception {
461+
try (Connection conn = getJdbcConnection()) {
462+
DatabaseMetaData dbmd = conn.getMetaData();
463+
try (ResultSet rs = dbmd.getTypeInfo()) {
464+
Set<String> nestedTypes = Arrays.stream(ClickHouseDataType.values())
465+
.filter(dt -> dt.isNested()).map(dt -> dt.name()).collect(Collectors.toSet());
466+
467+
while (rs.next()) {
468+
String typeName = rs.getString("TYPE_NAME");
469+
nestedTypes.remove(typeName);
470+
}
471+
472+
assertTrue(nestedTypes.isEmpty(), "Nested types " + nestedTypes + " not found");
473+
}
474+
}
475+
}
476+
456477
@Test(groups = { "integration" })
457478
public void testGetFunctions() throws Exception {
458479
if (ClickHouseVersion.of(getServerVersion()).check("(,23.8]")) {

0 commit comments

Comments
 (0)