-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Throw exceptions if nextOrd called more than docValueCount times #17649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
aec63cc
85a97b3
7a4eac3
e2d6961
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -196,6 +196,7 @@ | |
|
|
||
| private long currentOffset; | ||
| private long currentEndOffset; | ||
| private int docValueCount; | ||
|
|
||
| MultiDocs(MultiOrdinals ordinals, ValuesHolder values) { | ||
| this.valueCount = ordinals.valueCount; | ||
|
|
@@ -213,13 +214,14 @@ | |
| public boolean advanceExact(int docId) throws IOException { | ||
| currentOffset = docId != 0 ? endOffsets.get(docId - 1) : 0; | ||
| currentEndOffset = endOffsets.get(docId); | ||
| return currentOffset != currentEndOffset; | ||
| docValueCount = Math.toIntExact(currentEndOffset - currentOffset); | ||
| return docValueCount > 0; | ||
| } | ||
|
|
||
| @Override | ||
| public long nextOrd() throws IOException { | ||
| if (currentOffset == currentEndOffset) { | ||
| return SortedSetDocValues.NO_MORE_DOCS; | ||
| throw new IllegalStateException("nextOrd() called more than docValueCount() times"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am wondering if this exception and
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The In practice, these checks should be short-lived. Lucene doesn't even do checks. The JavaDoc there just says "It is illegal to call this more than docValueCount() times for the currently-positioned doc." Some implementations will just return the same value over and over. Other implementations may do something else. I added these exceptions to highlight the places where we were doing the wrong thing. The later commits on this PR were where I fixed those places. In theory, before we ship OpenSearch 3.0, we could probably remove these exceptions.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, let us make these exceptions consistent. |
||
| } else { | ||
| return ords.get(currentOffset++); | ||
| } | ||
|
|
@@ -232,7 +234,7 @@ | |
|
|
||
| @Override | ||
| public int docValueCount() { | ||
| return Math.toIntExact(currentEndOffset - currentOffset); | ||
| return docValueCount; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -339,6 +339,7 @@ | |
| static SortedSetDocValues insertOrd(final SortedSetDocValues values, final long insertedOrd, final BytesRef missingValue) { | ||
| return new AbstractSortedSetDocValues() { | ||
|
|
||
| private int ordCount = 0; | ||
| private boolean hasOrds; | ||
| private long nextMissingOrd; | ||
|
|
||
|
|
@@ -367,6 +368,9 @@ | |
| @Override | ||
| public long nextOrd() throws IOException { | ||
| if (hasOrds) { | ||
| if (++ordCount > values.docValueCount()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @msfroh This is failing due to the check we are doing here. The
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This behavior is the same since Lucene 9.2.0 upgrade so shouldn't be a problem. WDYT ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm... that implementation in |
||
| throw new IllegalStateException("Called nextOrd after docValueCount"); | ||
|
Check warning on line 372 in server/src/main/java/org/opensearch/search/aggregations/support/MissingValues.java
|
||
| } | ||
| final long ord = values.nextOrd(); | ||
| if (ord < insertedOrd) { | ||
| return ord; | ||
|
|
@@ -376,6 +380,9 @@ | |
| return ord + 1; | ||
| } | ||
| } else { | ||
| if (nextMissingOrd == SortedSetDocValues.NO_MORE_DOCS) { | ||
| throw new IllegalStateException("Called nextOrd after docValueCount"); | ||
|
Check warning on line 384 in server/src/main/java/org/opensearch/search/aggregations/support/MissingValues.java
|
||
| } | ||
| // we want to return the next missing ord but set this to | ||
| // NO_MORE_DOCS so on the next call we indicate there are no | ||
| // more values | ||
|
|
@@ -388,6 +395,7 @@ | |
| @Override | ||
| public boolean advanceExact(int doc) throws IOException { | ||
| hasOrds = values.advanceExact(doc); | ||
| ordCount = 0; | ||
| nextMissingOrd = insertedOrd; | ||
| // always return true because we want to return a value even if | ||
| // the document does not have a value | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.