Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -391,14 +391,14 @@ public Plan readChanges() {
groupByPartFiles(plan.files(FileKind.DELETE));
Map<BinaryRow, Map<Integer, List<DataFileMeta>>> dataFiles =
groupByPartFiles(plan.files(FileKind.ADD));

return toChangesPlan(true, plan, plan.snapshot().id() - 1, beforeFiles, dataFiles);
Snapshot beforeSnapshot = snapshotManager.snapshot(plan.snapshot().id() - 1);
return toChangesPlan(true, plan, beforeSnapshot, beforeFiles, dataFiles);
}

private Plan toChangesPlan(
boolean isStreaming,
FileStoreScan.Plan plan,
long beforeSnapshotId,
Snapshot beforeSnapshot,
Map<BinaryRow, Map<Integer, List<DataFileMeta>>> beforeFiles,
Map<BinaryRow, Map<Integer, List<DataFileMeta>>> dataFiles) {
Snapshot snapshot = plan.snapshot();
Expand All @@ -416,7 +416,7 @@ private Plan toChangesPlan(
Map<Pair<BinaryRow, Integer>, List<IndexFileMeta>> beforDeletionIndexFilesMap =
deletionVectors
? indexFileHandler.scan(
beforeSnapshotId, DELETION_VECTORS_INDEX, beforeFiles.keySet())
beforeSnapshot, DELETION_VECTORS_INDEX, beforeFiles.keySet())
: Collections.emptyMap();
Map<Pair<BinaryRow, Integer>, List<IndexFileMeta>> deletionIndexFilesMap =
deletionVectors
Expand Down Expand Up @@ -476,7 +476,7 @@ public Plan readIncrementalDiff(Snapshot before) {
groupByPartFiles(plan.files(FileKind.ADD));
Map<BinaryRow, Map<Integer, List<DataFileMeta>>> beforeFiles =
groupByPartFiles(scan.withSnapshot(before).plan().files(FileKind.ADD));
return toChangesPlan(false, plan, before.id(), beforeFiles, dataFiles);
return toChangesPlan(false, plan, before, beforeFiles, dataFiles);
}

private RecordComparator partitionComparator() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,34 @@ public void testTimeTravelReadWithSnapshotExpiration() throws Exception {
.containsExactlyInAnyOrder(Row.of(1, 11, 111), Row.of(2, 22, 222));
}

@Test
public void testIncrementBetweenReadWithSnapshotExpiration() throws Exception {
String tableName = "T";
batchSql(String.format("INSERT INTO %s VALUES (1, 11, 111)", tableName));

paimonTable(tableName).createTag("tag1", 1);

batchSql(String.format("INSERT INTO %s VALUES (2, 22, 222)", tableName));
paimonTable(tableName).createTag("tag2", 2);
batchSql(String.format("INSERT INTO %s VALUES (3, 33, 333)", tableName));
paimonTable(tableName).createTag("tag3", 3);

// expire snapshot 1
Map<String, String> expireOptions = new HashMap<>();
expireOptions.put(CoreOptions.SNAPSHOT_NUM_RETAINED_MAX.key(), "1");
expireOptions.put(CoreOptions.SNAPSHOT_NUM_RETAINED_MIN.key(), "1");
FileStoreTable table = (FileStoreTable) paimonTable(tableName);
table.copy(expireOptions).newCommit("").expireSnapshots();
assertThat(table.snapshotManager().snapshotCount()).isEqualTo(1);

assertThat(
batchSql(
String.format(
"SELECT * FROM %s /*+ OPTIONS('incremental-between' = 'tag1,tag2', 'deletion-vectors.enabled' = 'true') */",
tableName)))
.containsExactlyInAnyOrder(Row.of(2, 22, 222));
}

@Test
public void testSortSpillMerge() {
sql(
Expand Down
Loading