diff --git a/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/Catalogs.java b/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/Catalogs.java index e431e0323a45..c1ff42b0ab5e 100644 --- a/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/Catalogs.java +++ b/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/Catalogs.java @@ -19,10 +19,12 @@ package org.apache.iceberg.mr; +import java.io.Closeable; import java.util.Map; import java.util.Optional; import java.util.Properties; import java.util.Set; +import org.apache.commons.io.IOUtils; import org.apache.hadoop.conf.Configuration; import org.apache.iceberg.CatalogUtil; import org.apache.iceberg.PartitionSpec; @@ -111,7 +113,13 @@ 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)); + try { + return catalog.get().loadTable(TableIdentifier.parse(tableIdentifier)); + } finally { + if (catalog.get() instanceof Closeable closeable) { + IOUtils.closeQuietly(closeable); + } + } } Preconditions.checkArgument(tableLocation != null, "Table location not set");