LUCENE-10603: Remove SSDV#NO_MORE_ORDS definition (#1021)

This commit is contained in:
Greg Miller 2022-07-13 20:02:17 -07:00 committed by GitHub
parent ca7917472b
commit 9b185b99c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 53 additions and 174 deletions

View File

@ -29,6 +29,8 @@ API Changes
* LUCENE-10266: Move nearest-neighbor search on points to core. (Rushabh Shah)
* LUCENE-10603: Remove SortedSetDocValues#NO_MORE_ORDS definition. (Greg Miller)
New Features
---------------------

View File

@ -47,6 +47,14 @@ the top-n ranges ordered by count from 10.0 onwards (as described in the `Facets
of returning all ranges ordered by constructor-specified range order. The pre-existing behavior in
9.x and earlier can be retained by migrating to the new `Facets#getAllChildren` API (LUCENE-10550).
### SortedSetDocValues#NO_MORE_ORDS removed (LUCENE-10603)
`SortedSetDocValues#nextOrd()` no longer returns `NO_MORE_ORDS` when ordinals are exhausted for the
currently-positioned document. Callers should instead use `SortedSetDocValues#docValueCount()` to
determine the number of valid ordinals for the currently-positioned document up-front. It is now
illegal to call `SortedSetDocValues#nextOrd()` more than `SortedSetDocValues#docValueCount()` times
for the currently-positioned document (doing so will result in undefined behavior).
## Migration from Lucene 9.0 to Lucene 9.1
### Test framework package migration and module (LUCENE-10301)

View File

@ -1560,7 +1560,7 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
return new BaseSortedSetDocValues(entry, data) {
int doc = -1;
long start, end;
long curr;
int count;
@Override
@ -1583,27 +1583,24 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
if (target >= maxDoc) {
return doc = NO_MORE_DOCS;
}
start = addresses.get(target);
end = addresses.get(target + 1L);
count = (int) (end - start);
curr = addresses.get(target);
long end = addresses.get(target + 1L);
count = (int) (end - curr);
return doc = target;
}
@Override
public boolean advanceExact(int target) throws IOException {
start = addresses.get(target);
end = addresses.get(target + 1L);
count = (int) (end - start);
curr = addresses.get(target);
long end = addresses.get(target + 1L);
count = (int) (end - curr);
doc = target;
return true;
}
@Override
public long nextOrd() throws IOException {
if (start == end) {
return NO_MORE_ORDS;
}
return ords.get(start++);
return ords.get(curr++);
}
@Override
@ -1624,8 +1621,7 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
return new BaseSortedSetDocValues(entry, data) {
boolean set;
long start;
long end = 0;
long curr;
int count;
@Override
@ -1656,27 +1652,20 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
return disi.advanceExact(target);
}
private boolean set() {
private void set() {
if (set == false) {
final int index = disi.index();
start = addresses.get(index);
end = addresses.get(index + 1L);
count = (int) (end - start);
curr = addresses.get(index);
long end = addresses.get(index + 1L);
count = (int) (end - curr);
set = true;
return true;
}
return false;
}
@Override
public long nextOrd() throws IOException {
if (set()) {
return ords.get(start++);
} else if (start == end) {
return NO_MORE_ORDS;
} else {
return ords.get(start++);
}
set();
return ords.get(curr++);
}
@Override

View File

@ -484,8 +484,6 @@ public abstract class BaseLucene80DocValuesFormatTestCase
in.readBytes(b.bytes(), 0, b.length());
assertEquals(b.get(), values.lookupOrd(values.nextOrd()));
}
assertEquals(SortedSetDocValues.NO_MORE_ORDS, values.nextOrd());
}
r.close();
dir.close();

View File

@ -1207,7 +1207,6 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
assertEquals(i, dvSortedSet.nextDoc());
assertEquals(1, dvSortedSet.docValueCount());
long ord = dvSortedSet.nextOrd();
assertEquals(SortedSetDocValues.NO_MORE_ORDS, dvSortedSet.nextOrd());
term = dvSortedSet.lookupOrd(ord);
assertEquals(expectedRef, term);

View File

