Search in sources :

Example 1 with PageListBuilder

use of com.facebook.presto.iceberg.util.PageListBuilder in project presto by prestodb.

the class FilesTable method buildPages.

private static List<Page> buildPages(ConnectorTableMetadata tableMetadata, ConnectorSession session, Table icebergTable, Optional<Long> snapshotId) {
    PageListBuilder pagesBuilder = forTable(tableMetadata);
    TableScan tableScan = getTableScan(TupleDomain.all(), snapshotId, icebergTable).includeColumnStats();
    Map<Integer, Type> idToTypeMap = getIdToTypeMap(icebergTable.schema());
    tableScan.planFiles().forEach(fileScanTask -> {
        DataFile dataFile = fileScanTask.file();
        pagesBuilder.beginRow();
        pagesBuilder.appendVarchar(dataFile.path().toString());
        pagesBuilder.appendVarchar(dataFile.format().name());
        pagesBuilder.appendBigint(dataFile.recordCount());
        pagesBuilder.appendBigint(dataFile.fileSizeInBytes());
        if (checkNonNull(dataFile.columnSizes(), pagesBuilder)) {
            pagesBuilder.appendIntegerBigintMap(dataFile.columnSizes());
        }
        if (checkNonNull(dataFile.valueCounts(), pagesBuilder)) {
            pagesBuilder.appendIntegerBigintMap(dataFile.valueCounts());
        }
        if (checkNonNull(dataFile.nullValueCounts(), pagesBuilder)) {
            pagesBuilder.appendIntegerBigintMap(dataFile.nullValueCounts());
        }
        if (checkNonNull(dataFile.lowerBounds(), pagesBuilder)) {
            pagesBuilder.appendIntegerVarcharMap(dataFile.lowerBounds().entrySet().stream().collect(toImmutableMap(Map.Entry<Integer, ByteBuffer>::getKey, entry -> Transforms.identity(idToTypeMap.get(entry.getKey())).toHumanString(Conversions.fromByteBuffer(idToTypeMap.get(entry.getKey()), entry.getValue())))));
        }
        if (checkNonNull(dataFile.upperBounds(), pagesBuilder)) {
            pagesBuilder.appendIntegerVarcharMap(dataFile.upperBounds().entrySet().stream().collect(toImmutableMap(Map.Entry<Integer, ByteBuffer>::getKey, entry -> Transforms.identity(idToTypeMap.get(entry.getKey())).toHumanString(Conversions.fromByteBuffer(idToTypeMap.get(entry.getKey()), entry.getValue())))));
        }
        if (checkNonNull(dataFile.keyMetadata(), pagesBuilder)) {
            pagesBuilder.appendVarbinary(Slices.wrappedBuffer(dataFile.keyMetadata()));
        }
        if (checkNonNull(dataFile.splitOffsets(), pagesBuilder)) {
            pagesBuilder.appendBigintArray(dataFile.splitOffsets());
        }
        pagesBuilder.endRow();
    });
    return pagesBuilder.build();
}
Also used : DataFile(org.apache.iceberg.DataFile) PageListBuilder(com.facebook.presto.iceberg.util.PageListBuilder) IcebergUtil.getTableScan(com.facebook.presto.iceberg.IcebergUtil.getTableScan) TableScan(org.apache.iceberg.TableScan) ArrayType(com.facebook.presto.common.type.ArrayType) Type(org.apache.iceberg.types.Type)

Example 2 with PageListBuilder

use of com.facebook.presto.iceberg.util.PageListBuilder in project presto by prestodb.

the class ManifestsTable method buildPages.

private static List<Page> buildPages(ConnectorTableMetadata tableMetadata, Table icebergTable, long snapshotId) {
    PageListBuilder pagesBuilder = PageListBuilder.forTable(tableMetadata);
    Snapshot snapshot = icebergTable.snapshot(snapshotId);
    if (snapshot == null) {
        throw new PrestoException(ICEBERG_INVALID_METADATA, format("Snapshot ID [%s] does not exist for table: %s", snapshotId, icebergTable));
    }
    Map<Integer, PartitionSpec> partitionSpecsById = icebergTable.specs();
    snapshot.allManifests().forEach(file -> {
        pagesBuilder.beginRow();
        pagesBuilder.appendVarchar(file.path());
        pagesBuilder.appendBigint(file.length());
        pagesBuilder.appendInteger(file.partitionSpecId());
        pagesBuilder.appendBigint(file.snapshotId());
        pagesBuilder.appendInteger(file.addedFilesCount());
        pagesBuilder.appendInteger(file.existingFilesCount());
        pagesBuilder.appendInteger(file.deletedFilesCount());
        writePartitionSummaries(pagesBuilder.nextColumn(), file.partitions(), partitionSpecsById.get(file.partitionSpecId()));
        pagesBuilder.endRow();
    });
    return pagesBuilder.build();
}
Also used : PageListBuilder(com.facebook.presto.iceberg.util.PageListBuilder) Snapshot(org.apache.iceberg.Snapshot) PrestoException(com.facebook.presto.spi.PrestoException) PartitionSpec(org.apache.iceberg.PartitionSpec)

Example 3 with PageListBuilder

use of com.facebook.presto.iceberg.util.PageListBuilder in project presto by prestodb.

the class SnapshotsTable method buildPages.

private static List<Page> buildPages(ConnectorTableMetadata tableMetadata, ConnectorSession session, Table icebergTable) {
    PageListBuilder pagesBuilder = PageListBuilder.forTable(tableMetadata);
    icebergTable.snapshots().forEach(snapshot -> {
        pagesBuilder.beginRow();
        pagesBuilder.appendTimestampTzMillis(snapshot.timestampMillis(), session.getSqlFunctionProperties().getTimeZoneKey());
        pagesBuilder.appendBigint(snapshot.snapshotId());
        if (checkNonNull(snapshot.parentId(), pagesBuilder)) {
            pagesBuilder.appendBigint(snapshot.parentId());
        }
        if (checkNonNull(snapshot.operation(), pagesBuilder)) {
            pagesBuilder.appendVarchar(snapshot.operation());
        }
        if (checkNonNull(snapshot.manifestListLocation(), pagesBuilder)) {
            pagesBuilder.appendVarchar(snapshot.manifestListLocation());
        }
        if (checkNonNull(snapshot.summary(), pagesBuilder)) {
            pagesBuilder.appendVarcharVarcharMap(snapshot.summary());
        }
        pagesBuilder.endRow();
    });
    return pagesBuilder.build();
}
Also used : PageListBuilder(com.facebook.presto.iceberg.util.PageListBuilder)

Aggregations

PageListBuilder (com.facebook.presto.iceberg.util.PageListBuilder)3 ArrayType (com.facebook.presto.common.type.ArrayType)1 IcebergUtil.getTableScan (com.facebook.presto.iceberg.IcebergUtil.getTableScan)1 PrestoException (com.facebook.presto.spi.PrestoException)1 DataFile (org.apache.iceberg.DataFile)1 PartitionSpec (org.apache.iceberg.PartitionSpec)1 Snapshot (org.apache.iceberg.Snapshot)1 TableScan (org.apache.iceberg.TableScan)1 Type (org.apache.iceberg.types.Type)1