Search in sources :

Example 6 with OrcType

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();
}
Also used : CharType.createCharType(io.trino.spi.type.CharType.createCharType) OrcType(io.trino.orc.metadata.OrcType) MapType(io.trino.spi.type.MapType) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) RowType(io.trino.spi.type.RowType) ArrayType(io.trino.spi.type.ArrayType) DecimalType(io.trino.spi.type.DecimalType) Type(io.trino.spi.type.Type) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) TrinoException(io.trino.spi.TrinoException) ColumnInfo(io.trino.plugin.raptor.legacy.metadata.ColumnInfo)

Example 7 with OrcType

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;
}
Also used : OrcColumnId(io.trino.orc.metadata.OrcColumnId) OrcType(io.trino.orc.metadata.OrcType) ArrayList(java.util.ArrayList)

Example 8 with OrcType

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();
}
Also used : OrcColumnId(io.trino.orc.metadata.OrcColumnId) Types(org.apache.iceberg.types.Types) StandardTypes(io.trino.spi.type.StandardTypes) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ArrayList(java.util.ArrayList) OrcType(io.trino.orc.metadata.OrcType) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List)

Example 9 with OrcType

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());
}
Also used : IntStream(java.util.stream.IntStream) DateTimeZone(org.joda.time.DateTimeZone) Slice(io.airlift.slice.Slice) ExceptionWrappingMetadataReader(io.trino.orc.metadata.ExceptionWrappingMetadataReader) Logger(io.airlift.log.Logger) AggregatedMemoryContext.newSimpleAggregatedMemoryContext(io.trino.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext) Type(io.trino.spi.type.Type) Page(io.trino.spi.Page) Throwables.throwIfUnchecked(com.google.common.base.Throwables.throwIfUnchecked) OrcTypeKind(io.trino.orc.metadata.OrcType.OrcTypeKind) Function(java.util.function.Function) SIZE_OF_BYTE(io.airlift.slice.SizeOf.SIZE_OF_BYTE) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Collectors.mapping(java.util.stream.Collectors.mapping) AggregatedMemoryContext(io.trino.memory.context.AggregatedMemoryContext) Math.toIntExact(java.lang.Math.toIntExact) PostScript(io.trino.orc.metadata.PostScript) OrcMetadataReader(io.trino.orc.metadata.OrcMetadataReader) MAGIC(io.trino.orc.metadata.PostScript.MAGIC) ENGLISH(java.util.Locale.ENGLISH) OrcChunkLoader(io.trino.orc.stream.OrcChunkLoader) ROOT_COLUMN(io.trino.orc.metadata.OrcColumnId.ROOT_COLUMN) OrcType(io.trino.orc.metadata.OrcType) OrcDecompressor.createOrcDecompressor(io.trino.orc.OrcDecompressor.createOrcDecompressor) ImmutableMap(com.google.common.collect.ImmutableMap) HiveWriterVersion(io.trino.orc.metadata.PostScript.HiveWriterVersion) Predicate(java.util.function.Predicate) OrcInputStream(io.trino.orc.stream.OrcInputStream) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) IOException(java.io.IOException) ColumnMetadata(io.trino.orc.metadata.ColumnMetadata) Math.min(java.lang.Math.min) UTC(org.joda.time.DateTimeZone.UTC) Collectors(java.util.stream.Collectors) CompressionKind(io.trino.orc.metadata.CompressionKind) Footer(io.trino.orc.metadata.Footer) Metadata(io.trino.orc.metadata.Metadata) DataSize(io.airlift.units.DataSize) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Optional(java.util.Optional) Collections(java.util.Collections) Joiner(com.google.common.base.Joiner) OrcColumnId(io.trino.orc.metadata.OrcColumnId) InputStream(java.io.InputStream) OrcType(io.trino.orc.metadata.OrcType)

Example 10 with OrcType

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);
    }
}
Also used : NamedTypeSignature(io.trino.spi.type.NamedTypeSignature) TypeSignature(io.trino.spi.type.TypeSignature) OrcType(io.trino.orc.metadata.OrcType) TypeSignatureParameter(io.trino.spi.type.TypeSignatureParameter) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) RowFieldName(io.trino.spi.type.RowFieldName) NamedTypeSignature(io.trino.spi.type.NamedTypeSignature) TrinoException(io.trino.spi.TrinoException)

Aggregations

OrcType (io.trino.orc.metadata.OrcType)10 OrcColumnId (io.trino.orc.metadata.OrcColumnId)8 ImmutableList (com.google.common.collect.ImmutableList)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)4 ArrayList (java.util.ArrayList)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 TrinoException (io.trino.spi.TrinoException)3 Type (io.trino.spi.type.Type)3 Slice (io.airlift.slice.Slice)2 AggregatedMemoryContext (io.trino.memory.context.AggregatedMemoryContext)2 ColumnMetadata (io.trino.orc.metadata.ColumnMetadata)2 OrcTypeKind (io.trino.orc.metadata.OrcType.OrcTypeKind)2 HiveWriterVersion (io.trino.orc.metadata.PostScript.HiveWriterVersion)2 ColumnStatistics (io.trino.orc.metadata.statistics.ColumnStatistics)2 List (java.util.List)2 Joiner (com.google.common.base.Joiner)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Predicates (com.google.common.base.Predicates)1 Throwables.throwIfUnchecked (com.google.common.base.Throwables.throwIfUnchecked)1