use of org.apache.iceberg.types.Type in project presto by prestodb.
the class IcebergAbstractMetadata method toIcebergSchema.
protected static Schema toIcebergSchema(List<ColumnMetadata> columns) {
List<Types.NestedField> icebergColumns = new ArrayList<>();
for (ColumnMetadata column : columns) {
if (!column.isHidden()) {
int index = icebergColumns.size();
Type type = toIcebergType(column.getType());
Types.NestedField field = column.isNullable() ? Types.NestedField.optional(index, column.getName(), type, column.getComment()) : Types.NestedField.required(index, column.getName(), type, column.getComment());
icebergColumns.add(field);
}
}
Type icebergSchema = Types.StructType.of(icebergColumns);
AtomicInteger nextFieldId = new AtomicInteger(1);
icebergSchema = TypeUtil.assignFreshIds(icebergSchema, nextFieldId::getAndIncrement);
return new Schema(icebergSchema.asStructType().fields());
}
use of org.apache.iceberg.types.Type 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);
}
use of org.apache.iceberg.types.Type in project presto by prestodb.
the class ManifestsTable method writePartitionSummaries.
private static void writePartitionSummaries(BlockBuilder arrayBlockBuilder, List<ManifestFile.PartitionFieldSummary> summaries, PartitionSpec partitionSpec) {
BlockBuilder singleArrayWriter = arrayBlockBuilder.beginBlockEntry();
for (int i = 0; i < summaries.size(); i++) {
ManifestFile.PartitionFieldSummary summary = summaries.get(i);
PartitionField field = partitionSpec.fields().get(i);
Type nestedType = partitionSpec.partitionType().fields().get(i).type();
BlockBuilder rowBuilder = singleArrayWriter.beginBlockEntry();
BOOLEAN.writeBoolean(rowBuilder, summary.containsNull());
VARCHAR.writeString(rowBuilder, field.transform().toHumanString(Conversions.fromByteBuffer(nestedType, summary.lowerBound())));
VARCHAR.writeString(rowBuilder, field.transform().toHumanString(Conversions.fromByteBuffer(nestedType, summary.upperBound())));
singleArrayWriter.closeEntry();
}
arrayBlockBuilder.closeEntry();
}
use of org.apache.iceberg.types.Type in project presto by prestodb.
the class FilesTable method populateIdToTypeMap.
private static void populateIdToTypeMap(Types.NestedField field, ImmutableMap.Builder<Integer, Type> idToTypeMap) {
Type type = field.type();
idToTypeMap.put(field.fieldId(), type);
if (type instanceof Type.NestedType) {
type.asNestedType().fields().forEach(child -> populateIdToTypeMap(child, idToTypeMap));
}
}
use of org.apache.iceberg.types.Type in project drill by apache.
the class IcebergColumnConverterFactory method getColumnMetadata.
public static ColumnMetadata getColumnMetadata(Types.NestedField field) {
Type type = field.type();
String name = field.name();
return getColumnMetadata(name, type, field.isOptional() ? TypeProtos.DataMode.OPTIONAL : TypeProtos.DataMode.REQUIRED);
}
Aggregations