Skip to content

Commit e185e8f

Browse files
committed
[DRAFT] Throw exceptions if nextOrd called more than docValueCount times
Signed-off-by: Michael Froh <[email protected]>
1 parent d5e9093 commit e185e8f

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

server/src/main/java/org/opensearch/index/fielddata/ordinals/GlobalOrdinalMapping.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ public boolean advanceExact(int target) throws IOException {
8989
@Override
9090
public long nextOrd() throws IOException {
9191
if (++nextOrd > docValueCount) {
92-
return SortedSetDocValues.NO_MORE_DOCS;
92+
throw new IllegalStateException("Called nextOrd after docValueCount");
9393
}
9494
long segmentOrd = values.nextOrd();
9595
if (segmentOrd == SortedSetDocValues.NO_MORE_DOCS) {
96-
return SortedSetDocValues.NO_MORE_DOCS;
96+
throw new IllegalStateException("Wrapped values returned no more docs too early");
9797
} else {
9898
return getGlobalOrd(segmentOrd);
9999
}

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

+8
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ public String toString() {
338338
static SortedSetDocValues insertOrd(final SortedSetDocValues values, final long insertedOrd, final BytesRef missingValue) {
339339
return new AbstractSortedSetDocValues() {
340340

341+
private int ordCount = 0;
341342
private boolean hasOrds;
342343
private long nextMissingOrd;
343344

@@ -365,6 +366,9 @@ public int docValueCount() {
365366
@Override
366367
public long nextOrd() throws IOException {
367368
if (hasOrds) {
369+
if (++ordCount == values.getValueCount()) {
370+
throw new IllegalStateException("Called nextOrd after docValueCount");
371+
}
368372
final long ord = values.nextOrd();
369373
if (ord < insertedOrd) {
370374
return ord;
@@ -374,6 +378,9 @@ public long nextOrd() throws IOException {
374378
return ord + 1;
375379
}
376380
} else {
381+
if (nextMissingOrd == SortedSetDocValues.NO_MORE_DOCS) {
382+
throw new IllegalStateException("Called nextOrd after docValueCount");
383+
}
377384
// we want to return the next missing ord but set this to
378385
// NO_MORE_DOCS so on the next call we indicate there are no
379386
// more values
@@ -386,6 +393,7 @@ public long nextOrd() throws IOException {
386393
@Override
387394
public boolean advanceExact(int doc) throws IOException {
388395
hasOrds = values.advanceExact(doc);
396+
ordCount = 0;
389397
nextMissingOrd = insertedOrd;
390398
// always return true because we want to return a value even if
391399
// the document does not have a value

0 commit comments

Comments
 (0)