Search in sources :

Example 1 with AppendFiles

use of org.apache.iceberg.AppendFiles in project presto by prestodb.

the class IcebergAbstractMetadata method finishInsert.

@Override
public Optional<ConnectorOutputMetadata> finishInsert(ConnectorSession session, ConnectorInsertTableHandle insertHandle, Collection<Slice> fragments, Collection<ComputedStatistics> computedStatistics) {
    if (fragments.isEmpty()) {
        transaction.commitTransaction();
        return Optional.empty();
    }
    IcebergWritableTableHandle table = (IcebergWritableTableHandle) insertHandle;
    org.apache.iceberg.Table icebergTable = transaction.table();
    List<CommitTaskData> commitTasks = fragments.stream().map(slice -> commitTaskCodec.fromJson(slice.getBytes())).collect(toImmutableList());
    Type[] partitionColumnTypes = icebergTable.spec().fields().stream().map(field -> field.transform().getResultType(icebergTable.schema().findType(field.sourceId()))).toArray(Type[]::new);
    AppendFiles appendFiles = transaction.newFastAppend();
    for (CommitTaskData task : commitTasks) {
        DataFiles.Builder builder = DataFiles.builder(icebergTable.spec()).withPath(task.getPath()).withFileSizeInBytes(task.getFileSizeInBytes()).withFormat(table.getFileFormat()).withMetrics(task.getMetrics().metrics());
        if (!icebergTable.spec().fields().isEmpty()) {
            String partitionDataJson = task.getPartitionDataJson().orElseThrow(() -> new VerifyException("No partition data for partitioned table"));
            builder.withPartition(PartitionData.fromJson(partitionDataJson, partitionColumnTypes));
        }
        appendFiles.appendFile(builder.build());
    }
    appendFiles.commit();
    transaction.commitTransaction();
    return Optional.of(new HiveWrittenPartitions(commitTasks.stream().map(CommitTaskData::getPath).collect(toImmutableList())));
}
Also used : JsonCodec(com.facebook.airlift.json.JsonCodec) TypeUtil(org.apache.iceberg.types.TypeUtil) Types(org.apache.iceberg.types.Types) ComputedStatistics(com.facebook.presto.spi.statistics.ComputedStatistics) AppendFiles(org.apache.iceberg.AppendFiles) Collections.singletonList(java.util.Collections.singletonList) SchemaTableName(com.facebook.presto.spi.SchemaTableName) DataFiles(org.apache.iceberg.DataFiles) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) PartitionFields.toPartitionFields(com.facebook.presto.iceberg.PartitionFields.toPartitionFields) FILE_FORMAT_PROPERTY(com.facebook.presto.iceberg.IcebergTableProperties.FILE_FORMAT_PROPERTY) SystemTable(com.facebook.presto.spi.SystemTable) TypeConverter.toPrestoType(com.facebook.presto.iceberg.TypeConverter.toPrestoType) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PARTITIONING_PROPERTY(com.facebook.presto.iceberg.IcebergTableProperties.PARTITIONING_PROPERTY) Set(java.util.Set) Schema(org.apache.iceberg.Schema) PartitionSpecParser(org.apache.iceberg.PartitionSpecParser) SchemaParser(org.apache.iceberg.SchemaParser) ConnectorSession(com.facebook.presto.spi.ConnectorSession) Type(org.apache.iceberg.types.Type) List(java.util.List) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) TypeConverter.toIcebergType(com.facebook.presto.iceberg.TypeConverter.toIcebergType) NOT_SUPPORTED(com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED) Optional(java.util.Optional) HiveWrittenPartitions(com.facebook.presto.hive.HiveWrittenPartitions) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) Logger(com.facebook.airlift.log.Logger) Slice(io.airlift.slice.Slice) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) ConnectorOutputTableHandle(com.facebook.presto.spi.ConnectorOutputTableHandle) PrestoException(com.facebook.presto.spi.PrestoException) ArrayList(java.util.ArrayList) IcebergUtil.getFileFormat(com.facebook.presto.iceberg.IcebergUtil.getFileFormat) IcebergUtil.resolveSnapshotIdByName(com.facebook.presto.iceberg.IcebergUtil.resolveSnapshotIdByName) ImmutableList(com.google.common.collect.ImmutableList) TypeManager(com.facebook.presto.common.type.TypeManager) Objects.requireNonNull(java.util.Objects.requireNonNull) IcebergUtil.getColumns(com.facebook.presto.iceberg.IcebergUtil.getColumns) ConnectorInsertTableHandle(com.facebook.presto.spi.ConnectorInsertTableHandle) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) VerifyException(com.google.common.base.VerifyException) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) ConnectorOutputMetadata(com.facebook.presto.spi.connector.ConnectorOutputMetadata) ConnectorTableLayout(com.facebook.presto.spi.ConnectorTableLayout) Constraint(com.facebook.presto.spi.Constraint) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) ColumnHandle(com.facebook.presto.spi.ColumnHandle) Transaction(org.apache.iceberg.Transaction) ConnectorNewTableLayout(com.facebook.presto.spi.ConnectorNewTableLayout) AppendFiles(org.apache.iceberg.AppendFiles) DataFiles(org.apache.iceberg.DataFiles) HiveWrittenPartitions(com.facebook.presto.hive.HiveWrittenPartitions) TypeConverter.toPrestoType(com.facebook.presto.iceberg.TypeConverter.toPrestoType) Type(org.apache.iceberg.types.Type) TypeConverter.toIcebergType(com.facebook.presto.iceberg.TypeConverter.toIcebergType) VerifyException(com.google.common.base.VerifyException)

Aggregations

JsonCodec (com.facebook.airlift.json.JsonCodec)1 Logger (com.facebook.airlift.log.Logger)1 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)1 TypeManager (com.facebook.presto.common.type.TypeManager)1 HiveWrittenPartitions (com.facebook.presto.hive.HiveWrittenPartitions)1 FILE_FORMAT_PROPERTY (com.facebook.presto.iceberg.IcebergTableProperties.FILE_FORMAT_PROPERTY)1 PARTITIONING_PROPERTY (com.facebook.presto.iceberg.IcebergTableProperties.PARTITIONING_PROPERTY)1 IcebergUtil.getColumns (com.facebook.presto.iceberg.IcebergUtil.getColumns)1 IcebergUtil.getFileFormat (com.facebook.presto.iceberg.IcebergUtil.getFileFormat)1 IcebergUtil.resolveSnapshotIdByName (com.facebook.presto.iceberg.IcebergUtil.resolveSnapshotIdByName)1 PartitionFields.toPartitionFields (com.facebook.presto.iceberg.PartitionFields.toPartitionFields)1 TypeConverter.toIcebergType (com.facebook.presto.iceberg.TypeConverter.toIcebergType)1 TypeConverter.toPrestoType (com.facebook.presto.iceberg.TypeConverter.toPrestoType)1 ColumnHandle (com.facebook.presto.spi.ColumnHandle)1 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)1 ConnectorInsertTableHandle (com.facebook.presto.spi.ConnectorInsertTableHandle)1 ConnectorNewTableLayout (com.facebook.presto.spi.ConnectorNewTableLayout)1 ConnectorOutputTableHandle (com.facebook.presto.spi.ConnectorOutputTableHandle)1 ConnectorSession (com.facebook.presto.spi.ConnectorSession)1 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)1