okumin commented on code in PR #6131:
URL: https://github.com/apache/hive/pull/6131#discussion_r2431246618


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/Catalogs.java:
##########
@@ -111,7 +111,17 @@ private static Table loadTable(Configuration conf, String 
tableIdentifier, Strin
 
     if (catalog.isPresent()) {
       Preconditions.checkArgument(tableIdentifier != null, "Table identifier 
not set");
-      return catalog.get().loadTable(TableIdentifier.parse(tableIdentifier));
+
+      if (catalog.get() instanceof AutoCloseable) {
+        try (AutoCloseable ignored = (AutoCloseable) catalog.get()) {
+          return 
catalog.get().loadTable(TableIdentifier.parse(tableIdentifier));
+        } catch (Exception e) {
+          throw new RuntimeException("Failed to close catalog", e);
+        }
+      } else {
+        // fallback if not AutoCloseable
+        return catalog.get().loadTable(TableIdentifier.parse(tableIdentifier));
+      }

Review Comment:
   This file is a copy of 
[apache/iceberg/mr/.../Catalogs.java](https://github.com/apache/iceberg/blob/main/mr/src/main/java/org/apache/iceberg/mr/Catalogs.java),
 and the upstream version does not have the equivalent of this change. Why does 
Apache Iceberg justify the current implementation? Or it is still a problem on 
upstream, but no MapReduce users are interested in the warning message.
   
   The current implementation is likely to work. For future reference, I'm also 
curious about what the to-be solution is.



##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/Catalogs.java:
##########
@@ -111,7 +111,17 @@ private static Table loadTable(Configuration conf, String 
tableIdentifier, Strin
 
     if (catalog.isPresent()) {
       Preconditions.checkArgument(tableIdentifier != null, "Table identifier 
not set");
-      return catalog.get().loadTable(TableIdentifier.parse(tableIdentifier));
+
+      if (catalog.get() instanceof AutoCloseable) {

Review Comment:
   I guess Java 21 provides a smarter way to express this cast.
   
https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6131&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to