mirror of https://github.com/apache/lucene.git
LUCENE-7489: Remove one layer of abstraction in binary doc values and single-valued numerics.
This commit is contained in:
parent
71c6518456
commit
643429de6e
|
@ -340,88 +340,147 @@ final class Lucene70DocValuesProducer extends DocValuesProducer implements Close
|
||||||
return getNumeric(entry);
|
return getNumeric(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static abstract class DenseNumericDocValues extends NumericDocValues {
|
||||||
|
|
||||||
|
final int maxDoc;
|
||||||
|
int doc = -1;
|
||||||
|
|
||||||
|
DenseNumericDocValues(int maxDoc) {
|
||||||
|
this.maxDoc = maxDoc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int docID() {
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int nextDoc() throws IOException {
|
||||||
|
return advance(doc + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int advance(int target) throws IOException {
|
||||||
|
if (target >= maxDoc) {
|
||||||
|
return doc = NO_MORE_DOCS;
|
||||||
|
}
|
||||||
|
return doc = target;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean advanceExact(int target) {
|
||||||
|
doc = target;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long cost() {
|
||||||
|
return maxDoc;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static abstract class SparseNumericDocValues extends NumericDocValues {
|
||||||
|
|
||||||
|
final IndexedDISI disi;
|
||||||
|
|
||||||
|
SparseNumericDocValues(IndexedDISI disi) {
|
||||||
|
this.disi = disi;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int advance(int target) throws IOException {
|
||||||
|
return disi.advance(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean advanceExact(int target) throws IOException {
|
||||||
|
return disi.advanceExact(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int nextDoc() throws IOException {
|
||||||
|
return disi.nextDoc();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int docID() {
|
||||||
|
return disi.docID();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long cost() {
|
||||||
|
return disi.cost();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private NumericDocValues getNumeric(NumericEntry entry) throws IOException {
|
private NumericDocValues getNumeric(NumericEntry entry) throws IOException {
|
||||||
if (entry.docsWithFieldOffset == -2) {
|
if (entry.docsWithFieldOffset == -2) {
|
||||||
// empty
|
// empty
|
||||||
return DocValues.emptyNumeric();
|
return DocValues.emptyNumeric();
|
||||||
} else if (entry.docsWithFieldOffset == -1) {
|
} else if (entry.docsWithFieldOffset == -1) {
|
||||||
// dense
|
// dense
|
||||||
final LongValues normValues = getNumericValues(entry);
|
if (entry.bitsPerValue == 0) {
|
||||||
return new NumericDocValues() {
|
return new DenseNumericDocValues(maxDoc) {
|
||||||
|
@Override
|
||||||
int doc = -1;
|
public long longValue() throws IOException {
|
||||||
|
return entry.minValue;
|
||||||
@Override
|
|
||||||
public long longValue() throws IOException {
|
|
||||||
return normValues.get(doc);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int docID() {
|
|
||||||
return doc;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int nextDoc() throws IOException {
|
|
||||||
return advance(doc + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int advance(int target) throws IOException {
|
|
||||||
if (target >= maxDoc) {
|
|
||||||
return doc = NO_MORE_DOCS;
|
|
||||||
}
|
}
|
||||||
return doc = target;
|
};
|
||||||
|
} else {
|
||||||
|
final RandomAccessInput slice = data.randomAccessSlice(entry.valuesOffset, entry.valuesLength);
|
||||||
|
final LongValues values = DirectReader.getInstance(slice, entry.bitsPerValue);
|
||||||
|
if (entry.table != null) {
|
||||||
|
final long[] table = entry.table;
|
||||||
|
return new DenseNumericDocValues(maxDoc) {
|
||||||
|
@Override
|
||||||
|
public long longValue() throws IOException {
|
||||||
|
return table[(int) values.get(doc)];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
final long mul = entry.gcd;
|
||||||
|
final long delta = entry.minValue;
|
||||||
|
return new DenseNumericDocValues(maxDoc) {
|
||||||
|
@Override
|
||||||
|
public long longValue() throws IOException {
|
||||||
|
return mul * values.get(doc) + delta;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public boolean advanceExact(int target) {
|
|
||||||
doc = target;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long cost() {
|
|
||||||
return maxDoc;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
// sparse
|
// sparse
|
||||||
final LongValues values = getNumericValues(entry);
|
|
||||||
final IndexedDISI disi = new IndexedDISI(data, entry.docsWithFieldOffset, entry.docsWithFieldLength, entry.numValues);
|
final IndexedDISI disi = new IndexedDISI(data, entry.docsWithFieldOffset, entry.docsWithFieldLength, entry.numValues);
|
||||||
return new NumericDocValues() {
|
if (entry.bitsPerValue == 0) {
|
||||||
|
return new SparseNumericDocValues(disi) {
|
||||||
@Override
|
@Override
|
||||||
public int advance(int target) throws IOException {
|
public long longValue() throws IOException {
|
||||||
return disi.advance(target);
|
return entry.minValue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
final RandomAccessInput slice = data.randomAccessSlice(entry.valuesOffset, entry.valuesLength);
|
||||||
|
final LongValues values = DirectReader.getInstance(slice, entry.bitsPerValue);
|
||||||
|
if (entry.table != null) {
|
||||||
|
final long[] table = entry.table;
|
||||||
|
return new SparseNumericDocValues(disi) {
|
||||||
|
@Override
|
||||||
|
public long longValue() throws IOException {
|
||||||
|
return table[(int) values.get(disi.index())];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
final long mul = entry.gcd;
|
||||||
|
final long delta = entry.minValue;
|
||||||
|
return new SparseNumericDocValues(disi) {
|
||||||
|
@Override
|
||||||
|
public long longValue() throws IOException {
|
||||||
|
return mul * values.get(disi.index()) + delta;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public boolean advanceExact(int target) throws IOException {
|
|
||||||
return disi.advanceExact(target);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int nextDoc() throws IOException {
|
|
||||||
return disi.nextDoc();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int docID() {
|
|
||||||
return disi.docID();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long cost() {
|
|
||||||
return disi.cost();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long longValue() throws IOException {
|
|
||||||
return values.get(disi.index());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -467,6 +526,79 @@ final class Lucene70DocValuesProducer extends DocValuesProducer implements Close
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static abstract class DenseBinaryDocValues extends BinaryDocValues {
|
||||||
|
|
||||||
|
final int maxDoc;
|
||||||
|
int doc = -1;
|
||||||
|
|
||||||
|
DenseBinaryDocValues(int maxDoc) {
|
||||||
|
this.maxDoc = maxDoc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int nextDoc() throws IOException {
|
||||||
|
return advance(doc + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int docID() {
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long cost() {
|
||||||
|
return maxDoc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int advance(int target) throws IOException {
|
||||||
|
if (target >= maxDoc) {
|
||||||
|
return doc = NO_MORE_DOCS;
|
||||||
|
}
|
||||||
|
return doc = target;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean advanceExact(int target) throws IOException {
|
||||||
|
doc = target;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static abstract class SparseBinaryDocValues extends BinaryDocValues {
|
||||||
|
|
||||||
|
final IndexedDISI disi;
|
||||||
|
|
||||||
|
SparseBinaryDocValues(IndexedDISI disi) {
|
||||||
|
this.disi = disi;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int nextDoc() throws IOException {
|
||||||
|
return disi.nextDoc();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int docID() {
|
||||||
|
return disi.docID();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long cost() {
|
||||||
|
return disi.cost();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int advance(int target) throws IOException {
|
||||||
|
return disi.advance(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean advanceExact(int target) throws IOException {
|
||||||
|
return disi.advanceExact(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BinaryDocValues getBinary(FieldInfo field) throws IOException {
|
public BinaryDocValues getBinary(FieldInfo field) throws IOException {
|
||||||
BinaryEntry entry = binaries.get(field.name);
|
BinaryEntry entry = binaries.get(field.name);
|
||||||
|
@ -474,116 +606,77 @@ final class Lucene70DocValuesProducer extends DocValuesProducer implements Close
|
||||||
return DocValues.emptyBinary();
|
return DocValues.emptyBinary();
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexInput bytesSlice = data.slice("fixed-binary", entry.dataOffset, entry.dataLength);
|
final IndexInput bytesSlice = data.slice("fixed-binary", entry.dataOffset, entry.dataLength);
|
||||||
BytesRefs bytesRefs;
|
|
||||||
if (entry.minLength == entry.maxLength) {
|
|
||||||
bytesRefs = new BytesRefs() {
|
|
||||||
BytesRef bytes = new BytesRef(new byte[entry.maxLength], 0, entry.maxLength);
|
|
||||||
@Override
|
|
||||||
public BytesRef get(int index) throws IOException {
|
|
||||||
bytesSlice.seek((long) index * bytes.length);
|
|
||||||
bytesSlice.readBytes(bytes.bytes, 0, bytes.length);
|
|
||||||
return bytes;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
final RandomAccessInput addressesData = this.data.randomAccessSlice(entry.addressesOffset, entry.addressesLength);
|
|
||||||
final LongValues addresses = DirectMonotonicReader.getInstance(entry.addressesMeta, addressesData);
|
|
||||||
bytesRefs = new BytesRefs() {
|
|
||||||
BytesRef bytes = new BytesRef(entry.maxLength);
|
|
||||||
@Override
|
|
||||||
BytesRef get(int index) throws IOException {
|
|
||||||
long startOffset = addresses.get(index);
|
|
||||||
bytes.length = (int) (addresses.get(index + 1L) - startOffset);
|
|
||||||
bytesSlice.seek(startOffset);
|
|
||||||
bytesSlice.readBytes(bytes.bytes, 0, bytes.length);
|
|
||||||
return bytes;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entry.docsWithFieldOffset == -1) {
|
if (entry.docsWithFieldOffset == -1) {
|
||||||
// dense
|
// dense
|
||||||
return new BinaryDocValues() {
|
if (entry.minLength == entry.maxLength) {
|
||||||
|
// fixed length
|
||||||
|
final int length = entry.maxLength;
|
||||||
|
return new DenseBinaryDocValues(maxDoc) {
|
||||||
|
final BytesRef bytes = new BytesRef(new byte[length], 0, length);
|
||||||
|
|
||||||
int doc = -1;
|
@Override
|
||||||
|
public BytesRef binaryValue() throws IOException {
|
||||||
@Override
|
bytesSlice.seek((long) doc * length);
|
||||||
public int nextDoc() throws IOException {
|
bytesSlice.readBytes(bytes.bytes, 0, length);
|
||||||
return advance(doc + 1);
|
return bytes;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int docID() {
|
|
||||||
return doc;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long cost() {
|
|
||||||
return maxDoc;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int advance(int target) throws IOException {
|
|
||||||
if (target >= maxDoc) {
|
|
||||||
return doc = NO_MORE_DOCS;
|
|
||||||
}
|
}
|
||||||
return doc = target;
|
};
|
||||||
}
|
} else {
|
||||||
|
// variable length
|
||||||
|
final RandomAccessInput addressesData = this.data.randomAccessSlice(entry.addressesOffset, entry.addressesLength);
|
||||||
|
final LongValues addresses = DirectMonotonicReader.getInstance(entry.addressesMeta, addressesData);
|
||||||
|
return new DenseBinaryDocValues(maxDoc) {
|
||||||
|
final BytesRef bytes = new BytesRef(new byte[entry.maxLength], 0, entry.maxLength);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean advanceExact(int target) throws IOException {
|
public BytesRef binaryValue() throws IOException {
|
||||||
doc = target;
|
long startOffset = addresses.get(doc);
|
||||||
return true;
|
bytes.length = (int) (addresses.get(doc + 1L) - startOffset);
|
||||||
}
|
bytesSlice.seek(startOffset);
|
||||||
|
bytesSlice.readBytes(bytes.bytes, 0, bytes.length);
|
||||||
@Override
|
return bytes;
|
||||||
public BytesRef binaryValue() throws IOException {
|
}
|
||||||
return bytesRefs.get(doc);
|
};
|
||||||
}
|
}
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
// sparse
|
// sparse
|
||||||
final IndexedDISI disi = new IndexedDISI(data, entry.docsWithFieldOffset, entry.docsWithFieldLength, entry.numDocsWithField);
|
final IndexedDISI disi = new IndexedDISI(data, entry.docsWithFieldOffset, entry.docsWithFieldLength, entry.numDocsWithField);
|
||||||
return new BinaryDocValues() {
|
if (entry.minLength == entry.maxLength) {
|
||||||
|
// fixed length
|
||||||
|
final int length = entry.maxLength;
|
||||||
|
return new SparseBinaryDocValues(disi) {
|
||||||
|
final BytesRef bytes = new BytesRef(new byte[length], 0, length);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int nextDoc() throws IOException {
|
public BytesRef binaryValue() throws IOException {
|
||||||
return disi.nextDoc();
|
bytesSlice.seek((long) disi.index() * length);
|
||||||
}
|
bytesSlice.readBytes(bytes.bytes, 0, length);
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
// variable length
|
||||||
|
final RandomAccessInput addressesData = this.data.randomAccessSlice(entry.addressesOffset, entry.addressesLength);
|
||||||
|
final LongValues addresses = DirectMonotonicReader.getInstance(entry.addressesMeta, addressesData);
|
||||||
|
return new SparseBinaryDocValues(disi) {
|
||||||
|
final BytesRef bytes = new BytesRef(new byte[entry.maxLength], 0, entry.maxLength);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int docID() {
|
public BytesRef binaryValue() throws IOException {
|
||||||
return disi.docID();
|
final int index = disi.index();
|
||||||
}
|
long startOffset = addresses.get(index);
|
||||||
|
bytes.length = (int) (addresses.get(index + 1L) - startOffset);
|
||||||
@Override
|
bytesSlice.seek(startOffset);
|
||||||
public long cost() {
|
bytesSlice.readBytes(bytes.bytes, 0, bytes.length);
|
||||||
return disi.cost();
|
return bytes;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
@Override
|
}
|
||||||
public int advance(int target) throws IOException {
|
|
||||||
return disi.advance(target);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean advanceExact(int target) throws IOException {
|
|
||||||
return disi.advanceExact(target);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BytesRef binaryValue() throws IOException {
|
|
||||||
return bytesRefs.get(disi.index());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static abstract class BytesRefs {
|
|
||||||
abstract BytesRef get(int index) throws IOException;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SortedDocValues getSorted(FieldInfo field) throws IOException {
|
public SortedDocValues getSorted(FieldInfo field) throws IOException {
|
||||||
SortedEntry entry = sorted.get(field.name);
|
SortedEntry entry = sorted.get(field.name);
|
||||||
|
|
Loading…
Reference in New Issue