use of org.apache.iceberg.HistoryEntry 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();
}
use of org.apache.iceberg.HistoryEntry in project hive by apache.
the class TestHiveIcebergTimeTravel method testSelectAsOfVersion.
@Test
public void testSelectAsOfVersion() throws IOException, InterruptedException {
Table table = prepareTableWithVersions(2);
HistoryEntry first = table.history().get(0);
List<Object[]> rows = shell.executeStatement("SELECT * FROM customers FOR SYSTEM_VERSION AS OF " + first.snapshotId());
Assert.assertEquals(3, rows.size());
HistoryEntry second = table.history().get(1);
rows = shell.executeStatement("SELECT * FROM customers FOR SYSTEM_VERSION AS OF " + second.snapshotId());
Assert.assertEquals(4, rows.size());
AssertHelpers.assertThrows("should throw exception", IllegalArgumentException.class, "Cannot find snapshot with ID 1234", () -> {
shell.executeStatement("SELECT * FROM customers FOR SYSTEM_VERSION AS OF 1234");
});
}
use of org.apache.iceberg.HistoryEntry in project hive by apache.
the class TestHiveIcebergTimeTravel method timestampAfterSnapshot.
/**
* Get the timestamp string which we can use in the queries. The timestamp will be after the given snapshot
* and before the next one
* @param table The table which we want to query
* @param snapshotPosition The position of the last snapshot we want to see in the query results
* @return The timestamp which we can use in the queries
*/
private String timestampAfterSnapshot(Table table, int snapshotPosition) {
List<HistoryEntry> history = table.history();
long snapshotTime = history.get(snapshotPosition).timestampMillis();
long time = snapshotTime + 100;
if (history.size() > snapshotPosition + 1) {
time = snapshotTime + ((history.get(snapshotPosition + 1).timestampMillis() - snapshotTime) / 2);
}
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS000000");
return simpleDateFormat.format(new Date(time));
}
use of org.apache.iceberg.HistoryEntry in project drill by apache.
the class IcebergQueriesTest method testSelectHistoryMetadata.
@Test
public void testSelectHistoryMetadata() throws Exception {
String query = "select * from dfs.tmp.`testAllTypes#history`";
List<HistoryEntry> entries = table.history();
testBuilder().sqlQuery(query).unOrdered().baselineColumns("made_current_at", "snapshot_id", "parent_id", "is_current_ancestor").baselineValues(LocalDateTime.ofInstant(Instant.ofEpochMilli(entries.get(0).timestampMillis()), ZoneId.of("UTC")), entries.get(0).snapshotId(), null, true).baselineValues(LocalDateTime.ofInstant(Instant.ofEpochMilli(entries.get(1).timestampMillis()), ZoneId.of("UTC")), entries.get(1).snapshotId(), entries.get(0).snapshotId(), true).go();
}
Aggregations