deniskuzZ commented on code in PR #6131:
URL: https://github.com/apache/hive/pull/6131#discussion_r2431628543
##########
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:
can we avoid logical fallback and close resource when required?
````
private static Table loadTable(Configuration conf, String tableIdentifier,
String tableLocation,
String catalogName) {
Optional<Catalog> catalog = loadCatalog(conf, catalogName);
if (catalog.isPresent()) {
Preconditions.checkArgument(tableIdentifier != null, "Table
identifier not set");
try {
return
catalog.get().loadTable(TableIdentifier.parse(tableIdentifier));
} finally {
closeResource(catalog.get());
}
}
....
}
private static void closeResource(Object resource) {
if (resource instanceof Closeable) {
try {
((Closeable) resource).close();
} catch (Exception e) {
throw new RuntimeException("Failed to close resource", e);
}
}
}
````
--
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]