Skip to content

Commit 478a643

Browse files
authored
Merge pull request #2334 from gfunc/main
[jdbc-v2] bug fix for UInt32 UInt64 and Added support for Nested Type
2 parents bbdca2a + 9f09e7d commit 478a643

File tree

7 files changed

+295
-16
lines changed

7 files changed

+295
-16
lines changed

client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryStreamReader.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ public <T> T readValue(ClickHouseColumn column, Class<?> typeHint) throws IOExce
234234
return (T) readVariant(actualColumn);
235235
case Dynamic:
236236
return (T) readValue(actualColumn, typeHint);
237+
case Nested:
238+
return convertArray(readNested(actualColumn), typeHint);
237239
default:
238240
throw new IllegalArgumentException("Unsupported data type: " + actualColumn.getDataType());
239241
}
@@ -785,6 +787,33 @@ public Object[] readTuple(ClickHouseColumn column) throws IOException {
785787
return tuple;
786788
}
787789

790+
/**
791+
* Reads a nested into an ArrayValue object.
792+
* @param column - column information
793+
* @return array value
794+
* @throws IOException when IO error occurs
795+
*/
796+
public ArrayValue readNested(ClickHouseColumn column) throws IOException {
797+
int len = readVarInt(input);
798+
if (len == 0) {
799+
return new ArrayValue(Object[].class, 0);
800+
}
801+
802+
ArrayValue array;
803+
array = new ArrayValue(Object[].class, len);
804+
for (int i = 0; i < len; i++) {
805+
int tupleLen = column.getNestedColumns().size();
806+
Object[] tuple = new Object[tupleLen];
807+
for (int j = 0; j < tupleLen; j++) {
808+
tuple[j] = readValue(column.getNestedColumns().get(j));
809+
}
810+
811+
array.set(i, tuple);
812+
}
813+
814+
return array;
815+
}
816+
788817
public Object readVariant(ClickHouseColumn column) throws IOException {
789818
int ordNum = readByte();
790819
return readValue(column.getNestedColumns().get(ordNum));

client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,6 @@ private void addQueryParams(URIBuilder req, Map<String, String> chConfig, Map<St
556556
Collection<String> sessionRoles = (Collection<String>) requestConfig.getOrDefault(ClientConfigProperties.SESSION_DB_ROLES.getKey(),
557557
ClientConfigProperties.valuesFromCommaSeparated(chConfiguration.getOrDefault(ClientConfigProperties.SESSION_DB_ROLES.getKey(), "")));
558558
if (!sessionRoles.isEmpty()) {
559-
560559
sessionRoles.forEach(r -> req.addParameter(ClickHouseHttpProto.QPARAM_ROLE, r));
561560
}
562561

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,8 @@ public boolean executeImpl(String sql, StatementType type, QuerySettings setting
382382
//USE Database
383383
List<String> tokens = JdbcUtils.tokenizeSQL(sql);
384384
this.schema = tokens.get(1).replace("\"", "");
385-
LOG.debug("Changed statement schema {}", schema);
385+
connection.setSchema(schema);
386+
LOG.debug("Changed statement schema to {}", schema);
386387
return false;
387388
} else {
388389
executeUpdateImpl(sql, type, settings);

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,9 @@ public class JdbcUtils {
4040
private static Map<ClickHouseDataType, SQLType> generateTypeMap() {
4141
Map<ClickHouseDataType, SQLType> map = new TreeMap<>(); // TreeMap is used to sort the keys in natural order so FixedString will be before String :-) (type match should be more accurate)
4242
map.put(ClickHouseDataType.Int8, JDBCType.TINYINT);
43-
map.put(ClickHouseDataType.UInt8, JDBCType.TINYINT);
4443
map.put(ClickHouseDataType.Int16, JDBCType.SMALLINT);
45-
map.put(ClickHouseDataType.UInt16, JDBCType.SMALLINT);
4644
map.put(ClickHouseDataType.Int32, JDBCType.INTEGER);
47-
map.put(ClickHouseDataType.UInt32, JDBCType.INTEGER);
4845
map.put(ClickHouseDataType.Int64, JDBCType.BIGINT);
49-
map.put(ClickHouseDataType.UInt64, JDBCType.BIGINT);
5046
map.put(ClickHouseDataType.Float32, JDBCType.FLOAT);
5147
map.put(ClickHouseDataType.Float64, JDBCType.DOUBLE);
5248
map.put(ClickHouseDataType.Bool, JDBCType.BOOLEAN);

0 commit comments

Comments
 (0)