Search in sources :

Example 11 with MappedField

use of org.apache.iceberg.mapping.MappedField in project iceberg by apache.

the class ApplyNameMapping method list.

@Override
public Type list(GroupType list, Type elementType) {
    Preconditions.checkArgument(elementType != null, "List type must have element field");
    Type listElement = ParquetSchemaUtil.determineListElementType(list);
    MappedField field = nameMapping.find(currentPath());
    Types.GroupBuilder<GroupType> listBuilder = Types.buildGroup(list.getRepetition()).as(LogicalTypeAnnotation.listType());
    if (listElement.isRepetition(Type.Repetition.REPEATED)) {
        listBuilder.addFields(elementType);
    } else {
        listBuilder.repeatedGroup().addFields(elementType).named(list.getFieldName(0));
    }
    Type listType = listBuilder.named(list.getName());
    return field == null ? listType : listType.withId(field.id());
}
Also used : MappedField(org.apache.iceberg.mapping.MappedField) Types(org.apache.parquet.schema.Types) PrimitiveType(org.apache.parquet.schema.PrimitiveType) GroupType(org.apache.parquet.schema.GroupType) MessageType(org.apache.parquet.schema.MessageType) Type(org.apache.parquet.schema.Type) GroupType(org.apache.parquet.schema.GroupType)

Example 12 with MappedField

use of org.apache.iceberg.mapping.MappedField in project iceberg by apache.

the class ApplyNameMapping method record.

@Override
public TypeDescription record(TypeDescription record, List<String> names, List<TypeDescription> fields) {
    Preconditions.checkArgument(names.size() == fields.size(), "All fields must have names");
    MappedField field = nameMapping.find(currentPath());
    TypeDescription structType = TypeDescription.createStruct();
    for (int i = 0; i < fields.size(); i++) {
        String fieldName = names.get(i);
        TypeDescription fieldType = fields.get(i);
        if (fieldType != null) {
            structType.addField(fieldName, fieldType);
        }
    }
    return setId(structType, field);
}
Also used : MappedField(org.apache.iceberg.mapping.MappedField) TypeDescription(org.apache.orc.TypeDescription)

Example 13 with MappedField

use of org.apache.iceberg.mapping.MappedField in project iceberg by apache.

the class ApplyNameMapping method list.

@Override
public TypeDescription list(TypeDescription array, TypeDescription element) {
    Preconditions.checkArgument(element != null, "List type must have element type");
    MappedField field = nameMapping.find(currentPath());
    TypeDescription listType = TypeDescription.createList(element);
    return setId(listType, field);
}
Also used : MappedField(org.apache.iceberg.mapping.MappedField) TypeDescription(org.apache.orc.TypeDescription)

Example 14 with MappedField

use of org.apache.iceberg.mapping.MappedField in project trino by trinodb.

the class IcebergPageSourceProvider method setMissingFieldIds.

private static OrcColumn setMissingFieldIds(OrcColumn column, NameMapping nameMapping, List<String> qualifiedPath) {
    MappedField mappedField = nameMapping.find(qualifiedPath);
    ImmutableMap.Builder<String, String> attributes = ImmutableMap.<String, String>builder().putAll(column.getAttributes());
    if (mappedField != null && mappedField.id() != null) {
        attributes.put(ORC_ICEBERG_ID_KEY, String.valueOf(mappedField.id()));
    }
    return new OrcColumn(column.getPath(), column.getColumnId(), column.getColumnName(), column.getColumnType(), column.getOrcDataSourceId(), column.getNestedColumns().stream().map(nestedColumn -> {
        ImmutableList.Builder<String> nextQualifiedPath = ImmutableList.<String>builder().addAll(qualifiedPath);
        if (column.getColumnType().equals(OrcType.OrcTypeKind.LIST)) {
            // The Trino ORC reader uses "item" for list element names, but the NameMapper expects "element"
            nextQualifiedPath.add("element");
        } else {
            nextQualifiedPath.add(nestedColumn.getColumnName());
        }
        return setMissingFieldIds(nestedColumn, nameMapping, nextQualifiedPath.build());
    }).collect(toImmutableList()), attributes.buildOrThrow());
}
Also used : MappedField(org.apache.iceberg.mapping.MappedField) OrcColumn(io.trino.orc.OrcColumn) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

MappedField (org.apache.iceberg.mapping.MappedField)14 NameMapping (org.apache.iceberg.mapping.NameMapping)7 Test (org.junit.Test)7 Objects (java.util.Objects)5 Set (java.util.Set)5 ValidationException (org.apache.iceberg.exceptions.ValidationException)5 MappedFields (org.apache.iceberg.mapping.MappedFields)5 MappingUtil (org.apache.iceberg.mapping.MappingUtil)5 NameMappingParser (org.apache.iceberg.mapping.NameMappingParser)5 ImmutableList (org.apache.iceberg.relocated.com.google.common.collect.ImmutableList)5 Iterables (org.apache.iceberg.relocated.com.google.common.collect.Iterables)5 Sets (org.apache.iceberg.relocated.com.google.common.collect.Sets)5 Types (org.apache.iceberg.types.Types)5 Assert (org.junit.Assert)5 RunWith (org.junit.runner.RunWith)5 Parameterized (org.junit.runners.Parameterized)5 TypeDescription (org.apache.orc.TypeDescription)3 GroupType (org.apache.parquet.schema.GroupType)3 MessageType (org.apache.parquet.schema.MessageType)3 PrimitiveType (org.apache.parquet.schema.PrimitiveType)3