Skip to content

Commit

Permalink
Merge pull request #2033 from ClickHouse/updating-metadata-types-for-…
Browse files Browse the repository at this point in the history
…arrays

Adding the types to be clearer
  • Loading branch information
Paultagoras authored Dec 18, 2024
2 parents 57810b4 + fb9cc45 commit fba928f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.clickhouse.client.api.ClientConfigProperties;
import com.clickhouse.client.api.query.GenericRecord;
import com.clickhouse.client.api.query.QuerySettings;
import com.clickhouse.data.ClickHouseDataType;
import com.clickhouse.jdbc.internal.ClientInfoProperties;
import com.clickhouse.jdbc.internal.JdbcConfiguration;
import com.clickhouse.jdbc.internal.ExceptionUtils;
Expand Down Expand Up @@ -483,8 +484,7 @@ public Properties getClientInfo() throws SQLException {
@Override
public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
try {
// TODO: pass type name
return new com.clickhouse.jdbc.types.Array(List.of(elements), Types.OTHER);
return new com.clickhouse.jdbc.types.Array(List.of(elements), typeName, JdbcUtils.convertToSqlType(ClickHouseDataType.valueOf(typeName)));
} catch (Exception e) {
throw new SQLException("Failed to create array", ExceptionUtils.SQL_STATE_CLIENT_ERROR, e);
}
Expand Down
4 changes: 3 additions & 1 deletion jdbc-v2/src/main/java/com/clickhouse/jdbc/ResultSetImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,9 @@ public java.sql.Array getArray(String columnLabel) throws SQLException {
checkClosed();
try {
ClickHouseColumn column = reader.getSchema().getColumnByName(columnLabel);
return new Array(reader.getList(columnLabel), JdbcUtils.convertToSqlType(column.getArrayBaseColumn().getDataType()));
return new Array(reader.getList(columnLabel),
column.getArrayBaseColumn().getDataType().name(),
JdbcUtils.convertToSqlType(column.getArrayBaseColumn().getDataType()));
} catch (Exception e) {
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getArray(%s)", parentStatement.getLastSql(), columnLabel), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public int getColumnType(int column) throws SQLException {
@Override
public String getColumnTypeName(int column) throws SQLException {
try {
return getColumn(column).getDataType().name();
return getColumn(column).getOriginalTypeName();
} catch (Exception e) {
throw ExceptionUtils.toSqlState(e);
}
Expand Down
6 changes: 4 additions & 2 deletions jdbc-v2/src/main/java/com/clickhouse/jdbc/types/Array.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ public class Array implements java.sql.Array {
private static final Logger log = LoggerFactory.getLogger(Array.class);
Object[] array;
int type; //java.sql.Types
String typeName;

public Array(List<Object> list, int itemType) throws SQLException {
public Array(List<Object> list, String itemTypeName, int itemType) throws SQLException {
if (list == null) {
throw ExceptionUtils.toSqlState(new IllegalArgumentException("List cannot be null"));
}

this.array = list.toArray();
this.type = itemType;
this.typeName = itemTypeName;
}

@Override
public String getBaseTypeName() throws SQLException {
return Object.class.getName();
return typeName;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public void setAndGetClientInfoTest() throws SQLException {
@Test(groups = { "integration" })
public void createArrayOfTest() throws SQLException {
Connection localConnection = this.getJdbcConnection();
Array array = localConnection.createArrayOf("type-name", new Object[] { 1, 2, 3 });
Array array = localConnection.createArrayOf("Int8", new Object[] { 1, 2, 3 });
Assert.assertNotNull(array);
Assert.assertEquals(array.getArray(), new Object[] { 1, 2, 3 });
}
Expand Down

0 comments on commit fba928f

Please sign in to comment.