Skip to content

Commit d475e82

Browse files
authored
Merge pull request #2480 from ClickHouse/jdbc_fix_metadata_issues
[jdbc-v2] Fix Database Metadata issue when wrong column data types are returned
2 parents 3503209 + a3fe0c2 commit d475e82

File tree

5 files changed

+1152
-123
lines changed

5 files changed

+1152
-123
lines changed

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

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
import com.clickhouse.jdbc.types.Array;
77
import com.google.common.collect.ImmutableMap;
88

9+
import java.awt.*;
10+
import java.math.BigInteger;
911
import java.net.Inet4Address;
1012
import java.net.Inet6Address;
1113
import java.sql.Date;
1214
import java.sql.JDBCType;
1315
import java.sql.SQLException;
1416
import java.sql.SQLType;
17+
import java.sql.Types;
1518
import java.time.LocalDate;
1619
import java.time.LocalDateTime;
1720
import java.time.LocalTime;
@@ -42,6 +45,14 @@ private static Map<ClickHouseDataType, SQLType> generateTypeMap() {
4245
map.put(ClickHouseDataType.Int16, JDBCType.SMALLINT);
4346
map.put(ClickHouseDataType.Int32, JDBCType.INTEGER);
4447
map.put(ClickHouseDataType.Int64, JDBCType.BIGINT);
48+
map.put(ClickHouseDataType.Int128, JDBCType.OTHER);
49+
map.put(ClickHouseDataType.Int256, JDBCType.OTHER);
50+
map.put(ClickHouseDataType.UInt8, JDBCType.SMALLINT);
51+
map.put(ClickHouseDataType.UInt16, JDBCType.INTEGER);
52+
map.put(ClickHouseDataType.UInt32, JDBCType.BIGINT);
53+
map.put(ClickHouseDataType.UInt64, JDBCType.OTHER);
54+
map.put(ClickHouseDataType.UInt128, JDBCType.OTHER);
55+
map.put(ClickHouseDataType.UInt256, JDBCType.OTHER);
4556
map.put(ClickHouseDataType.Float32, JDBCType.FLOAT);
4657
map.put(ClickHouseDataType.Float64, JDBCType.DOUBLE);
4758
map.put(ClickHouseDataType.Bool, JDBCType.BOOLEAN);
@@ -81,8 +92,8 @@ private static Map<SQLType, Class<?>> generateClassMap() {
8192
map.put(JDBCType.DECIMAL, java.math.BigDecimal.class);
8293
map.put(JDBCType.BIT, Boolean.class);
8394
map.put(JDBCType.BOOLEAN, Boolean.class);
84-
map.put(JDBCType.TINYINT, Integer.class);
85-
map.put(JDBCType.SMALLINT, Integer.class);
95+
map.put(JDBCType.TINYINT, Byte.class);
96+
map.put(JDBCType.SMALLINT, Short.class);
8697
map.put(JDBCType.INTEGER, Integer.class);
8798
map.put(JDBCType.BIGINT, Long.class);
8899
map.put(JDBCType.REAL, Float.class);
@@ -115,9 +126,44 @@ private static Map<SQLType, Class<?>> generateClassMap() {
115126
private static Map<ClickHouseDataType, Class<?>> getDataTypeClassMap() {
116127
Map<ClickHouseDataType, Class<?>> map = new HashMap<>();
117128
for (Map.Entry<ClickHouseDataType, SQLType> e : CLICKHOUSE_TO_SQL_TYPE_MAP.entrySet()) {
118-
map.put(e.getKey(), SQL_TYPE_TO_CLASS_MAP.get(e.getValue()));
129+
if (e.getValue().equals(JDBCType.OTHER)) {
130+
switch (e.getKey()) {
131+
case UInt64:
132+
map.put(e.getKey(), BigInteger.class);
133+
break;
134+
case UInt128:
135+
map.put(e.getKey(), BigInteger.class);
136+
break;
137+
case UInt256:
138+
map.put(e.getKey(), BigInteger.class);
139+
break;
140+
case Int128:
141+
map.put(e.getKey(), BigInteger.class);
142+
break;
143+
case Int256:
144+
map.put(e.getKey(), BigInteger.class);
145+
break;
146+
case Point:
147+
map.put(e.getKey(), double[].class);
148+
break;
149+
case LineString:
150+
case Ring:
151+
map.put(e.getKey(), double[][].class);
152+
break;
153+
case Polygon:
154+
case MultiLineString:
155+
map.put(e.getKey(), double[][][].class);
156+
break;
157+
case MultiPolygon:
158+
map.put(e.getKey(), double[][][][].class);
159+
break;
160+
default:
161+
map.put(e.getKey(), Object.class);
162+
}
163+
} else {
164+
map.put(e.getKey(), SQL_TYPE_TO_CLASS_MAP.get(e.getValue()));
165+
}
119166
}
120-
121167
return map;
122168
}
123169

0 commit comments

Comments
 (0)