the-other-tim-brown commented on code in PR #13695:
URL: https://github.com/apache/hudi/pull/13695#discussion_r2283640183
##########
hudi-common/src/main/java/org/apache/hudi/common/util/HoodieDataUtils.java:
##########
@@ -94,4 +96,76 @@ public static <K, V> Map<K, Set<V>>
collectPairDataAsMap(HoodiePairData<K, V> pa
},
HashMap::putAll);
}
+
+ /**
+ * Executes a function with HoodieData and ensures cleanup after use
Review Comment:
Let's add context of what `cleanup` means here. For example, will this close
any open resources?
Also include when you are required to use this.
##########
hudi-common/src/main/java/org/apache/hudi/common/util/HoodieDataUtils.java:
##########
@@ -94,4 +96,76 @@ public static <K, V> Map<K, Set<V>>
collectPairDataAsMap(HoodiePairData<K, V> pa
},
HashMap::putAll);
}
+
+ /**
+ * Executes a function with HoodieData and ensures cleanup after use
+ *
+ * @param hoodieData The HoodieData to use
+ * @param f Function that processes the HoodieData
+ * @param <T> Type parameter of HoodieData
+ * @param <R> Return type of the function
+ * @return Result of the function
+ */
+ public static <T, R> R withHoodieDataCleanUp(HoodieData<T> hoodieData,
Function<HoodieData<T>, R> f) {
+ try {
+ return f.apply(hoodieData);
+ } finally {
+ hoodieData.unpersistWithDependencies();
+ }
+ }
+
+ /**
+ * Executes a function with HoodiePairData and ensures cleanup after use
+ *
+ * @param hoodiePairData The HoodiePairData to use
+ * @param f Function that processes the HoodiePairData
+ * @param <K> Key type parameter of HoodiePairData
+ * @param <V> Value type parameter of HoodiePairData
+ * @param <R> Return type of the function
+ * @return Result of the function
+ */
+ public static <K, V, R> R withHoodieDataCleanUp(HoodiePairData<K, V>
hoodiePairData, Function<HoodiePairData<K, V>, R> f) {
+ try {
+ return f.apply(hoodiePairData);
+ } finally {
+ hoodiePairData.unpersistWithDependencies();
+ }
+ }
+
+ /**
+ * Executes a function with HoodieData and ensures cleanup only on exception
+ *
+ * @param hoodieData The HoodieData to use
+ * @param f Function that processes the HoodieData
+ * @param <T> Type parameter of HoodieData
+ * @param <R> Return type of the function
+ * @return Result of the function
+ */
+ public static <T, R> R withHoodieDataCleanUpOnException(HoodieData<T>
hoodieData, Function<HoodieData<T>, R> f) {
Review Comment:
Why do we need this when we already have the cleanup in a `finally` block
above?
--
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]