Search in sources :

Example 1 with Snapshot

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

the class HistoryTable method cursor.

@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession session, TupleDomain<Integer> constraint) {
    InMemoryRecordSet.Builder table = InMemoryRecordSet.builder(COLUMNS);
    Set<Long> ancestorIds = ImmutableSet.copyOf(SnapshotUtil.currentAncestors(icebergTable));
    for (HistoryEntry historyEntry : icebergTable.history()) {
        long snapshotId = historyEntry.snapshotId();
        Snapshot snapshot = icebergTable.snapshot(snapshotId);
        table.addRow(packDateTimeWithZone(historyEntry.timestampMillis(), session.getSqlFunctionProperties().getTimeZoneKey()), snapshotId, snapshot != null ? snapshot.parentId() : null, ancestorIds.contains(snapshotId));
    }
    return table.build().cursor();
}
Also used : Snapshot(org.apache.iceberg.Snapshot) HistoryEntry(org.apache.iceberg.HistoryEntry) InMemoryRecordSet(com.facebook.presto.spi.InMemoryRecordSet)

Example 2 with Snapshot

use of org.apache.iceberg.Snapshot 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 Snapshot

use of org.apache.iceberg.Snapshot in project drill by apache.

the class IcebergQueriesTest method testSelectSnapshotsMetadata.

@Test
public void testSelectSnapshotsMetadata() throws Exception {
    String query = "select * from dfs.tmp.`testAllTypes#snapshots`";
    List<Snapshot> snapshots = new ArrayList<>();
    table.snapshots().forEach(snapshots::add);
    JsonStringHashMap<Object, Object> summaryMap = new JsonStringHashMap<>();
    snapshots.get(0).summary().forEach((k, v) -> summaryMap.put(new Text(k.getBytes(StandardCharsets.UTF_8)), new Text(v.getBytes(StandardCharsets.UTF_8))));
    JsonStringHashMap<Object, Object> secondSummaryMap = new JsonStringHashMap<>();
    snapshots.get(1).summary().forEach((k, v) -> secondSummaryMap.put(new Text(k.getBytes(StandardCharsets.UTF_8)), new Text(v.getBytes(StandardCharsets.UTF_8))));
    testBuilder().sqlQuery(query).unOrdered().baselineColumns("committed_at", "snapshot_id", "parent_id", "operation", "manifest_list", "summary").baselineValues(LocalDateTime.ofInstant(Instant.ofEpochMilli(snapshots.get(0).timestampMillis()), ZoneId.of("UTC")), snapshots.get(0).snapshotId(), snapshots.get(0).parentId(), snapshots.get(0).operation(), snapshots.get(0).manifestListLocation(), summaryMap).baselineValues(LocalDateTime.ofInstant(Instant.ofEpochMilli(snapshots.get(1).timestampMillis()), ZoneId.of("UTC")), snapshots.get(1).snapshotId(), snapshots.get(1).parentId(), snapshots.get(1).operation(), snapshots.get(1).manifestListLocation(), secondSummaryMap).go();
}
Also used : Snapshot(org.apache.iceberg.Snapshot) ArrayList(java.util.ArrayList) TestBuilder.mapOfObject(org.apache.drill.test.TestBuilder.mapOfObject) Text(org.apache.drill.exec.util.Text) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) JsonStringHashMap(org.apache.drill.exec.util.JsonStringHashMap) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test)

Example 4 with Snapshot

use of org.apache.iceberg.Snapshot in project hive by apache.

the class HiveCreateReplaceTableTest method testCreateTableTxnAndAppend.

@Test
public void testCreateTableTxnAndAppend() {
    Assert.assertFalse("Table should not exist", catalog.tableExists(TABLE_IDENTIFIER));
    Transaction txn = catalog.newCreateTableTransaction(TABLE_IDENTIFIER, SCHEMA, SPEC, tableLocation, Maps.newHashMap());
    AppendFiles append = txn.newAppend();
    DataFile dataFile = DataFiles.builder(SPEC).withPath("/path/to/data-a.parquet").withFileSizeInBytes(0).withRecordCount(1).build();
    append.appendFile(dataFile);
    append.commit();
    txn.commitTransaction();
    Table table = catalog.loadTable(TABLE_IDENTIFIER);
    Snapshot snapshot = table.currentSnapshot();
    Assert.assertTrue("Table should have one manifest file", snapshot.allManifests().size() == 1);
}
Also used : DataFile(org.apache.iceberg.DataFile) Snapshot(org.apache.iceberg.Snapshot) Table(org.apache.iceberg.Table) Transaction(org.apache.iceberg.Transaction) AppendFiles(org.apache.iceberg.AppendFiles) Test(org.junit.Test)

Aggregations

Snapshot (org.apache.iceberg.Snapshot)4 Test (org.junit.Test)2 PageListBuilder (com.facebook.presto.iceberg.util.PageListBuilder)1 InMemoryRecordSet (com.facebook.presto.spi.InMemoryRecordSet)1 PrestoException (com.facebook.presto.spi.PrestoException)1 ArrayList (java.util.ArrayList)1 JsonStringHashMap (org.apache.drill.exec.util.JsonStringHashMap)1 Text (org.apache.drill.exec.util.Text)1 ClusterTest (org.apache.drill.test.ClusterTest)1 TestBuilder.mapOfObject (org.apache.drill.test.TestBuilder.mapOfObject)1 AppendFiles (org.apache.iceberg.AppendFiles)1 DataFile (org.apache.iceberg.DataFile)1 HistoryEntry (org.apache.iceberg.HistoryEntry)1 PartitionSpec (org.apache.iceberg.PartitionSpec)1 Table (org.apache.iceberg.Table)1 Transaction (org.apache.iceberg.Transaction)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1