rdblue commented on a change in pull request #750: Add time-travel methods
(asOfTime,useSnapshot) in IcebergGenerics
URL: https://github.com/apache/incubator-iceberg/pull/750#discussion_r371381016
##########
File path: data/src/test/java/org/apache/iceberg/data/TestLocalScan.java
##########
@@ -215,28 +275,90 @@ public void testFullScan() {
Iterable<Record> results = IcebergGenerics.read(sharedTable).build();
Set<Record> expected = Sets.newHashSet();
- expected.addAll(file1Records);
- expected.addAll(file2Records);
- expected.addAll(file3Records);
+ expected.addAll(file1SecondSnapshotRecords);
+ expected.addAll(file2SecondSnapshotRecords);
+ expected.addAll(file3SecondSnapshotRecords);
+
+ Set<Record> records = Sets.newHashSet(results);
+ Assert.assertEquals("Should produce correct number of records",
+ expected.size(), records.size());
+ Assert.assertEquals("Random record set should match",
+ Sets.newHashSet(expected), records);
+ Assert.assertNotNull(records.stream().findFirst().get().getField("id"));
+ Assert.assertNotNull(records.stream().findFirst().get().getField("data"));
+ }
+
+ @Test
+ public void testUnknownSnapshotId() {
+ exceptionRule.expect(IllegalArgumentException.class);
+ exceptionRule.expectMessage(startsWith("Cannot find snapshot with ID "));
+
+ Long minSnapshotId = sharedTable.history().stream().map(h ->
h.snapshotId()).min(Long::compareTo).get();
+
+ IcebergGenerics.read(sharedTable)
+ .useSnapshot(/* unknown snapshot id */ minSnapshotId - 1);
+ }
+
+ @Test
+ public void testAsOfTimeOlderThanFirstSnapshot() {
+ exceptionRule.expect(IllegalArgumentException.class);
+ exceptionRule.expectMessage(startsWith("Cannot find a snapshot older than
"));
+
+ IcebergGenerics.read(sharedTable)
+ .asOfTime(/* older than first snapshot */
sharedTable.history().get(0).timestampMillis() - 1);
+ }
+
+ @Test
+ public void testUseSnapshot() {
Review comment:
The table setup is done in a `@Before` method, so the table is recreated for
each test case. Since the first snapshot is only used by this test case and
`testAsOfTime`, you might consider moving the overwrite into a helper method.
That would require fewer changes to existing test methods.
If you did that, then this would start with `overwriteExistingData()` and
then you could test that you can read the old data or the overwrite snapshot.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]