in java/clickhouse-client/src/main/java/com/epam/deltix/clickhouse/DescribeTableResultSetExtractor.java [39:91]
public List<ColumnDeclaration> extractData(ResultSet rs) throws SQLException, DataAccessException {
List<ColumnDeclaration> columns = new ArrayList<>();
//Map<String, ColumnDeclaration> nestedColumns = new HashMap<>();
String currentNestedColumn = null;
List<ColumnDeclaration> currentNestedDataType = null;
while (rs.next()) {
String name = rs.getString(FIELD_NAME);
String type = rs.getString(FIELD_TYPE);
SqlDataType dataType = ParseProcessor.parseDataType(type);
String defaultExpression = rs.getString(FIELD_DEFAULT_EXPRESSION);
// check for nested
String[] nameParts = name.split("\\.");
if (nameParts.length == 1) {
if (currentNestedColumn != null) {
columns.add(new ColumnDeclaration(currentNestedColumn, new NestedDataType(currentNestedDataType)));
currentNestedColumn = null;
currentNestedDataType = null;
}
ColumnDeclaration column = new ColumnDeclaration(name, dataType, defaultExpression);
columns.add(column);
} else if (nameParts.length == 2) {
if (currentNestedColumn == null) {
currentNestedColumn = nameParts[0];
currentNestedDataType = new ArrayList<>();
} else if (!currentNestedColumn.equals(nameParts[0])) {
columns.add(new ColumnDeclaration(currentNestedColumn, new NestedDataType(currentNestedDataType)));
currentNestedColumn = nameParts[0];
currentNestedDataType = new ArrayList<>();
}
if (!(dataType instanceof ArraySqlType))
throw new IllegalStateException(String.format("Unexpected data type for nested column '%s' (type)", name));
SqlDataType elementType = ((ArraySqlType)dataType).getElementType();
currentNestedDataType.add(new ColumnDeclaration(nameParts[1], elementType, defaultExpression));
} else {
throw new IllegalStateException(String.format("Incorrect column name syntax '%s'", name));
}
}
if (currentNestedColumn != null) {
columns.add(new ColumnDeclaration(currentNestedColumn, new NestedDataType(currentNestedDataType)));
}
return columns;
}