Search in sources :

Example 16 with Type

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());
}
Also used : Types(org.apache.iceberg.types.Types) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) TypeConverter.toPrestoType(com.facebook.presto.iceberg.TypeConverter.toPrestoType) Type(org.apache.iceberg.types.Type) TypeConverter.toIcebergType(com.facebook.presto.iceberg.TypeConverter.toIcebergType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Schema(org.apache.iceberg.Schema) ArrayList(java.util.ArrayList) Constraint(com.facebook.presto.spi.Constraint)

Example 17 with Type

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);
}
Also used : HashMap(java.util.HashMap) StructLike(org.apache.iceberg.StructLike) PartitionSpec(org.apache.iceberg.PartitionSpec) ByteBuffer(java.nio.ByteBuffer) PartitionField(org.apache.iceberg.PartitionField) Type(org.apache.iceberg.types.Type)

Example 18 with Type

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();
}
Also used : PartitionField(org.apache.iceberg.PartitionField) ArrayType(com.facebook.presto.common.type.ArrayType) Type(org.apache.iceberg.types.Type) RowType(com.facebook.presto.common.type.RowType) ManifestFile(org.apache.iceberg.ManifestFile) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Example 19 with Type

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));
    }
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) Type(org.apache.iceberg.types.Type)

Example 20 with Type

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);
}
Also used : Type(org.apache.iceberg.types.Type)

Aggregations

Type (org.apache.iceberg.types.Type)20 Schema (org.apache.iceberg.Schema)7 TypeConverter.toPrestoType (com.facebook.presto.iceberg.TypeConverter.toPrestoType)6 PartitionField (org.apache.iceberg.PartitionField)6 Types (org.apache.iceberg.types.Types)6 Test (org.junit.Test)6 ImmutableList (com.google.common.collect.ImmutableList)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 List (java.util.List)5 Map (java.util.Map)5 Table (org.apache.iceberg.Table)5 ArrayType (com.facebook.presto.common.type.ArrayType)3 RowType (com.facebook.presto.common.type.RowType)3 TypeManager (com.facebook.presto.common.type.TypeManager)3 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)3 Constraint (com.facebook.presto.spi.Constraint)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Objects.requireNonNull (java.util.Objects.requireNonNull)3