Ensure everything is closed in SpillableHashAggregationBuilder
@@ -26,9 +26,11 @@ import com.facebook.presto.spiller.SpillerFactory;
import com.facebook.presto.sql.gen.JoinCompiler;
import com.facebook.presto.sql.planner.plan.AggregationNode;
import com.google.common.collect.ImmutableList;
+import com.google.common.io.Closer;
import com.google.common.util.concurrent.ListenableFuture;
import io.airlift.units.DataSize;
+import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
@@ -189,14 +191,13 @@ public class SpillableHashAggregationBuilder
@Override
public void close()
{
- if (merger.isPresent()) {
- merger.get().close();
+ try (Closer closer = Closer.create()) {
+ merger.ifPresent(closer::register);
+ spiller.ifPresent(closer::register);
+ mergeHashSort.ifPresent(closer::register);
}
- if (spiller.isPresent()) {
- spiller.get().close();
- }
- if (mergeHashSort.isPresent()) {
- mergeHashSort.get().close();
+ catch (IOException e) {
+ throw new RuntimeException(e);
}
}
