Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ public <T> T readValue(ClickHouseColumn column, Class<?> typeHint) throws IOExce
return (T) readVariant(actualColumn);
case Dynamic:
return (T) readValue(actualColumn, typeHint);
case Nested:
return convertArray(readNested(actualColumn), typeHint);
default:
throw new IllegalArgumentException("Unsupported data type: " + actualColumn.getDataType());
}
Expand Down Expand Up @@ -785,6 +787,33 @@ public Object[] readTuple(ClickHouseColumn column) throws IOException {
return tuple;
}

/**
* Reads a nested into an ArrayValue object.
* @param column - column information
* @return array value
* @throws IOException when IO error occurs
*/
public ArrayValue readNested(ClickHouseColumn column) throws IOException {
int len = readVarInt(input);
if (len == 0) {
return new ArrayValue(Object[].class, 0);
}

ArrayValue array;
array = new ArrayValue(Object[].class, len);
for (int i = 0; i < len; i++) {
int tupleLen = column.getNestedColumns().size();
Object[] tuple = new Object[tupleLen];
for (int j = 0; j < tupleLen; j++) {
tuple[j] = readValue(column.getNestedColumns().get(j));
}

array.set(i, tuple);
}

return array;
}

public Object readVariant(ClickHouseColumn column) throws IOException {
int ordNum = readByte();
return readValue(column.getNestedColumns().get(ordNum));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,6 @@ private void addQueryParams(URIBuilder req, Map<String, String> chConfig, Map<St
Collection<String> sessionRoles = (Collection<String>) requestConfig.getOrDefault(ClientConfigProperties.SESSION_DB_ROLES.getKey(),
ClientConfigProperties.valuesFromCommaSeparated(chConfiguration.getOrDefault(ClientConfigProperties.SESSION_DB_ROLES.getKey(), "")));
if (!sessionRoles.isEmpty()) {

sessionRoles.forEach(r -> req.addParameter(ClickHouseHttpProto.QPARAM_ROLE, r));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ public boolean executeImpl(String sql, StatementType type, QuerySettings setting
//USE Database
List<String> tokens = JdbcUtils.tokenizeSQL(sql);
this.schema = tokens.get(1).replace("\"", "");
LOG.debug("Changed statement schema {}", schema);
connection.setSchema(schema);
LOG.debug("Changed statement schema to {}", schema);
return false;
} else {
executeUpdateImpl(sql, type, settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,9 @@ public class JdbcUtils {
private static Map<ClickHouseDataType, SQLType> generateTypeMap() {
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)
map.put(ClickHouseDataType.Int8, JDBCType.TINYINT);
map.put(ClickHouseDataType.UInt8, JDBCType.TINYINT);
map.put(ClickHouseDataType.Int16, JDBCType.SMALLINT);
map.put(ClickHouseDataType.UInt16, JDBCType.SMALLINT);
map.put(ClickHouseDataType.Int32, JDBCType.INTEGER);
map.put(ClickHouseDataType.UInt32, JDBCType.INTEGER);
map.put(ClickHouseDataType.Int64, JDBCType.BIGINT);
map.put(ClickHouseDataType.UInt64, JDBCType.BIGINT);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that UInt64 is not mapped to anything, right? I think it is not correct.
UInt64 is not Other just because it is represent by BigInteger. This mapping is mainly for metadata.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right in some way.
But UInt32 and UInt64 are both OTHER because JDBC type is valid only for signed numbers.
Would you please remove UInt8, UInt16, UInt32 and UInt64 from this mapping? We should return whatever BinaryStreamReader returns.

Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all Uint had been removed

map.put(ClickHouseDataType.Float32, JDBCType.FLOAT);
map.put(ClickHouseDataType.Float64, JDBCType.DOUBLE);
map.put(ClickHouseDataType.Bool, JDBCType.BOOLEAN);
Expand Down
Loading
Loading