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

HSEARCH-4969 IndexOutOfBoundsException in TextMultiValues #3748

Merged
merged 2 commits into from
Sep 25, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -89,43 +89,35 @@ protected LongMultiValues select(SortedNumericDocValues values, ChildDocIds chil
return LongMultiValues.EMPTY;
}

return new LongMultiValues() {
int currentParentDoc = -1;
int remainingValuesForChild = 0;
return new LongMultiValues.DocValuesLongMultiValues( values ) {
private int currentParentDoc = -1;

@Override
public boolean advanceExact(int parentDoc) throws IOException {
assert parentDoc >= currentParentDoc : "can only evaluate current and upcoming parent docs";
if ( parentDoc == currentParentDoc ) {
return hasNextValue();
}

currentParentDoc = parentDoc;
remainingValuesForChild = 0; // To be set in the next call to hasNextValue()

return childDocsWithValues.advanceExactParent( parentDoc );
boolean found = childDocsWithValues.advanceExactParent( parentDoc );
if ( found ) {
// Position the iterator on the next child so that updateRemaining()
// can get the relevant docvalues.
childDocsWithValues.nextChild();
}
updateRemaining( found );
return found;
}

@Override
public boolean hasNextValue() throws IOException {
if ( remainingValuesForChild > 0 ) {
if ( super.hasNextValue() ) {
return true;
}

if ( childDocsWithValues.nextChild() != DocIdSetIterator.NO_MORE_DOCS ) {
remainingValuesForChild = values.docValueCount();
return true;
}
else {
remainingValuesForChild = 0;
return false;
}
}

@Override
public long nextValue() throws IOException {
--remainingValuesForChild;
return values.nextValue();
boolean hasNextChildDocWithValue = childDocsWithValues.nextChild() != DocIdSetIterator.NO_MORE_DOCS;
updateRemaining( hasNextChildDocWithValue );
return hasNextChildDocWithValue;
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,23 @@ protected TextMultiValues select(SortedSetDocValues values, ChildDocIds childDoc
}

return new TextMultiValues.DocValuesTextMultiValues( values ) {
int currentParentDoc = -1;
private int currentParentDoc = -1;

@Override
public boolean advanceExact(int parentDoc) throws IOException {
assert parentDoc >= currentParentDoc : "can only evaluate current and upcoming parent docs";
if ( parentDoc == currentParentDoc ) {
return hasNextValue();
}

return childDocsWithValues.advanceExactParent( parentDoc );
currentParentDoc = parentDoc;
boolean found = childDocsWithValues.advanceExactParent( parentDoc );
if ( found ) {
// Position the iterator on the next child so that updateRemaining()
// can get the relevant docvalues.
childDocsWithValues.nextChild();
}
updateRemaining( found );
return found;
}

@Override
Expand All @@ -93,13 +100,9 @@ public boolean hasNextValue() throws IOException {
return true;
}

if ( childDocsWithValues.nextChild() != DocIdSetIterator.NO_MORE_DOCS ) {
nextOrd = values.nextOrd();
return true;
}
else {
return false;
}
boolean hasNextChildDocWithValue = childDocsWithValues.nextChild() != DocIdSetIterator.NO_MORE_DOCS;
updateRemaining( hasNextChildDocWithValue );
return hasNextChildDocWithValue;
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public long nextValue() {
}
};

private static class DocValuesLongMultiValues extends LongMultiValues {
protected static class DocValuesLongMultiValues extends LongMultiValues {

private final SortedNumericDocValues values;
private int remaining;
Expand All @@ -77,12 +77,16 @@ private static class DocValuesLongMultiValues extends LongMultiValues {
@Override
public boolean advanceExact(int doc) throws IOException {
boolean found = values.advanceExact( doc );
this.remaining = found ? values.docValueCount() : 0;
updateRemaining( found );
return found;
}

protected final void updateRemaining(boolean hasDocValue) {
remaining = hasDocValue ? values.docValueCount() : 0;
}

@Override
public boolean hasNextValue() {
public boolean hasNextValue() throws IOException {
return remaining > 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,8 @@ public long getValueCount() {
};

protected static class DocValuesTextMultiValues extends TextMultiValues {

protected final SortedSetDocValues values;
protected long nextOrd;
protected int docValueCount = 0;
protected int nextOrdIndex = 0;
private int remaining;

DocValuesTextMultiValues(SortedSetDocValues values) {
this.values = values;
Expand All @@ -99,28 +96,23 @@ protected static class DocValuesTextMultiValues extends TextMultiValues {
@Override
public boolean advanceExact(int doc) throws IOException {
boolean found = values.advanceExact( doc );
if ( found ) {
nextOrd = values.nextOrd();
docValueCount = values.docValueCount();
}
else {
docValueCount = 0;
}
nextOrdIndex = 0;
updateRemaining( found );
return found;
}

protected final void updateRemaining(boolean hasDocValue) {
remaining = hasDocValue ? values.docValueCount() : 0;
}

@Override
public boolean hasNextValue() throws IOException {
return nextOrdIndex < docValueCount;
return remaining > 0;
}

@Override
public long nextOrd() throws IOException {
nextOrdIndex++;
long previousOrd = nextOrd;
nextOrd = values.nextOrd();
return previousOrd;
--remaining;
return values.nextOrd();
}

@Override
Expand Down
Loading