This is an automated email from the ASF dual-hosted git repository.
kerwin 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 08025dda7 [core] BranchManager lists branches in the order of create
time (#3155)
08025dda7 is described below
commit 08025dda7bd3daff8d2a34a7083a4ec4f62bb83b
Author: yuzelin <[email protected]>
AuthorDate: Sun Apr 7 13:57:05 2024 +0800
[core] BranchManager lists branches in the order of create time (#3155)
---
.../src/main/java/org/apache/paimon/utils/BranchManager.java | 12 +++++++++---
.../java/org/apache/paimon/table/system/TagsTableTest.java | 2 +-
2 files changed, 10 insertions(+), 4 deletions(-)
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 6564bd4e5..95034e05a 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
@@ -31,7 +31,9 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Comparator;
import java.util.List;
+import java.util.PriorityQueue;
import java.util.SortedMap;
import java.util.stream.Collectors;
@@ -164,7 +166,8 @@ public class BranchManager {
listVersionedFileStatus(fileIO, branchDirectory(),
BRANCH_PREFIX)
.map(status -> Pair.of(status.getPath(),
status.getModificationTime()))
.collect(Collectors.toList());
- List<TableBranch> branches = new ArrayList<>();
+ PriorityQueue<TableBranch> pq =
+ new
PriorityQueue<>(Comparator.comparingLong(TableBranch::getCreateTime));
for (Pair<Path, Long> path : paths) {
String branchName =
path.getLeft().getName().substring(BRANCH_PREFIX.length());
FileStoreTable branchTable =
@@ -175,10 +178,13 @@ public class BranchManager {
Snapshot snapshot = snapshotTags.firstKey();
List<String> tags = snapshotTags.get(snapshot);
checkArgument(tags.size() == 1);
- branches.add(
- new TableBranch(branchName, tags.get(0),
snapshot.id(), path.getValue()));
+ pq.add(new TableBranch(branchName, tags.get(0), snapshot.id(),
path.getValue()));
}
+ List<TableBranch> branches = new ArrayList<>(pq.size());
+ while (!pq.isEmpty()) {
+ branches.add(pq.poll());
+ }
return branches;
} catch (IOException e) {
throw new RuntimeException(e);
diff --git
a/paimon-core/src/test/java/org/apache/paimon/table/system/TagsTableTest.java
b/paimon-core/src/test/java/org/apache/paimon/table/system/TagsTableTest.java
index c754aa779..97beecd4d 100644
---
a/paimon-core/src/test/java/org/apache/paimon/table/system/TagsTableTest.java
+++
b/paimon-core/src/test/java/org/apache/paimon/table/system/TagsTableTest.java
@@ -110,7 +110,7 @@ class TagsTableTest extends TableTestBase {
if (tag.equals("2023-07-17")) {
return
Collections.singletonList("2023-07-17-branch1");
} else if (tag.equals("2023-07-18")) {
- return Arrays.asList("2023-07-18-branch2",
"2023-07-18-branch1");
+ return Arrays.asList("2023-07-18-branch1",
"2023-07-18-branch2");
} else {
return new ArrayList<>();
}