Skip to content

Commit

Permalink
[core] when use from-timestamp read data from snapshot, if time < ear…
Browse files Browse the repository at this point in the history
…liestSnapshot time , no data return (#3904) (#3910)
  • Loading branch information
chunji96 authored Aug 11, 2024
1 parent 0c0a083 commit 8d76bdb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,16 @@ public Result scan(SnapshotReader reader) {
|| endTimestamp < earliestSnapshot.timeMillis()) {
return new NoSnapshot();
}
// in org.apache.paimon.utils.SnapshotManager.earlierOrEqualTimeMills
// 1. if earliestSnapshotId or latestSnapshotId is null startingSnapshotId will be null
// 2. if earliestSnapShot.timeMillis() > startTimestamp startingSnapshotId will be
// earliestSnapShotId
// if earliestSnapShot.timeMillis() > startTimestamp we should include the earliestSnapShot
// data
Long startSnapshotId =
(startingSnapshotId == null) ? earliestSnapshot.id() - 1 : startingSnapshotId;
(startingSnapshotId == null || earliestSnapshot.timeMillis() > startTimestamp)
? earliestSnapshot.id() - 1
: startingSnapshotId;
Snapshot endSnapshot = snapshotManager.earlierOrEqualTimeMills(endTimestamp);
Long endSnapshotId = (endSnapshot == null) ? latestSnapshot.id() : endSnapshot.id();
IncrementalStartingScanner incrementalStartingScanner =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,9 @@ private Snapshot changelogOrSnapshot(long snapshotId) {
return null;
}

if (snapshot(earliest).timeMillis() > timestampMills) {
return null;
Snapshot earliestSnapShot = snapshot(earliest);
if (earliestSnapShot.timeMillis() > timestampMills) {
return earliestSnapShot;
}
Snapshot finalSnapshot = null;
while (earliest <= latest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ public void testTravelToOldSchema() throws Exception {
public void testTravelToNonExistedTimestamp() {
sql("CREATE TABLE t (k INT, v STRING)");
sql("INSERT INTO t VALUES(1, 'hello'), (2, 'world')");
assertThat(sql("SELECT * FROM t FOR SYSTEM_TIME AS OF TIMESTAMP '1900-01-01 00:00:00'"))
.isEmpty();
assertThat(
sql("SELECT * FROM t FOR SYSTEM_TIME AS OF TIMESTAMP '1900-01-01 00:00:00'")
.toString())
.isEqualTo("[+I[1, hello], +I[2, world]]");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void testTravelToNonExistedTimestamp() {
.option("path", tablePath1.toString())
.option(CoreOptions.SCAN_TIMESTAMP_MILLIS.key(), 0)
.load();
assertThat(dataset.collectAsList()).isEmpty();
assertThat(dataset.collectAsList().toString()).isEqualTo("[[1,2,1], [5,6,3]]");
}

@Test
Expand Down

0 comments on commit 8d76bdb

Please sign in to comment.