HashJoinEngine: Fix extraneous advance of left cursor. (#11890)

This could happen for right or full outer joins in certain cases. Tests
weren't catching this because existing Cursor implementations generally
ignore extraneous calls to "advance". So, to help catch this in tests,
extra state validations are also added to RowWalker, which is used by
RowBasedSegment.
This commit is contained in:
Gian Merlino 2021-11-09 11:34:11 -08:00 committed by GitHub
parent babf00f8e3
commit 324d4374f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -35,6 +35,7 @@ public class RowWalker<T>
private final Iterable<T> rowIterable;
private final ToLongFunction<T> timestampFunction;
@Nullable
private Iterator<T> rowIterator;
@Nullable
@ -60,13 +61,16 @@ public class RowWalker<T>
public void advance()
{
if (rowIterator.hasNext()) {
if (rowIterator == null) {
throw new IllegalStateException("cannot call advance when isDone == true");
} else if (rowIterator.hasNext()) {
current = rowIterator.next();
if (current == null) {
throw new NullPointerException("null row encountered in walker");
}
} else {
rowIterator = null;
current = null;
}
}

View File

@ -181,6 +181,12 @@ public class HashJoinEngine
assert !joinMatcher.hasMatch();
if (leftCursor.isDone()) {
// No right-hand matches and nothing on the left cursor. We're done; return.
assert isDone();
return;
}
do {
// No more right-hand side matches; advance the left-hand side.
leftCursor.advanceUninterruptibly();