@ -720,11 +720,7 @@ class SimpleTextDocValuesReader extends DocValuesProducer {
@Override
public long nextOrd() throws IOException {
if (currentIndex == currentOrds.length) {
return NO_MORE_ORDS;
} else {
return Long.parseLong(currentOrds[currentIndex++]);
}
return Long.parseLong(currentOrds[currentIndex++]);
}
@Override

View File

@ -940,9 +940,6 @@ public abstract class DocValuesConsumer implements Closeable {
@Override
public long nextOrd() throws IOException {
long subOrd = currentSub.values.nextOrd();
if (subOrd == NO_MORE_ORDS) {
return NO_MORE_ORDS;
}
return currentSub.map.get(subOrd);
}

View File

@ -1453,23 +1453,19 @@ final class Lucene90DocValuesProducer extends DocValuesProducer {
private final int maxDoc = Lucene90DocValuesProducer.this.maxDoc;
private int doc = -1;
private long start;
private long end;
private long curr;
private int count;
@Override
public long nextOrd() throws IOException {
if (start == end) {
return NO_MORE_ORDS;
}
return values.get(start++);
return values.get(curr++);
}
@Override
public boolean advanceExact(int target) throws IOException {
start = addresses.get(target);
end = addresses.get(target + 1L);
count = (int) (end - start);
curr = addresses.get(target);
long end = addresses.get(target + 1L);
count = (int) (end - curr);
doc = target;
return true;
}
@ -1494,9 +1490,9 @@ final class Lucene90DocValuesProducer extends DocValuesProducer {
if (target >= maxDoc) {
return doc = NO_MORE_DOCS;
}
start = addresses.get(target);
end = addresses.get(target + 1L);
count = (int) (end - start);
curr = addresses.get(target);
long end = addresses.get(target + 1L);
count = (int) (end - curr);
return doc = target;
}
@ -1518,16 +1514,13 @@ final class Lucene90DocValuesProducer extends DocValuesProducer {
return new BaseSortedSetDocValues(entry, data) {
boolean set;
long start, end;
long curr;
int count;
@Override
public long nextOrd() throws IOException {
set();
if (start == end) {
return NO_MORE_ORDS;
}
return values.get(start++);
return values.get(curr++);
}
@Override
@ -1567,9 +1560,9 @@ final class Lucene90DocValuesProducer extends DocValuesProducer {
private void set() {
if (set == false) {
final int index = disi.index();
start = addresses.get(index);
end = addresses.get(index + 1L);
count = (int) (end - start);
curr = addresses.get(index);
long end = addresses.get(index + 1L);
count = (int) (end - curr);
set = true;
}
}
@ -1580,20 +1573,8 @@ final class Lucene90DocValuesProducer extends DocValuesProducer {
final SortedNumericDocValues ords = getSortedNumeric(ordsEntry);
return new BaseSortedSetDocValues(entry, data) {
int i = 0;
int count = 0;
boolean set = false;
@Override
public long nextOrd() throws IOException {
if (set == false) {
set = true;
i = 0;
count = ords.docValueCount();
}
if (i++ == count) {
return NO_MORE_ORDS;
}
return ords.nextValue();
}
@ -1604,7 +1585,6 @@ final class Lucene90DocValuesProducer extends DocValuesProducer {
@Override
public boolean advanceExact(int target) throws IOException {
set = false;
return ords.advanceExact(target);
}
@ -1615,13 +1595,11 @@ final class Lucene90DocValuesProducer extends DocValuesProducer {
@Override
public int nextDoc() throws IOException {
set = false;
return ords.nextDoc();
}
@Override
public int advance(int target) throws IOException {
set = false;
return ords.advance(target);
}

View File

@ -930,11 +930,7 @@ public class MultiDocValues {
@Override
public long nextOrd() throws IOException {
long segmentOrd = currentValues.nextOrd();
if (segmentOrd == NO_MORE_ORDS) {
return segmentOrd;
} else {
return mapping.getGlobalOrds(nextLeaf - 1).get(segmentOrd);
}
return mapping.getGlobalOrds(nextLeaf - 1).get(segmentOrd);
}
@Override

View File

@ -52,9 +52,7 @@ final class SingletonSortedSetDocValues extends SortedSetDocValues {
@Override
public long nextOrd() {
long v = ord;
ord = NO_MORE_ORDS;
return v;
return ord;
}
@Override

View File

@ -32,24 +32,13 @@ public abstract class SortedSetDocValues extends DocValuesIterator {
/** Sole constructor. (For invocation by subclass constructors, typically implicit.) */
protected SortedSetDocValues() {}
/**
* When returned by {@link #nextOrd()} it means there are no more ordinals for the document.
*
* @deprecated Will be removed in a future version. Please use {@link #docValueCount()} to know
* the number of doc values for the current document up-front.
*/
@Deprecated public static final long NO_MORE_ORDS = -1;
/**
* Returns the next ordinal for the current document. It is illegal to call this method after
* {@link #advanceExact(int)} returned {@code false}.
* {@link #advanceExact(int)} returned {@code false}. It is illegal to call this more than {@link
* #docValueCount()} times for the currently-positioned doc.
*
* <p>Note: Returns {@link #NO_MORE_ORDS} when the current document has no more ordinals. This
* behavior will be removed in a future version. Callers should use {@link #docValueCount()} to
* determine the number of values for the current document up-front.
*
* @return next ordinal for the document, or {@link #NO_MORE_ORDS}. ordinals are dense, start at
* 0, then increment by 1 for the next value in sorted order.
* @return next ordinal for the document. ordinals are dense, start at 0, then increment by 1 for
* the next value in sorted order.
*/
public abstract long nextOrd() throws IOException;

View File

@ -304,11 +304,7 @@ class SortedSetDocValuesWriter extends DocValuesWriter<SortedSetDocValues> {
@Override
public long nextOrd() {
if (ordUpto == ordCount) {
return NO_MORE_ORDS;
} else {
return currentDoc[ordUpto++];
}
return currentDoc[ordUpto++];
}
@Override
@ -351,7 +347,6 @@ class SortedSetDocValuesWriter extends DocValuesWriter<SortedSetDocValues> {
private final DocOrds ords;
private int docID = -1;
private long ordUpto;
private long limit;
private int count;
SortingSortedSetDocValues(SortedSetDocValues in, DocOrds ords) {
@ -391,11 +386,7 @@ class SortedSetDocValuesWriter extends DocValuesWriter<SortedSetDocValues> {
@Override
public long nextOrd() {
if (limit == ordUpto) {
return NO_MORE_ORDS;
} else {
return ords.ords.get(ordUpto++);
}
return ords.ords.get(ordUpto++);
}
@Override
@ -423,7 +414,6 @@ class SortedSetDocValuesWriter extends DocValuesWriter<SortedSetDocValues> {
assert docID >= 0;
ordUpto = ords.offsets[docID] - 1;
count = (int) ords.docValueCounts.get(docID);
limit = ordUpto + count;
}
}

View File

@ -16,8 +16,6 @@
*/
package org.apache.lucene.search;
import static org.apache.lucene.index.SortedSetDocValues.NO_MORE_ORDS;
import java.io.IOException;
import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.SortedDocValues;
@ -155,8 +153,6 @@ public class SortedSetSelector {
private void setOrd() throws IOException {
if (docID() != NO_MORE_DOCS) {
ord = (int) in.nextOrd();
} else {
ord = (int) NO_MORE_ORDS;
}
}
}
@ -230,8 +226,6 @@ public class SortedSetSelector {
in.nextOrd();
}
ord = (int) in.nextOrd();
} else {
ord = (int) NO_MORE_ORDS;
}
}
}
@ -306,8 +300,6 @@ public class SortedSetSelector {
in.nextOrd();
}
ord = (int) in.nextOrd();
} else {
ord = (int) NO_MORE_ORDS;
}
}
}
@ -382,8 +374,6 @@ public class SortedSetSelector {
in.nextOrd();
}
ord = (int) in.nextOrd();
} else {
ord = (int) NO_MORE_ORDS;
}
}
}

View File

@ -492,8 +492,6 @@ public class TestLucene90DocValuesFormat extends BaseCompressingDocValuesFormatT
in.readBytes(b.bytes(), 0, b.length());
assertEquals(b.get(), values.lookupOrd(values.nextOrd()));
}
assertEquals(SortedSetDocValues.NO_MORE_ORDS, values.nextOrd());
}
r.close();
dir.close();

View File

@ -1,26 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.lucene.index;
import org.apache.lucene.tests.util.LuceneTestCase;
public class TestSortedSetDocValues extends LuceneTestCase {
public void testNoMoreOrdsConstant() {
assertEquals(SortedSetDocValues.NO_MORE_ORDS, -1);
}
}

View File

@ -1150,7 +1150,6 @@ public class MemoryIndex {
@Override
public long nextOrd() throws IOException {
if (ord >= values.size()) return NO_MORE_ORDS;
return ord++;
}

View File

@ -301,7 +301,6 @@ public class TestMemoryIndex extends LuceneTestCase {
assertEquals(0L, sortedSetDocValues.nextOrd());
assertEquals(1L, sortedSetDocValues.nextOrd());
assertEquals(2L, sortedSetDocValues.nextOrd());
assertEquals(SortedSetDocValues.NO_MORE_ORDS, sortedSetDocValues.nextOrd());
assertEquals("c", sortedSetDocValues.lookupOrd(0L).utf8ToString());
assertEquals("d", sortedSetDocValues.lookupOrd(1L).utf8ToString());
assertEquals("f", sortedSetDocValues.lookupOrd(2L).utf8ToString());
@ -333,7 +332,6 @@ public class TestMemoryIndex extends LuceneTestCase {
assertEquals(0L, sortedSetDocValues.nextOrd());
assertEquals(1L, sortedSetDocValues.nextOrd());
assertEquals(2L, sortedSetDocValues.nextOrd());
assertEquals(SortedSetDocValues.NO_MORE_ORDS, sortedSetDocValues.nextOrd());
}
SortedNumericDocValues sortedNumericDocValues =

View File

@ -540,8 +540,6 @@ public class TestMemoryIndexAgainstDirectory extends BaseTokenStreamTestCase {
controlSortedSetDocValues.lookupOrd(controlOrd),
sortedSetDocValues.lookupOrd(controlOrd));
}
assertEquals(SortedSetDocValues.NO_MORE_ORDS, controlSortedSetDocValues.nextOrd());
assertEquals(SortedSetDocValues.NO_MORE_ORDS, sortedSetDocValues.nextOrd());
indexReader.close();
controlIndexReader.close();

View File

@ -977,7 +977,7 @@ public class AssertingLeafReader extends FilterLeafReader {
private final int maxDoc;
private final long valueCount;
private int lastDocID = -1;
private long lastOrd = NO_MORE_ORDS;
private int ordsRetrieved;
private boolean exists;
private AssertingSortedSetDocValues(SortedSetDocValues in, int maxDoc) {
@ -1011,8 +1011,8 @@ public class AssertingLeafReader extends FilterLeafReader {
assert docID == NO_MORE_DOCS || docID < maxDoc;
assert docID == in.docID();
lastDocID = docID;
lastOrd = -2;
exists = docID != NO_MORE_DOCS;
ordsRetrieved = 0;
return docID;
}
@ -1026,8 +1026,8 @@ public class AssertingLeafReader extends FilterLeafReader {
assert docID >= target;
assert docID == NO_MORE_DOCS || docID < maxDoc;
lastDocID = docID;
lastOrd = -2;
exists = docID != NO_MORE_DOCS;
ordsRetrieved = 0;
return docID;
}
@ -1040,7 +1040,7 @@ public class AssertingLeafReader extends FilterLeafReader {
exists = in.advanceExact(target);
assert in.docID() == target;
lastDocID = target;
lastOrd = -2;
ordsRetrieved = 0;
return exists;
}
@ -1055,12 +1055,11 @@ public class AssertingLeafReader extends FilterLeafReader {
@Override
public long nextOrd() throws IOException {
assertThread("Sorted set doc values", creationThread);
assert lastOrd != NO_MORE_ORDS;
assert exists;
assert ordsRetrieved < docValueCount();
ordsRetrieved++;
long ord = in.nextOrd();
assert ord < valueCount;
assert ord == NO_MORE_ORDS || ord > lastOrd;
lastOrd = ord;
return ord;
}

View File

@ -16,7 +16,6 @@
*/
package org.apache.lucene.tests.index;
import static org.apache.lucene.index.SortedSetDocValues.NO_MORE_ORDS;
import static org.apache.lucene.search.DocIdSetIterator.NO_MORE_DOCS;
import com.carrotsearch.randomizedtesting.generators.RandomPicks;
@ -1812,7 +1811,6 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes
assertEquals(1, dv.docValueCount());
assertEquals(0, dv.nextOrd());
assertEquals(NO_MORE_ORDS, dv.nextOrd());
BytesRef bytes = dv.lookupOrd(0);
assertEquals(newBytesRef("hello"), bytes);
@ -1838,7 +1836,6 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes
assertEquals(1, dv.docValueCount());
assertEquals(0, dv.nextOrd());
assertEquals(NO_MORE_ORDS, dv.nextOrd());
BytesRef bytes = dv.lookupOrd(0);
assertEquals(newBytesRef("hello"), bytes);
@ -1848,7 +1845,6 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes
assertEquals(1, dv.docValueCount());
assertEquals(0, dv.nextOrd());
assertEquals(NO_MORE_ORDS, dv.nextOrd());
bytes = dv.lookupOrd(0);
assertEquals(newBytesRef("world"), bytes);
@ -1883,7 +1879,6 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes
assertEquals(0, dv.nextDoc());
assertEquals(1, dv.docValueCount());
assertEquals(0, dv.nextOrd());
assertEquals(NO_MORE_ORDS, dv.nextOrd());
BytesRef bytes = dv.lookupOrd(0);
assertEquals(newBytesRef("hello"), bytes);
@ -1891,7 +1886,6 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes
assertEquals(1, dv.nextDoc());
assertEquals(1, dv.docValueCount());
assertEquals(1, dv.nextOrd());
assertEquals(NO_MORE_ORDS, dv.nextOrd());
bytes = dv.lookupOrd(1);
assertEquals(newBytesRef("world"), bytes);
@ -1918,7 +1912,6 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes
assertEquals(2, dv.docValueCount());
assertEquals(0, dv.nextOrd());
assertEquals(1, dv.nextOrd());
assertEquals(NO_MORE_ORDS, dv.nextOrd());
BytesRef bytes = dv.lookupOrd(0);
assertEquals(newBytesRef("hello"), bytes);
@ -1948,7 +1941,6 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes
assertEquals(2, dv.docValueCount());
assertEquals(0, dv.nextOrd());
assertEquals(1, dv.nextOrd());
assertEquals(NO_MORE_ORDS, dv.nextOrd());
BytesRef bytes = dv.lookupOrd(0);
assertEquals(newBytesRef("hello"), bytes);
@ -1989,13 +1981,11 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes
assertEquals(2, dv.docValueCount());
assertEquals(1, dv.nextOrd());
assertEquals(2, dv.nextOrd());
assertEquals(NO_MORE_ORDS, dv.nextOrd());
assertEquals(1, dv.nextDoc());
assertEquals(2, dv.docValueCount());
assertEquals(0, dv.nextOrd());
assertEquals(1, dv.nextOrd());
assertEquals(NO_MORE_ORDS, dv.nextOrd());
BytesRef bytes = dv.lookupOrd(0);
assertEquals(newBytesRef("beer"), bytes);
@ -2033,7 +2023,6 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes
assertEquals(1, dv.docValueCount());
assertEquals(0, dv.nextOrd());
assertEquals(NO_MORE_ORDS, dv.nextOrd());
BytesRef bytes = dv.lookupOrd(0);
assertEquals(newBytesRef("hello"), bytes);
@ -2067,7 +2056,6 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes
assertEquals(1, dv.docValueCount());
assertEquals(0, dv.nextOrd());
assertEquals(NO_MORE_ORDS, dv.nextOrd());
BytesRef bytes = dv.lookupOrd(0);
assertEquals(newBytesRef("hello"), bytes);
@ -2100,7 +2088,6 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes
assertEquals(1, dv.docValueCount());
assertEquals(0, dv.nextOrd());
assertEquals(NO_MORE_ORDS, dv.nextOrd());
BytesRef bytes = dv.lookupOrd(0);
assertEquals(newBytesRef("hello"), bytes);
@ -2134,7 +2121,6 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes
assertEquals(1, dv.docValueCount());
assertEquals(0, dv.nextOrd());
assertEquals(NO_MORE_ORDS, dv.nextOrd());
BytesRef bytes = dv.lookupOrd(0);
assertEquals(newBytesRef("hello"), bytes);
@ -2341,7 +2327,6 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes
BytesRef scratch = docValues.lookupOrd(ord);
assertEquals(stringValue, scratch.utf8ToString());
}
assertEquals(NO_MORE_ORDS, docValues.nextOrd());
}
}
}
@ -2374,7 +2359,6 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes
BytesRef scratch = docValues.lookupOrd(ord);
assertEquals(stringValue, scratch.utf8ToString());
}
assertEquals(NO_MORE_ORDS, docValues.nextOrd());
}
}
}
@ -2911,7 +2895,6 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes
BytesRef value = sortedSet.lookupOrd(ord);
assertEquals(s, value.utf8ToString());
}
assertEquals(NO_MORE_ORDS, sortedSet.nextOrd());
}
String[] numValues = r.document(j).getValues("storedSortedNumeric");