Skip to content

Commit fba928f

Browse files
authored
Merge pull request #2033 from ClickHouse/updating-metadata-types-for-arrays
Adding the types to be clearer
2 parents 57810b4 + fb9cc45 commit fba928f

File tree

5 files changed

+11
-7
lines changed

5 files changed

+11
-7
lines changed

jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.clickhouse.client.api.ClientConfigProperties;
55
import com.clickhouse.client.api.query.GenericRecord;
66
import com.clickhouse.client.api.query.QuerySettings;
7+
import com.clickhouse.data.ClickHouseDataType;
78
import com.clickhouse.jdbc.internal.ClientInfoProperties;
89
import com.clickhouse.jdbc.internal.JdbcConfiguration;
910
import com.clickhouse.jdbc.internal.ExceptionUtils;
@@ -483,8 +484,7 @@ public Properties getClientInfo() throws SQLException {
483484
@Override
484485
public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
485486
try {
486-
// TODO: pass type name
487-
return new com.clickhouse.jdbc.types.Array(List.of(elements), Types.OTHER);
487+
return new com.clickhouse.jdbc.types.Array(List.of(elements), typeName, JdbcUtils.convertToSqlType(ClickHouseDataType.valueOf(typeName)));
488488
} catch (Exception e) {
489489
throw new SQLException("Failed to create array", ExceptionUtils.SQL_STATE_CLIENT_ERROR, e);
490490
}

jdbc-v2/src/main/java/com/clickhouse/jdbc/ResultSetImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,9 @@ public java.sql.Array getArray(String columnLabel) throws SQLException {
13021302
checkClosed();
13031303
try {
13041304
ClickHouseColumn column = reader.getSchema().getColumnByName(columnLabel);
1305-
return new Array(reader.getList(columnLabel), JdbcUtils.convertToSqlType(column.getArrayBaseColumn().getDataType()));
1305+
return new Array(reader.getList(columnLabel),
1306+
column.getArrayBaseColumn().getDataType().name(),
1307+
JdbcUtils.convertToSqlType(column.getArrayBaseColumn().getDataType()));
13061308
} catch (Exception e) {
13071309
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getArray(%s)", parentStatement.getLastSql(), columnLabel), e);
13081310
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public int getColumnType(int column) throws SQLException {
142142
@Override
143143
public String getColumnTypeName(int column) throws SQLException {
144144
try {
145-
return getColumn(column).getDataType().name();
145+
return getColumn(column).getOriginalTypeName();
146146
} catch (Exception e) {
147147
throw ExceptionUtils.toSqlState(e);
148148
}

jdbc-v2/src/main/java/com/clickhouse/jdbc/types/Array.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,21 @@ public class Array implements java.sql.Array {
1515
private static final Logger log = LoggerFactory.getLogger(Array.class);
1616
Object[] array;
1717
int type; //java.sql.Types
18+
String typeName;
1819

19-
public Array(List<Object> list, int itemType) throws SQLException {
20+
public Array(List<Object> list, String itemTypeName, int itemType) throws SQLException {
2021
if (list == null) {
2122
throw ExceptionUtils.toSqlState(new IllegalArgumentException("List cannot be null"));
2223
}
2324

2425
this.array = list.toArray();
2526
this.type = itemType;
27+
this.typeName = itemTypeName;
2628
}
2729

2830
@Override
2931
public String getBaseTypeName() throws SQLException {
30-
return Object.class.getName();
32+
return typeName;
3133
}
3234

3335
@Override

jdbc-v2/src/test/java/com/clickhouse/jdbc/ConnectionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public void setAndGetClientInfoTest() throws SQLException {
246246
@Test(groups = { "integration" })
247247
public void createArrayOfTest() throws SQLException {
248248
Connection localConnection = this.getJdbcConnection();
249-
Array array = localConnection.createArrayOf("type-name", new Object[] { 1, 2, 3 });
249+
Array array = localConnection.createArrayOf("Int8", new Object[] { 1, 2, 3 });
250250
Assert.assertNotNull(array);
251251
Assert.assertEquals(array.getArray(), new Object[] { 1, 2, 3 });
252252
}

0 commit comments

Comments
 (0)