Search in sources :

Example 1 with PageListBuilder

use of io.trino.plugin.iceberg.util.PageListBuilder in project trino by trinodb.

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 TrinoException(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(io.trino.plugin.iceberg.util.PageListBuilder) Snapshot(org.apache.iceberg.Snapshot) TrinoException(io.trino.spi.TrinoException) PartitionSpec(org.apache.iceberg.PartitionSpec)

Example 2 with PageListBuilder

use of io.trino.plugin.iceberg.util.PageListBuilder in project trino by trinodb.

the class PropertiesTable method buildPages.

private static List<Page> buildPages(ConnectorTableMetadata tableMetadata, Table icebergTable) {
    PageListBuilder pagesBuilder = PageListBuilder.forTable(tableMetadata);
    icebergTable.properties().entrySet().forEach(prop -> {
        pagesBuilder.beginRow();
        pagesBuilder.appendVarchar(prop.getKey());
        pagesBuilder.appendVarchar(prop.getValue());
        pagesBuilder.endRow();
    });
    return pagesBuilder.build();
}
Also used : PageListBuilder(io.trino.plugin.iceberg.util.PageListBuilder)

Example 3 with PageListBuilder

use of io.trino.plugin.iceberg.util.PageListBuilder in project trino by trinodb.

the class SnapshotsTable method buildPages.

private static List<Page> buildPages(ConnectorTableMetadata tableMetadata, ConnectorSession session, Table icebergTable) {
    PageListBuilder pagesBuilder = PageListBuilder.forTable(tableMetadata);
    TimeZoneKey timeZoneKey = session.getTimeZoneKey();
    icebergTable.snapshots().forEach(snapshot -> {
        pagesBuilder.beginRow();
        pagesBuilder.appendTimestampTzMillis(snapshot.timestampMillis(), timeZoneKey);
        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(io.trino.plugin.iceberg.util.PageListBuilder) TimeZoneKey(io.trino.spi.type.TimeZoneKey)

Example 4 with PageListBuilder

use of io.trino.plugin.iceberg.util.PageListBuilder in project trino by trinodb.

the class FilesTable method buildPages.

private static List<Page> buildPages(ConnectorTableMetadata tableMetadata, Table icebergTable, long snapshotId) {
    PageListBuilder pagesBuilder = PageListBuilder.forTable(tableMetadata);
    Map<Integer, Type> idToTypeMapping = getIcebergIdToTypeMapping(icebergTable.schema());
    TableScan tableScan = icebergTable.newScan().useSnapshot(snapshotId).includeColumnStats();
    tableScan.planFiles().forEach(fileScanTask -> {
        DataFile dataFile = fileScanTask.file();
        pagesBuilder.beginRow();
        pagesBuilder.appendInteger(dataFile.content().id());
        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.nanValueCounts(), pagesBuilder)) {
            pagesBuilder.appendIntegerBigintMap(dataFile.nanValueCounts());
        }
        if (checkNonNull(dataFile.lowerBounds(), pagesBuilder)) {
            pagesBuilder.appendIntegerVarcharMap(dataFile.lowerBounds().entrySet().stream().collect(toImmutableMap(Map.Entry<Integer, ByteBuffer>::getKey, entry -> Transforms.identity(idToTypeMapping.get(entry.getKey())).toHumanString(Conversions.fromByteBuffer(idToTypeMapping.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(idToTypeMapping.get(entry.getKey())).toHumanString(Conversions.fromByteBuffer(idToTypeMapping.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());
        }
        if (checkNonNull(dataFile.equalityFieldIds(), pagesBuilder)) {
            pagesBuilder.appendIntegerArray(dataFile.equalityFieldIds());
        }
        pagesBuilder.endRow();
    });
    return pagesBuilder.build();
}
Also used : DataFile(org.apache.iceberg.DataFile) PageListBuilder(io.trino.plugin.iceberg.util.PageListBuilder) TableScan(org.apache.iceberg.TableScan) ArrayType(io.trino.spi.type.ArrayType) Type(org.apache.iceberg.types.Type) TypeSignature.mapType(io.trino.spi.type.TypeSignature.mapType)

Aggregations

PageListBuilder (io.trino.plugin.iceberg.util.PageListBuilder)4 TrinoException (io.trino.spi.TrinoException)1 ArrayType (io.trino.spi.type.ArrayType)1 TimeZoneKey (io.trino.spi.type.TimeZoneKey)1 TypeSignature.mapType (io.trino.spi.type.TypeSignature.mapType)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