Skip to content

Commit 5151667

Browse files
committed
Fix MissingValues for Lucene 10
With the Lucene 10 upgrade, we should not rely on doc values returning NO_MORE_DOCS once they've run out of ords. Instead, we should return a correct value for docValueCount(). Signed-off-by: Michael Froh <[email protected]>
1 parent 6559571 commit 5151667

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

server/src/main/java/org/opensearch/search/aggregations/support/MissingValues.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,8 @@ public boolean advanceExact(int doc) throws IOException {
324324

325325
@Override
326326
public int docValueCount() {
327-
return values.docValueCount();
327+
// If we don't have ordinals, then we just have the missing value
328+
return hasOrds ? values.docValueCount() : 1;
328329
}
329330

330331
@Override

server/src/test/java/org/opensearch/search/aggregations/support/MissingValuesTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public long nextOrd() {
152152
if (i < ords[doc].length) {
153153
return ords[doc][i++];
154154
} else {
155-
return NO_MORE_DOCS;
155+
throw new IllegalStateException();
156156
}
157157
}
158158

@@ -175,13 +175,13 @@ public int docValueCount() {
175175
for (int i = 0; i < numDocs; ++i) {
176176
assertTrue(withMissingReplaced.advanceExact(i));
177177
if (ords[i].length > 0) {
178+
assertEquals(ords[i].length, withMissingReplaced.docValueCount());
178179
for (int ord : ords[i]) {
179180
assertEquals(values[ord], withMissingReplaced.lookupOrd(withMissingReplaced.nextOrd()));
180181
}
181-
assertEquals(SortedSetDocValues.NO_MORE_DOCS, withMissingReplaced.nextOrd());
182182
} else {
183+
assertEquals(1, withMissingReplaced.docValueCount());
183184
assertEquals(missing, withMissingReplaced.lookupOrd(withMissingReplaced.nextOrd()));
184-
assertEquals(SortedSetDocValues.NO_MORE_DOCS, withMissingReplaced.nextOrd());
185185
}
186186
}
187187
}

0 commit comments

Comments
 (0)