Close join probe before creating outer position iterator
@@ -56,7 +56,7 @@ public class LookupJoinOperator
private final List<Type> allTypes;
private final List<Type> probeTypes;
private final JoinProbeFactory joinProbeFactory;
- private final Runnable onClose;
+ private final Runnable afterClose;
private final OptionalInt lookupJoinsCount;
private final HashGenerator hashGenerator;
private final LookupSourceFactory lookupSourceFactory;
@@ -104,7 +104,7 @@ public class LookupJoinOperator
JoinType joinType,
LookupSourceFactory lookupSourceFactory,
JoinProbeFactory joinProbeFactory,
- Runnable onClose,
+ Runnable afterClose,
OptionalInt lookupJoinsCount,
HashGenerator hashGenerator,
PartitioningSpillerFactory partitioningSpillerFactory)
@@ -118,7 +118,7 @@ public class LookupJoinOperator
probeOnOuterSide = joinType == PROBE_OUTER || joinType == FULL_OUTER;
this.joinProbeFactory = requireNonNull(joinProbeFactory, "joinProbeFactory is null");
- this.onClose = requireNonNull(onClose, "onClose is null");
+ this.afterClose = requireNonNull(afterClose, "afterClose is null");
this.lookupJoinsCount = requireNonNull(lookupJoinsCount, "lookupJoinsCount is null");
this.hashGenerator = requireNonNull(hashGenerator, "hashGenerator is null");
this.lookupSourceFactory = requireNonNull(lookupSourceFactory, "lookupSourceFactory is null");
@@ -507,10 +507,13 @@ public class LookupJoinOperator
probe = null;
try (Closer closer = Closer.create()) {
+ // `afterClose` must be run last.
+ // Closer is documented to mimic try-with-resource, which implies close will happen in reverse order.
+ closer.register(afterClose::run);
+
closer.register(pageBuilder::reset);
closer.register(() -> Optional.ofNullable(lookupSourceProvider).ifPresent(LookupSourceProvider::close));
spiller.ifPresent(closer::register);
- closer.register(onClose::run);
}
catch (IOException e) {
throw new RuntimeException(e);
