use of org.apache.iceberg.StructLike in project presto by prestodb.
the class IcebergSplitSource method getPartitionKeys.
private static Map<Integer, String> getPartitionKeys(FileScanTask scanTask) {
StructLike partition = scanTask.file().partition();
PartitionSpec spec = scanTask.spec();
Map<PartitionField, Integer> fieldToIndex = getIdentityPartitions(spec);
Map<Integer, String> partitionKeys = new HashMap<>();
fieldToIndex.forEach((field, index) -> {
int id = field.sourceId();
Type type = spec.schema().findType(id);
Class<?> javaClass = type.typeId().javaClass();
Object value = partition.get(index, javaClass);
if (value == null) {
partitionKeys.put(id, null);
} else {
String partitionValue;
if (type.typeId() == FIXED || type.typeId() == BINARY) {
// this is safe because Iceberg PartitionData directly wraps the byte array
partitionValue = new String(((ByteBuffer) value).array(), UTF_8);
} else {
partitionValue = value.toString();
}
partitionKeys.put(id, partitionValue);
}
});
return Collections.unmodifiableMap(partitionKeys);
}
Aggregations