mxm commented on code in PR #19115:
URL: https://github.com/apache/iceberg/pull/19115#discussion_r4754027326
##########
flink/v2.3/flink/src/test/java/org/apache/iceberg/flink/source/lookup/TestIcebergLookup.java:
##########
@@ -134,6 +139,112 @@ void lookupReaderReadsPinnedSnapshot() throws Exception {
.containsExactlyInAnyOrder(1L, 2L, 3L, 6L);
}
+ @Test
+ void lookupReaderReadsDelta() throws Exception {
+ Table table = createTableWithRecords();
+ long firstSnapshot = table.currentSnapshot().snapshotId();
+
+ appendRecords(table, ImmutableList.of(record(6L, "frank", "D")));
+ long secondSnapshot = table.currentSnapshot().snapshotId();
+
+ IcebergLookupReader reader = lookupReader(table, ImmutableList.of(),
false);
+
+ assertThat(readDeltaIds(reader, firstSnapshot, secondSnapshot))
+ .as("A delta read must only return the rows added in the range")
+ .containsExactly(6L);
+ }
+
+ @Test
+ void lookupReaderDetectsAppendOnlyRange() throws Exception {
+ Table table = createTableWithRecords();
+ long firstSnapshot = table.currentSnapshot().snapshotId();
+
+ appendRecords(table, ImmutableList.of(record(6L, "frank", "D")));
+ long secondSnapshot = table.currentSnapshot().snapshotId();
+
+ IcebergLookupReader reader = lookupReader(table, ImmutableList.of(),
false);
+
+ assertThat(reader.isAppendOnlyRange(firstSnapshot, secondSnapshot))
+ .as("A range that only appends rows can be applied to a loaded cache")
+ .isTrue();
+ }
+
+ @Test
+ void lookupReaderRejectsRangeWithDeletes() throws Exception {
+ Table table = createTableWithRecords();
+ long firstSnapshot = table.currentSnapshot().snapshotId();
+
+ appendRecords(table, ImmutableList.of(record(6L, "frank", "D")));
+ table.newDelete().deleteFromRowFilter(Expressions.equal("id",
6L)).commit();
+
+ IcebergLookupReader reader = lookupReader(table, ImmutableList.of(),
false);
+
+ assertThat(reader.isAppendOnlyRange(firstSnapshot,
table.currentSnapshot().snapshotId()))
+ .as("A range that deletes rows cannot be applied to a loaded cache")
+ .isFalse();
+ }
+
+ @Test
+ void lookupReaderAcceptsRangeAfterExistingDeletes() throws Exception {
+ Table table = createTableWithRecords();
+ addEqualityDelete(table, 2L);
+ long deleteSnapshot = table.currentSnapshot().snapshotId();
+
+ appendRecords(table, ImmutableList.of(record(6L, "frank", "D")));
+ long appendSnapshot = table.currentSnapshot().snapshotId();
+
+ IcebergLookupReader reader = lookupReader(table, ImmutableList.of(),
false);
+
+ assertThat(reader.isAppendOnlyRange(deleteSnapshot, appendSnapshot))
+ .as("Delete files added before the range do not prevent applying an
append")
+ .isTrue();
+ }
+
+ @Test
+ void lookupReaderRejectsRangeThatIsNotAnAncestor() throws Exception {
+ Table table = createTableWithRecords();
+ long firstSnapshot = table.currentSnapshot().snapshotId();
+
+ appendRecords(table, ImmutableList.of(record(6L, "frank", "D")));
+ long secondSnapshot = table.currentSnapshot().snapshotId();
+
+ IcebergLookupReader reader = lookupReader(table, ImmutableList.of(),
false);
+
+ assertThat(reader.isAppendOnlyRange(secondSnapshot, firstSnapshot))
+ .as("A range that goes back in history cannot be applied to a loaded
cache")
+ .isFalse();
Review Comment:
Could we add a test where the cached snapshot is expired before the reload?
##########
flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/source/lookup/IcebergFullCachingLookupFunction.java:
##########
@@ -270,11 +290,53 @@ private synchronized void loadCache() throws IOException {
LOG.info(
"IcebergFullCachingLookupFunction loading finished, snapshot={},
rows={}, cost={} ms",
- snapshot == null ? "none" : snapshotId,
+ snapshotId,
rowCnt,
loadTimeMs);
}
+ private void loadDelta(long fromExclusive, long toInclusive) throws
IOException {
+ InMemoryLookupCache delta = new InMemoryLookupCache();
+ long start = System.currentTimeMillis();
+ long rowCnt;
+ try (CloseableIterable<RowData> rows = reader.readDelta(fromExclusive,
toInclusive)) {
+ rowCnt = fillCache(rows, delta);
+ }
+
+ long loadTimeMs = System.currentTimeMillis() - start;
+
+ if (closed) {
+ return;
+ }
+
+ this.cache = cache.mergedWith(delta);
+ this.currentSnapshotId = toInclusive;
+ this.cachedRecords = cachedRecords + rowCnt;
+ this.latestLoadTimeMs = loadTimeMs;
+ loadCounter.inc();
Review Comment:
+1 for adding a counters for full reloads, incremental updates, and errors.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]