Search in sources :

Example 1 with OrcType

use of com.facebook.presto.orc.metadata.OrcType in project presto by prestodb.

the class OrcRecordReader method createStreamReaders.

private static StreamReader[] createStreamReaders(OrcDataSource orcDataSource, List<OrcType> types, DateTimeZone hiveStorageTimeZone, Map<Integer, Type> includedColumns) {
    List<StreamDescriptor> streamDescriptors = createStreamDescriptor("", "", 0, types, orcDataSource).getNestedStreams();
    OrcType rowType = types.get(0);
    StreamReader[] streamReaders = new StreamReader[rowType.getFieldCount()];
    for (int columnId = 0; columnId < rowType.getFieldCount(); columnId++) {
        if (includedColumns.containsKey(columnId)) {
            StreamDescriptor streamDescriptor = streamDescriptors.get(columnId);
            streamReaders[columnId] = StreamReaders.createStreamReader(streamDescriptor, hiveStorageTimeZone);
        }
    }
    return streamReaders;
}
Also used : StreamReader(com.facebook.presto.orc.reader.StreamReader) OrcType(com.facebook.presto.orc.metadata.OrcType)

Example 2 with OrcType

use of com.facebook.presto.orc.metadata.OrcType in project presto by prestodb.

the class OrcRecordReader method createStreamDescriptor.

private static StreamDescriptor createStreamDescriptor(String parentStreamName, String fieldName, int typeId, List<OrcType> types, OrcDataSource dataSource) {
    OrcType type = types.get(typeId);
    if (!fieldName.isEmpty()) {
        parentStreamName += "." + fieldName;
    }
    ImmutableList.Builder<StreamDescriptor> nestedStreams = ImmutableList.builder();
    if (type.getOrcTypeKind() == OrcTypeKind.STRUCT) {
        for (int i = 0; i < type.getFieldCount(); ++i) {
            nestedStreams.add(createStreamDescriptor(parentStreamName, type.getFieldName(i), type.getFieldTypeIndex(i), types, dataSource));
        }
    } else if (type.getOrcTypeKind() == OrcTypeKind.LIST) {
        nestedStreams.add(createStreamDescriptor(parentStreamName, "item", type.getFieldTypeIndex(0), types, dataSource));
    } else if (type.getOrcTypeKind() == OrcTypeKind.MAP) {
        nestedStreams.add(createStreamDescriptor(parentStreamName, "key", type.getFieldTypeIndex(0), types, dataSource));
        nestedStreams.add(createStreamDescriptor(parentStreamName, "value", type.getFieldTypeIndex(1), types, dataSource));
    }
    return new StreamDescriptor(parentStreamName, typeId, fieldName, type.getOrcTypeKind(), dataSource, nestedStreams.build());
}
Also used : OrcType(com.facebook.presto.orc.metadata.OrcType) ImmutableList(com.google.common.collect.ImmutableList)

Example 3 with OrcType

use of com.facebook.presto.orc.metadata.OrcType in project presto by prestodb.

the class OrcStorageManager method getColumnInfoFromOrcColumnTypes.

private List<ColumnInfo> getColumnInfoFromOrcColumnTypes(List<String> orcColumnNames, List<OrcType> orcColumnTypes) {
    Type rowType = getType(orcColumnTypes, 0);
    if (orcColumnNames.size() != rowType.getTypeParameters().size()) {
        throw new PrestoException(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 : Type(com.facebook.presto.spi.type.Type) VarcharType.createUnboundedVarcharType(com.facebook.presto.spi.type.VarcharType.createUnboundedVarcharType) DecimalType(com.facebook.presto.spi.type.DecimalType) OrcType(com.facebook.presto.orc.metadata.OrcType) ImmutableList(com.google.common.collect.ImmutableList) ColumnInfo(com.facebook.presto.raptor.metadata.ColumnInfo) PrestoException(com.facebook.presto.spi.PrestoException)

Example 4 with OrcType

use of com.facebook.presto.orc.metadata.OrcType in project presto by prestodb.

the class OrcStorageManager method getType.

private Type getType(List<OrcType> types, int index) {
    OrcType type = types.get(index);
    switch(type.getOrcTypeKind()) {
        case BOOLEAN:
            return BOOLEAN;
        case LONG:
            return BIGINT;
        case DOUBLE:
            return DOUBLE;
        case STRING:
            return createUnboundedVarcharType();
        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.of(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.of(keyType), TypeSignatureParameter.of(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.of(new NamedTypeSignature(fieldNames.get(i), getType(types, type.getFieldTypeIndex(i)).getTypeSignature())));
            }
            return typeManager.getParameterizedType(StandardTypes.ROW, fieldTypes.build());
    }
    throw new PrestoException(RAPTOR_ERROR, "Unhandled ORC type: " + type);
}
Also used : TypeSignature(com.facebook.presto.spi.type.TypeSignature) NamedTypeSignature(com.facebook.presto.spi.type.NamedTypeSignature) OrcType(com.facebook.presto.orc.metadata.OrcType) TypeSignatureParameter(com.facebook.presto.spi.type.TypeSignatureParameter) ImmutableList(com.google.common.collect.ImmutableList) NamedTypeSignature(com.facebook.presto.spi.type.NamedTypeSignature) PrestoException(com.facebook.presto.spi.PrestoException)

Example 5 with OrcType

use of com.facebook.presto.orc.metadata.OrcType in project presto by prestodb.

the class StripeReader method getIncludedOrcColumns.

private static Set<Integer> getIncludedOrcColumns(List<OrcType> types, Set<Integer> includedColumns) {
    Set<Integer> includes = new LinkedHashSet<>();
    OrcType root = types.get(0);
    for (int includedColumn : includedColumns) {
        includeOrcColumnsRecursive(types, includes, root.getFieldTypeIndex(includedColumn));
    }
    return includes;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) OrcType(com.facebook.presto.orc.metadata.OrcType) Checkpoints.getDictionaryStreamCheckpoint(com.facebook.presto.orc.checkpoint.Checkpoints.getDictionaryStreamCheckpoint) StreamCheckpoint(com.facebook.presto.orc.checkpoint.StreamCheckpoint)

Aggregations

OrcType (com.facebook.presto.orc.metadata.OrcType)6 ImmutableList (com.google.common.collect.ImmutableList)3 Checkpoints.getDictionaryStreamCheckpoint (com.facebook.presto.orc.checkpoint.Checkpoints.getDictionaryStreamCheckpoint)2 StreamCheckpoint (com.facebook.presto.orc.checkpoint.StreamCheckpoint)2 PrestoException (com.facebook.presto.spi.PrestoException)2 StreamReader (com.facebook.presto.orc.reader.StreamReader)1 ColumnInfo (com.facebook.presto.raptor.metadata.ColumnInfo)1 DecimalType (com.facebook.presto.spi.type.DecimalType)1 NamedTypeSignature (com.facebook.presto.spi.type.NamedTypeSignature)1 Type (com.facebook.presto.spi.type.Type)1 TypeSignature (com.facebook.presto.spi.type.TypeSignature)1 TypeSignatureParameter (com.facebook.presto.spi.type.TypeSignatureParameter)1 VarcharType.createUnboundedVarcharType (com.facebook.presto.spi.type.VarcharType.createUnboundedVarcharType)1 LinkedHashSet (java.util.LinkedHashSet)1