use of io.trino.orc.metadata.OrcType in project trino by trinodb.
the class RaptorStorageManager method getColumnInfoFromOrcColumnTypes.
private List<ColumnInfo> getColumnInfoFromOrcColumnTypes(List<String> orcColumnNames, ColumnMetadata<OrcType> orcColumnTypes) {
Type rowType = getType(orcColumnTypes, ROOT_COLUMN);
if (orcColumnNames.size() != rowType.getTypeParameters().size()) {
throw new TrinoException(RAPTOR_ERROR, "Column names and types do not match");
}
ImmutableList.Builder<ColumnInfo> list = ImmutableList.builder();
for (int i = 0; i < orcColumnNames.size(); i++) {
list.add(new ColumnInfo(Long.parseLong(orcColumnNames.get(i)), rowType.getTypeParameters().get(i)));
}
return list.build();
}
use of io.trino.orc.metadata.OrcType in project trino by trinodb.
the class TypeConverter method toOrcListType.
private static List<OrcType> toOrcListType(int nextFieldTypeIndex, Types.ListType listType, Map<String, String> attributes) {
nextFieldTypeIndex++;
Map<String, String> elementAttributes = ImmutableMap.<String, String>builder().put(ORC_ICEBERG_ID_KEY, Integer.toString(listType.elementId())).put(ORC_ICEBERG_REQUIRED_KEY, Boolean.toString(listType.isElementRequired())).buildOrThrow();
List<OrcType> itemTypes = toOrcType(nextFieldTypeIndex, listType.elementType(), elementAttributes);
List<OrcType> orcTypes = new ArrayList<>();
orcTypes.add(new OrcType(OrcTypeKind.LIST, ImmutableList.of(new OrcColumnId(nextFieldTypeIndex)), ImmutableList.of("item"), Optional.empty(), Optional.empty(), Optional.empty(), attributes));
orcTypes.addAll(itemTypes);
return orcTypes;
}
use of io.trino.orc.metadata.OrcType in project trino by trinodb.
the class TypeConverter method toOrcStructType.
private static List<OrcType> toOrcStructType(int nextFieldTypeIndex, Types.StructType structType, Map<String, String> attributes) {
nextFieldTypeIndex++;
List<OrcColumnId> fieldTypeIndexes = new ArrayList<>();
List<String> fieldNames = new ArrayList<>();
List<List<OrcType>> fieldTypesList = new ArrayList<>();
for (Types.NestedField field : structType.fields()) {
fieldTypeIndexes.add(new OrcColumnId(nextFieldTypeIndex));
fieldNames.add(field.name());
Map<String, String> fieldAttributes = ImmutableMap.<String, String>builder().put(ORC_ICEBERG_ID_KEY, Integer.toString(field.fieldId())).put(ORC_ICEBERG_REQUIRED_KEY, Boolean.toString(field.isRequired())).buildOrThrow();
List<OrcType> fieldOrcTypes = toOrcType(nextFieldTypeIndex, field.type(), fieldAttributes);
fieldTypesList.add(fieldOrcTypes);
nextFieldTypeIndex += fieldOrcTypes.size();
}
ImmutableList.Builder<OrcType> orcTypes = ImmutableList.builder();
orcTypes.add(new OrcType(OrcTypeKind.STRUCT, fieldTypeIndexes, fieldNames, Optional.empty(), Optional.empty(), Optional.empty(), attributes));
fieldTypesList.forEach(orcTypes::addAll);
return orcTypes.build();
}
use of io.trino.orc.metadata.OrcType in project trino by trinodb.
the class OrcReader method createOrcColumn.
private static OrcColumn createOrcColumn(String parentStreamName, String fieldName, OrcColumnId columnId, ColumnMetadata<OrcType> types, OrcDataSourceId orcDataSourceId) {
String path = fieldName.isEmpty() ? parentStreamName : parentStreamName + "." + fieldName;
OrcType orcType = types.get(columnId);
List<OrcColumn> nestedColumns = ImmutableList.of();
if (orcType.getOrcTypeKind() == OrcTypeKind.STRUCT) {
nestedColumns = IntStream.range(0, orcType.getFieldCount()).mapToObj(fieldId -> createOrcColumn(path, orcType.getFieldName(fieldId), orcType.getFieldTypeIndex(fieldId), types, orcDataSourceId)).collect(toImmutableList());
} else if (orcType.getOrcTypeKind() == OrcTypeKind.LIST) {
nestedColumns = ImmutableList.of(createOrcColumn(path, "item", orcType.getFieldTypeIndex(0), types, orcDataSourceId));
} else if (orcType.getOrcTypeKind() == OrcTypeKind.MAP) {
nestedColumns = ImmutableList.of(createOrcColumn(path, "key", orcType.getFieldTypeIndex(0), types, orcDataSourceId), createOrcColumn(path, "value", orcType.getFieldTypeIndex(1), types, orcDataSourceId));
} else if (orcType.getOrcTypeKind() == OrcTypeKind.UNION) {
nestedColumns = IntStream.range(0, orcType.getFieldCount()).mapToObj(fieldId -> createOrcColumn(path, "field" + fieldId, orcType.getFieldTypeIndex(fieldId), types, orcDataSourceId)).collect(toImmutableList());
}
return new OrcColumn(path, columnId, fieldName, orcType.getOrcTypeKind(), orcDataSourceId, nestedColumns, orcType.getAttributes());
}
use of io.trino.orc.metadata.OrcType in project trino by trinodb.
the class RaptorStorageManager method getType.
private Type getType(ColumnMetadata<OrcType> types, OrcColumnId columnId) {
OrcType type = types.get(columnId);
switch(type.getOrcTypeKind()) {
case BOOLEAN:
return BOOLEAN;
case LONG:
return BIGINT;
case DOUBLE:
return DOUBLE;
case STRING:
return createUnboundedVarcharType();
case VARCHAR:
return createVarcharType(type.getLength().get());
case CHAR:
return createCharType(type.getLength().get());
case BINARY:
return VARBINARY;
case DECIMAL:
return DecimalType.createDecimalType(type.getPrecision().get(), type.getScale().get());
case LIST:
TypeSignature elementType = getType(types, type.getFieldTypeIndex(0)).getTypeSignature();
return typeManager.getParameterizedType(StandardTypes.ARRAY, ImmutableList.of(TypeSignatureParameter.typeParameter(elementType)));
case MAP:
TypeSignature keyType = getType(types, type.getFieldTypeIndex(0)).getTypeSignature();
TypeSignature valueType = getType(types, type.getFieldTypeIndex(1)).getTypeSignature();
return typeManager.getParameterizedType(StandardTypes.MAP, ImmutableList.of(TypeSignatureParameter.typeParameter(keyType), TypeSignatureParameter.typeParameter(valueType)));
case STRUCT:
List<String> fieldNames = type.getFieldNames();
ImmutableList.Builder<TypeSignatureParameter> fieldTypes = ImmutableList.builder();
for (int i = 0; i < type.getFieldCount(); i++) {
fieldTypes.add(TypeSignatureParameter.namedTypeParameter(new NamedTypeSignature(Optional.of(new RowFieldName(fieldNames.get(i))), getType(types, type.getFieldTypeIndex(i)).getTypeSignature())));
}
return typeManager.getParameterizedType(StandardTypes.ROW, fieldTypes.build());
default:
throw new TrinoException(RAPTOR_ERROR, "Unhandled ORC type: " + type);
}
}
Aggregations