Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/123197.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 123197
summary: Fix early termination in `LuceneSourceOperator`
area: ES|QL
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void collect(int doc) throws IOException {

@Override
public boolean isFinished() {
return doneCollecting;
return doneCollecting || remainingDocs <= 0;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.elasticsearch.compute.operator.Driver;
import org.elasticsearch.compute.operator.DriverContext;
import org.elasticsearch.compute.operator.Operator;
import org.elasticsearch.compute.operator.SourceOperator;
import org.elasticsearch.compute.test.AnyOperatorTestCase;
import org.elasticsearch.compute.test.OperatorTestCase;
import org.elasticsearch.compute.test.TestResultPageSinkOperator;
Expand Down Expand Up @@ -117,6 +118,27 @@ public void testShardDataPartitioning() {
testSimple(driverContext(), size, limit);
}

public void testEarlyTermination() {
int size = between(1_000, 20_000);
int limit = between(10, size);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm, max in between is exclusive and limit is always strictly less than size?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Limit can be larger than the size.

LuceneSourceOperator.Factory factory = simple(randomFrom(DataPartitioning.values()), size, limit, scoring);
try (SourceOperator sourceOperator = factory.get(driverContext())) {
assertFalse(sourceOperator.isFinished());
int collected = 0;
while (sourceOperator.isFinished() == false) {
Page page = sourceOperator.getOutput();
if (page != null) {
collected += page.getPositionCount();
page.releaseBlocks();
}
if (collected >= limit) {
assertTrue("source operator is not finished after reaching limit", sourceOperator.isFinished());
assertThat(collected, equalTo(limit));
}
}
}
}

public void testEmpty() {
testSimple(driverContext(), 0, between(10, 10_000));
}
Expand Down