Search in sources :

Example 1 with PrimitiveField

use of io.prestosql.parquet.PrimitiveField in project hetu-core by openlookeng.

the class ParquetColumnIOConverter method constructField.

public static Optional<Field> constructField(Type type, ColumnIO columnIO) {
    if (columnIO == null) {
        return Optional.empty();
    }
    boolean required = columnIO.getType().getRepetition() != OPTIONAL;
    int repetitionLevel = columnRepetitionLevel(columnIO);
    int definitionLevel = columnDefinitionLevel(columnIO);
    if (ROW.equals(type.getTypeSignature().getBase())) {
        GroupColumnIO groupColumnIO = (GroupColumnIO) columnIO;
        List<Type> parameters = type.getTypeParameters();
        ImmutableList.Builder<Optional<Field>> fieldsBuilder = ImmutableList.builder();
        List<TypeSignatureParameter> fields = type.getTypeSignature().getParameters();
        boolean structHasParameters = false;
        for (int i = 0; i < fields.size(); i++) {
            NamedTypeSignature namedTypeSignature = fields.get(i).getNamedTypeSignature();
            String name = namedTypeSignature.getName().get().toLowerCase(Locale.ENGLISH);
            Optional<Field> field = constructField(parameters.get(i), lookupColumnByName(groupColumnIO, name));
            structHasParameters |= field.isPresent();
            fieldsBuilder.add(field);
        }
        if (structHasParameters) {
            return Optional.of(new GroupField(type, repetitionLevel, definitionLevel, required, fieldsBuilder.build()));
        }
        return Optional.empty();
    }
    if (MAP.equals(type.getTypeSignature().getBase())) {
        GroupColumnIO groupColumnIO = (GroupColumnIO) columnIO;
        MapType mapType = (MapType) type;
        GroupColumnIO keyValueColumnIO = getMapKeyValueColumn(groupColumnIO);
        if (keyValueColumnIO.getChildrenCount() != 2) {
            return Optional.empty();
        }
        Optional<Field> keyField = constructField(mapType.getKeyType(), keyValueColumnIO.getChild(0));
        Optional<Field> valueField = constructField(mapType.getValueType(), keyValueColumnIO.getChild(1));
        return Optional.of(new GroupField(type, repetitionLevel, definitionLevel, required, ImmutableList.of(keyField, valueField)));
    }
    if (ARRAY.equals(type.getTypeSignature().getBase())) {
        GroupColumnIO groupColumnIO = (GroupColumnIO) columnIO;
        List<Type> types = type.getTypeParameters();
        if (groupColumnIO.getChildrenCount() != 1) {
            return Optional.empty();
        }
        Optional<Field> field = constructField(types.get(0), getArrayElementColumn(groupColumnIO.getChild(0)));
        return Optional.of(new GroupField(type, repetitionLevel, definitionLevel, required, ImmutableList.of(field)));
    }
    PrimitiveColumnIO primitiveColumnIO = (PrimitiveColumnIO) columnIO;
    RichColumnDescriptor column = new RichColumnDescriptor(primitiveColumnIO.getColumnDescriptor(), columnIO.getType().asPrimitiveType());
    return Optional.of(new PrimitiveField(type, repetitionLevel, definitionLevel, required, column, primitiveColumnIO.getId()));
}
Also used : Optional(java.util.Optional) ImmutableList(com.google.common.collect.ImmutableList) GroupField(io.prestosql.parquet.GroupField) RichColumnDescriptor(io.prestosql.parquet.RichColumnDescriptor) NamedTypeSignature(io.prestosql.spi.type.NamedTypeSignature) MapType(io.prestosql.spi.type.MapType) PrimitiveColumnIO(org.apache.parquet.io.PrimitiveColumnIO) GroupField(io.prestosql.parquet.GroupField) PrimitiveField(io.prestosql.parquet.PrimitiveField) Field(io.prestosql.parquet.Field) MapType(io.prestosql.spi.type.MapType) Type(io.prestosql.spi.type.Type) GroupColumnIO(org.apache.parquet.io.GroupColumnIO) TypeSignatureParameter(io.prestosql.spi.type.TypeSignatureParameter) PrimitiveField(io.prestosql.parquet.PrimitiveField)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 Field (io.prestosql.parquet.Field)1 GroupField (io.prestosql.parquet.GroupField)1 PrimitiveField (io.prestosql.parquet.PrimitiveField)1 RichColumnDescriptor (io.prestosql.parquet.RichColumnDescriptor)1 MapType (io.prestosql.spi.type.MapType)1 NamedTypeSignature (io.prestosql.spi.type.NamedTypeSignature)1 Type (io.prestosql.spi.type.Type)1 TypeSignatureParameter (io.prestosql.spi.type.TypeSignatureParameter)1 Optional (java.util.Optional)1 GroupColumnIO (org.apache.parquet.io.GroupColumnIO)1 PrimitiveColumnIO (org.apache.parquet.io.PrimitiveColumnIO)1