Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] when use from-timestamp read data from snapshot, if time < earliestSnapshot time , no data return (#3904) #3910

Merged
merged 4 commits into from
Aug 11, 2024
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 @@ -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
Loading