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());
}
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);
}
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);
}
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());
}
Aggregations