Skip to content

Commit 9503e2a

Browse files
committed
Added more tests for other metadata columns
1 parent 0ac059f commit 9503e2a

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public enum ClickHouseDataType {
108108
JSON(Object.class, false, false, false, 0, 0, 0, 0, 0, true, 0x30),
109109
@Deprecated
110110
Object(Object.class, true, true, false, 0, 0, 0, 0, 0, true),
111-
String(String.class, false, false, false, 0, 0, 0, 0, 0, false, 0x15, "BINARY LARGE OBJECT", "BINARY VARYING", "BLOB",
111+
String(String.class, false, true, false, 0, 0, 0, 0, 0, false, 0x15, "BINARY LARGE OBJECT", "BINARY VARYING", "BLOB",
112112
"BYTEA", "CHAR", "CHAR LARGE OBJECT", "CHAR VARYING", "CHARACTER", "CHARACTER LARGE OBJECT",
113113
"CHARACTER VARYING", "CLOB", "GEOMETRY", "LONGBLOB", "LONGTEXT", "MEDIUMBLOB", "MEDIUMTEXT",
114114
"NATIONAL CHAR", "NATIONAL CHAR VARYING", "NATIONAL CHARACTER", "NATIONAL CHARACTER LARGE OBJECT",
@@ -119,8 +119,8 @@ public enum ClickHouseDataType {
119119
Nested(Object.class, true, true, false, 0, 0, 0, 0, 0, true, 0x2F),
120120
Tuple(List.class, true, true, false, 0, 0, 0, 0, 0, true, 0x1F),
121121
Nothing(Object.class, false, true, false, 0, 0, 0, 0, 0, true, 0x00),
122-
LowCardinality(Object.class, true, false, false, 0, 0, 0, 0, 0, true, 0x26),
123-
Nullable( Object.class, true, false, false, 0, 0, 0, 0, 0, true, 0x23),
122+
LowCardinality(Object.class, true, true, false, 0, 0, 0, 0, 0, true, 0x26),
123+
Nullable( Object.class, true, true, false, 0, 0, 0, 0, 0, true, 0x23),
124124
SimpleAggregateFunction(String.class, true, true, false, 0, 0, 0, 0, 0, false, 0x2E),
125125
// implementation-defined intermediate state
126126
AggregateFunction(String.class, true, true, false, 0, 0, 0, 0, 0, true),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,9 +1029,9 @@ private static String getDataTypeInfoSql() {
10291029
"NULL AS LITERAL_SUFFIX, " +
10301030
"NULL AS CREATE_PARAMS, " +
10311031
"name AS NULLABLE, " + // passing type name to map for nullable
1032-
"not(dt.case_insensitive) AS CASE_SENSITIVE, " +
1032+
"not(dt.case_insensitive)::Boolean AS CASE_SENSITIVE, " +
10331033
java.sql.DatabaseMetaData.typeSearchable + " AS SEARCHABLE, " +
1034-
"attrs.c3 AS UNSIGNED_ATTRIBUTE, " +
1034+
"not(attrs.c3)::Boolean AS UNSIGNED_ATTRIBUTE, " +
10351035
"false AS FIXED_PREC_SCALE, " +
10361036
"false AS AUTO_INCREMENT, " +
10371037
"name AS LOCAL_TYPE_NAME, " +

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,17 +240,39 @@ public void testGetTypeInfo() throws Exception {
240240
while (rs.next()) {
241241
count++;
242242
ClickHouseDataType dataType = ClickHouseDataType.of( rs.getString("TYPE_NAME"));
243+
System.out.println("> " + dataType);
243244
assertEquals(ClickHouseDataType.of(rs.getString(1)), dataType);
244245
assertEquals(rs.getInt("DATA_TYPE"),
245246
(int) JdbcUtils.convertToSqlType(dataType).getVendorTypeNumber(),
246247
"Type mismatch for " + dataType.name() + ": expected " +
247248
JdbcUtils.convertToSqlType(dataType).getVendorTypeNumber() +
248249
" but was " + rs.getInt("DATA_TYPE") + " for TYPE_NAME: " + rs.getString("TYPE_NAME"));
250+
251+
assertEquals(rs.getInt("PRECISION"), dataType.getMaxPrecision());
252+
assertNull(rs.getString("LITERAL_PREFIX"));
253+
assertNull(rs.getString("LITERAL_SUFFIX"));
254+
assertEquals(rs.getInt("MINIMUM_SCALE"), dataType.getMinScale());
255+
assertEquals(rs.getInt("MAXIMUM_SCALE"), dataType.getMaxScale());
256+
assertNull(rs.getString("CREATE_PARAMS"));
257+
249258
if (dataType == ClickHouseDataType.Nullable || dataType == ClickHouseDataType.Dynamic) {
250259
assertEquals( rs.getShort("NULLABLE"), DatabaseMetaData.typeNullable);
251260
} else {
252261
assertEquals(rs.getShort("NULLABLE"), DatabaseMetaData.typeNoNulls);
253262
}
263+
264+
if (dataType != ClickHouseDataType.Enum) {
265+
assertEquals(rs.getBoolean("CASE_SENSITIVE"), dataType.isCaseSensitive());
266+
}
267+
assertEquals(rs.getInt("SEARCHABLE"), DatabaseMetaData.typeSearchable);
268+
assertEquals(rs.getBoolean("UNSIGNED_ATTRIBUTE"), !dataType.isSigned());
269+
assertEquals(rs.getBoolean("FIXED_PREC_SCALE"), false);
270+
assertFalse(rs.getBoolean("AUTO_INCREMENT"));
271+
assertEquals(rs.getString("LOCAL_TYPE_NAME"), dataType.name());
272+
assertEquals(rs.getInt("MINIMUM_SCALE"), dataType.getMinScale());
273+
assertEquals(rs.getInt("MAXIMUM_SCALE"), dataType.getMaxScale());
274+
assertEquals(rs.getInt("SQL_DATA_TYPE"), 0);
275+
assertEquals(rs.getInt("SQL_DATETIME_SUB"), 0);
254276
}
255277

256278
assertTrue(count > 10, "At least 10 types should be returned but was " + count);

0 commit comments

Comments
 (0)