diff --git a/processing/src/main/java/org/apache/druid/segment/RowWalker.java b/processing/src/main/java/org/apache/druid/segment/RowWalker.java index b44802481b9..2a0e2ab5a6e 100644 --- a/processing/src/main/java/org/apache/druid/segment/RowWalker.java +++ b/processing/src/main/java/org/apache/druid/segment/RowWalker.java @@ -35,6 +35,7 @@ public class RowWalker private final Iterable rowIterable; private final ToLongFunction timestampFunction; + @Nullable private Iterator rowIterator; @Nullable @@ -60,13 +61,16 @@ public class RowWalker 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; } } diff --git a/processing/src/main/java/org/apache/druid/segment/join/HashJoinEngine.java b/processing/src/main/java/org/apache/druid/segment/join/HashJoinEngine.java index 40582eee77a..cdf80dcf676 100644 --- a/processing/src/main/java/org/apache/druid/segment/join/HashJoinEngine.java +++ b/processing/src/main/java/org/apache/druid/segment/join/HashJoinEngine.java @@ -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();