Skip to content
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

[DRAFT] Throw exceptions if nextOrd called more than docValueCount times #17649

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ public boolean advanceExact(int target) throws IOException {
@Override
public long nextOrd() throws IOException {
if (++nextOrd > docValueCount) {
return SortedSetDocValues.NO_MORE_DOCS;
throw new IllegalStateException("Called nextOrd after docValueCount");
}
long segmentOrd = values.nextOrd();
if (segmentOrd == SortedSetDocValues.NO_MORE_DOCS) {
return SortedSetDocValues.NO_MORE_DOCS;
throw new IllegalStateException("Wrapped values returned no more docs too early");
} else {
return getGlobalOrd(segmentOrd);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ public String toString() {
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;

Expand Down Expand Up @@ -365,6 +366,9 @@ public int docValueCount() {
@Override
public long nextOrd() throws IOException {
if (hasOrds) {
if (++ordCount > values.docValueCount()) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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 values here is MultiOrdinals$MultiOrds ( for TermsAggregatorTests #testBucketInTermsAggregationWithMissingValue ) and its docValueCount decreases with each call to nextOrd

 public int docValueCount() {
      return Math.toIntExact(currentEndOffset - currentOffset);
}

Copy link
Contributor

@expani expani Mar 28, 2025

Choose a reason for hiding this comment

The 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 ?

throw new IllegalStateException("Called nextOrd after docValueCount");
}
final long ord = values.nextOrd();
if (ord < insertedOrd) {
return ord;
Expand All @@ -374,6 +378,9 @@ public long nextOrd() throws IOException {
return ord + 1;
}
} else {
if (nextMissingOrd == SortedSetDocValues.NO_MORE_DOCS) {
throw new IllegalStateException("Called nextOrd after docValueCount");
}
// 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
Expand All @@ -386,6 +393,7 @@ public long nextOrd() throws IOException {
@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
Expand Down
Loading