the-other-tim-brown commented on code in PR #13695:
URL: https://github.com/apache/hudi/pull/13695#discussion_r2286340133


##########
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:
   I read it, still the question remains. 



-- 
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]

Reply via email to