LinMingQiang commented on code in PR #3787:
URL: https://github.com/apache/paimon/pull/3787#discussion_r1705114731
##########
paimon-core/src/main/java/org/apache/paimon/utils/SnapshotManager.java:
##########
@@ -696,6 +698,50 @@ private static int findPreviousOrEqualSnapshot(
return -1;
}
+ public static int findIndex(Snapshot targetSnapshot, List<Snapshot>
snapshotList) {
+ for (int i = 0; i < snapshotList.size(); i++) {
+ if (targetSnapshot.id() == snapshotList.get(i).id()) {
+ return i;
+ }
+ }
+ throw new RuntimeException(
+ String.format(
+ "Didn't find snapshot id '%s' in the list, this is
unexpected.",
+ targetSnapshot.id()));
+ }
+
+ public static List<Snapshot> findNearestNeighborsSnapshot(
+ Snapshot targetSnapshot, List<Snapshot> snapshotList,
SnapshotManager snapshotManager) {
+ List<Snapshot> skippedSnapshots = new ArrayList<>();
+
+ int index = SnapshotManager.findIndex(targetSnapshot, snapshotList);
+ // the nearest left neighbor snapshot.
+ if (index - 1 >= 0) {
+ skippedSnapshots.add(snapshotList.get(index - 1));
+ }
+ // the nearest right neighbor snapshot.
+ Snapshot nearestRight = snapshotManager.earliestSnapshot();
+ if (index + 1 < snapshotList.size()) {
+ Snapshot rightSnapshot = snapshotList.get(index + 1);
+ nearestRight = nearestRight.id() < rightSnapshot.id() ?
nearestRight : rightSnapshot;
+ }
+ skippedSnapshots.add(nearestRight);
+ return skippedSnapshots;
+ }
+
+ public static List<Snapshot> mergeTreeSetToList(
+ Collection<Snapshot> set1, Collection<Snapshot> set2) {
Review Comment:
Change method name to 'mergeSetToSortedList'
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]