This is an automated email from the ASF dual-hosted git repository.
JingsongLi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git
The following commit(s) were added to refs/heads/master by this push:
new 9a68ca5b36 [core] Skip manual-only tag groups in preview time travel
(#10284)
9a68ca5b36 is described below
commit 9a68ca5b36ad46867e2b94fbc283b0cf7d7fdbe5
Author: YangJie <[email protected]>
AuthorDate: Mon Oct 5 09:25:12 2026 -0400
[core] Skip manual-only tag groups in preview time travel (#10284)
---
.../java/org/apache/paimon/tag/TagPreview.java | 17 ++-------
.../java/org/apache/paimon/tag/TagPreviewTest.java | 44 ++++++++++++++++++++++
2 files changed, 47 insertions(+), 14 deletions(-)
diff --git a/paimon-core/src/main/java/org/apache/paimon/tag/TagPreview.java
b/paimon-core/src/main/java/org/apache/paimon/tag/TagPreview.java
index 60edb03e08..48902a46aa 100644
--- a/paimon-core/src/main/java/org/apache/paimon/tag/TagPreview.java
+++ b/paimon-core/src/main/java/org/apache/paimon/tag/TagPreview.java
@@ -27,9 +27,7 @@ import org.apache.paimon.utils.TagManager;
import javax.annotation.Nullable;
import java.time.LocalDateTime;
-import java.util.ArrayList;
import java.util.Comparator;
-import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -84,9 +82,10 @@ public class TagPreview {
return singletonMap(SCAN_SNAPSHOT_ID.key(),
String.valueOf(snapshot.id()));
}
+ // filter by tag name first: a snapshot may carry only manually
created tags
Optional<String> findTag =
- tagManager.tags().values().stream()
- .map(this::toOneAutoTag)
+ tagManager.tags(periodHandler::isAutoTag).values().stream()
+ .map(TagAutoCreation::checkAndGetOneAutoTag)
.filter(t -> t.compareTo(tag) <= 0)
.max(Comparator.naturalOrder());
if (findTag.isPresent()) {
@@ -95,14 +94,4 @@ public class TagPreview {
throw new RuntimeException("Cannot find snapshot or tag for tag name:
" + tag);
}
-
- private String toOneAutoTag(List<String> tags) {
- List<String> autoTags = new ArrayList<>();
- for (String tag : tags) {
- if (periodHandler.isAutoTag(tag)) {
- autoTags.add(tag);
- }
- }
- return TagAutoCreation.checkAndGetOneAutoTag(autoTags);
- }
}
diff --git
a/paimon-core/src/test/java/org/apache/paimon/tag/TagPreviewTest.java
b/paimon-core/src/test/java/org/apache/paimon/tag/TagPreviewTest.java
index 36a4cf569f..7945e2d63c 100644
--- a/paimon-core/src/test/java/org/apache/paimon/tag/TagPreviewTest.java
+++ b/paimon-core/src/test/java/org/apache/paimon/tag/TagPreviewTest.java
@@ -38,6 +38,7 @@ import static org.apache.paimon.CoreOptions.SCAN_TAG_NAME;
import static org.apache.paimon.CoreOptions.SNAPSHOT_NUM_RETAINED_MAX;
import static org.apache.paimon.CoreOptions.SNAPSHOT_NUM_RETAINED_MIN;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
/** Test for {@link TagPreview}. */
public class TagPreviewTest extends PrimaryKeyTableTestBase {
@@ -91,6 +92,49 @@ public class TagPreviewTest extends PrimaryKeyTableTestBase {
.containsAllEntriesOf(singletonMap(SCAN_TAG_NAME.key(),
"2023-07-18"));
}
+ @Test
+ public void testTimeTravelSkipsManualOnlySnapshots() throws Exception {
+ TagPreview preview = create();
+ TableCommitImpl commit =
table.newCommit(commitUser).ignoreEmptyCommit(false);
+
+ // the only tag is a manual one and no snapshot is early enough, so
nothing resolves
+ commit.commit(new ManifestCommittable(0,
utcMills("2023-07-18T12:12:00")));
+ table.createTag("my-manual-tag", 1);
+
+ assertThatThrownBy(() -> preview.timeTravel(table, "2023-07-01"))
+ .isInstanceOf(RuntimeException.class)
+ .hasMessageContaining("Cannot find snapshot or tag");
+
+ commit.close();
+ }
+
+ @Test
+ public void testTimeTravelResolvesAutoTagDespiteManualOnlyGroup() throws
Exception {
+ TagPreview preview = create();
+ Map<String, String> dynamicOptions = new HashMap<>();
+ dynamicOptions.put(SNAPSHOT_NUM_RETAINED_MIN.key(), "3");
+ dynamicOptions.put(SNAPSHOT_NUM_RETAINED_MAX.key(), "3");
+ TableCommitImpl commit =
+
table.copy(dynamicOptions).newCommit(commitUser).ignoreEmptyCommit(false);
+
+ // snapshot 1 has an auto tag, snapshot 2 only a manual tag that sorts
after it
+ commit.commit(new ManifestCommittable(0,
utcMills("2023-07-18T12:12:00")));
+ commit.commit(new ManifestCommittable(0,
utcMills("2023-07-19T12:12:00")));
+ table.createTag("2023-07-18", 1);
+ table.createTag("2023-07-18-backup", 2);
+
+ // expire snapshots 1 and 2, so no retained snapshot is early enough
and the lookup
+ // falls back to the tags
+ for (int i = 0; i < 5; i++) {
+ commit.commit(new ManifestCommittable(0,
utcMills("2023-07-21T12:12:00")));
+ }
+
+ assertThat(preview.timeTravel(table, "2023-07-19"))
+ .containsAllEntriesOf(singletonMap(SCAN_TAG_NAME.key(),
"2023-07-18"));
+
+ commit.close();
+ }
+
private TagPreview create() {
Options options = new Options();
options.set(METASTORE_TAG_TO_PARTITION_PREVIEW,
TagCreationMode.WATERMARK);