yihua commented on code in PR #18489:
URL: https://github.com/apache/hudi/pull/18489#discussion_r3066960914
##########
hudi-common/src/main/java/org/apache/hudi/common/table/timeline/TimelineUtils.java:
##########
@@ -647,4 +647,28 @@ public static <T> Option<HoodieInstantWriter>
getHoodieInstantWriterOption(Hoodi
}
return writerOption;
}
+
+ public static Option<Pair<String, HoodieCommitMetadata>>
getLatestInstantAndCommitMetadataWithValidCheckpointInfo(HoodieTimeline
timeline,
+
String... checkpointKeys) throws
IOException {
+ return (Option<Pair<String, HoodieCommitMetadata>>)
timeline.getReverseOrderedInstants().map(instant -> {
+ try {
+ HoodieCommitMetadata commitMetadata = HoodieCommitMetadata
+ .fromBytes(timeline.getInstantDetails(instant).get(),
HoodieCommitMetadata.class);
+ boolean hasCheckpointMetadata = false;
Review Comment:
🤖 nit: could you replace the for-loop with
`Arrays.stream(checkpointKeys).anyMatch(key ->
!StringUtils.isNullOrEmpty(commitMetadata.getMetadata(key)))`?
<sub><i>- Generated by an AI agent and may contain mistakes. Please verify
any suggestions before applying.</i></sub>
##########
hudi-common/src/main/java/org/apache/hudi/common/table/timeline/TimelineUtils.java:
##########
@@ -647,4 +647,28 @@ public static <T> Option<HoodieInstantWriter>
getHoodieInstantWriterOption(Hoodi
}
return writerOption;
}
+
+ public static Option<Pair<String, HoodieCommitMetadata>>
getLatestInstantAndCommitMetadataWithValidCheckpointInfo(HoodieTimeline
timeline,
+
String... checkpointKeys) throws
IOException {
+ return (Option<Pair<String, HoodieCommitMetadata>>)
timeline.getReverseOrderedInstants().map(instant -> {
Review Comment:
🤖 nit: add `@SuppressWarnings("unchecked")` above the method to document the
intentional type cast.
<sub><i>- Generated by an AI agent and may contain mistakes. Please verify
any suggestions before applying.</i></sub>
##########
hudi-common/src/main/java/org/apache/hudi/common/table/timeline/TimelineUtils.java:
##########
@@ -647,4 +647,28 @@ public static <T> Option<HoodieInstantWriter>
getHoodieInstantWriterOption(Hoodi
}
return writerOption;
}
+
+ public static Option<Pair<String, HoodieCommitMetadata>>
getLatestInstantAndCommitMetadataWithValidCheckpointInfo(HoodieTimeline
timeline,
+
String... checkpointKeys) throws
IOException {
+ return (Option<Pair<String, HoodieCommitMetadata>>)
timeline.getReverseOrderedInstants().map(instant -> {
+ try {
+ HoodieCommitMetadata commitMetadata = HoodieCommitMetadata
+ .fromBytes(timeline.getInstantDetails(instant).get(),
HoodieCommitMetadata.class);
+ boolean hasCheckpointMetadata = false;
+ for (String checkpointKey : checkpointKeys) {
+ if
(!StringUtils.isNullOrEmpty(commitMetadata.getMetadata(checkpointKey))) {
+ hasCheckpointMetadata = true;
+ break;
+ }
+ }
+ if (hasCheckpointMetadata) {
Review Comment:
🤖 nit: could you simplify this if-else to a ternary: `return
hasCheckpointMetadata ? Option.of(...) : Option.empty();`?
<sub><i>- Generated by an AI agent and may contain mistakes. Please verify
any suggestions before applying.</i></sub>
--
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]