diff --git a/paimon-core/src/main/java/org/apache/paimon/utils/BranchManager.java b/paimon-core/src/main/java/org/apache/paimon/utils/BranchManager.java index 1677633d2ad17..eb0feaaaf42a1 100644 --- a/paimon-core/src/main/java/org/apache/paimon/utils/BranchManager.java +++ b/paimon-core/src/main/java/org/apache/paimon/utils/BranchManager.java @@ -236,15 +236,23 @@ public List branches() { fileIO, new Path(getBranchPath(tablePath, branchName))); SortedMap> snapshotTags = branchTable.tagManager().tags(); + Long earliestSnapshotId = branchTable.snapshotManager().earliestSnapshotId(); if (snapshotTags.isEmpty()) { - Long earliestSnapshotId = branchTable.snapshotManager().earliestSnapshotId(); + // Create based on snapshotId. branches.add(new TableBranch(branchName, earliestSnapshotId, path.getValue())); } else { Snapshot snapshot = snapshotTags.firstKey(); - List tags = snapshotTags.get(snapshot); - checkArgument(tags.size() == 1); - branches.add( - new TableBranch(branchName, tags.get(0), snapshot.id(), path.getValue())); + if (earliestSnapshotId == snapshot.id()) { + List tags = snapshotTags.get(snapshot); + checkArgument(tags.size() == 1); + branches.add( + new TableBranch( + branchName, tags.get(0), snapshot.id(), path.getValue())); + } else { + // Create based on snapshotId. + branches.add( + new TableBranch(branchName, earliestSnapshotId, path.getValue())); + } } }