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

LUCENE-10598: SortedSetDocValues#docValueCount() should be always greater than zero #934

Merged
merged 3 commits into from Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -1454,7 +1454,7 @@ public long nextOrd() throws IOException {

@Override
public long docValueCount() {
return count;
return ords.docValueCount();
}

@Override
Expand Down
13 changes: 13 additions & 0 deletions lucene/core/src/java/org/apache/lucene/index/CheckIndex.java
Expand Up @@ -3337,9 +3337,22 @@ private static void checkSortedSetDocValues(
LongBitSet seenOrds = new LongBitSet(dv.getValueCount());
long maxOrd2 = -1;
for (int docID = dv.nextDoc(); docID != NO_MORE_DOCS; docID = dv.nextDoc()) {
long count = dv.docValueCount();
if (count == 0) {
throw new CheckIndexException(
"sortedset dv for field: "
+ fieldName
+ " returned docValueCount=0 for docID="
+ docID);
}
if (dv2.advanceExact(docID) == false) {
throw new CheckIndexException("advanceExact did not find matching doc ID: " + docID);
}
long count2 = dv2.docValueCount();
if (count != count2) {
throw new CheckIndexException(
"advanceExact reports different value count: " + count + " != " + count2);
}
long lastOrd = -1;
long ord;
int ordCount = 0;
Expand Down
Expand Up @@ -45,8 +45,9 @@ protected SortedSetDocValues() {}
public abstract long nextOrd() throws IOException;

/**
* Retrieves the number of values for the current document. This must always be greater than zero.
* It is illegal to call this method after {@link #advanceExact(int)} returned {@code false}.
* Retrieves the number of unique ords for the current document. This must always be greater than
* zero. It is illegal to call this method after {@link #advanceExact(int)} returned {@code
* false}.
*/
public abstract long docValueCount();

Expand Down
Expand Up @@ -265,6 +265,7 @@ private void doTestSparseDocValuesVsStoredFields() throws Exception {
assertTrue(valueSet.contains(sortedNumeric.nextValue()));
}
assertEquals(i, sortedSet.nextDoc());
assertEquals(valueSet.size(), sortedSet.docValueCount());
int sortedSetCount = 0;
while (true) {
long ord = sortedSet.nextOrd();
Expand Down Expand Up @@ -488,6 +489,7 @@ public void testSortedSetAroundBlockSize() throws IOException {
for (int i = 0; i < maxDoc; ++i) {
assertEquals(i, values.nextDoc());
final int numValues = in.readVInt();
assertEquals(numValues, values.docValueCount());

for (int j = 0; j < numValues; ++j) {
b.setLength(in.readVInt());
Expand Down
Expand Up @@ -279,6 +279,7 @@ public void testSortedSet() throws Exception {
if (docID == NO_MORE_DOCS) {
break;
}
assertEquals(single.docValueCount(), multi.docValueCount());

ArrayList<Long> expectedList = new ArrayList<>();
long ord;
Expand Down
Expand Up @@ -230,6 +230,7 @@ public void testSortOnAddIndicesRandom() throws IOException {
assertEquals(
new BytesRef(ids.longValue() + ""),
sorted_set_dv.lookupOrd(sorted_set_dv.nextOrd()));
assertEquals(1, sorted_set_dv.docValueCount());
assertEquals(1, sorted_numeric_dv.docValueCount());
assertEquals(ids.longValue(), sorted_numeric_dv.nextValue());

Expand Down
Expand Up @@ -297,6 +297,7 @@ public void testDocValues() throws Exception {
SortedSetDocValues sortedSetDocValues = leafReader.getSortedSetDocValues("sorted_set");
assertEquals(3, sortedSetDocValues.getValueCount());
assertEquals(0, sortedSetDocValues.nextDoc());
assertEquals(3, sortedSetDocValues.docValueCount());
assertEquals(0L, sortedSetDocValues.nextOrd());
assertEquals(1L, sortedSetDocValues.nextOrd());
assertEquals(2L, sortedSetDocValues.nextOrd());
Expand Down