Skip to content

Commit

Permalink
Add advance(int) for numeric values in order to allow point based opt…
Browse files Browse the repository at this point in the history
…imization to kick in

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
  • Loading branch information
reta committed Jan 30, 2024
1 parent c55af66 commit 0d47358
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 0 deletions.
34 changes: 34 additions & 0 deletions server/src/main/java/org/opensearch/index/fielddata/FieldData.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.lucene.index.NumericDocValues;
import org.apache.lucene.index.SortedNumericDocValues;
import org.apache.lucene.index.SortedSetDocValues;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.util.BytesRef;
import org.opensearch.common.Numbers;
import org.opensearch.common.geo.GeoPoint;
Expand Down Expand Up @@ -76,6 +77,10 @@ public double doubleValue() throws IOException {
throw new UnsupportedOperationException();
}

@Override
public int advance(int target) throws IOException {
return DocIdSetIterator.NO_MORE_DOCS;
}
};
}

Expand Down Expand Up @@ -561,6 +566,10 @@ public boolean advanceExact(int doc) throws IOException {
return values.advanceExact(doc);
}

@Override
public int advance(int target) throws IOException {
return values.advance(target);
}
}

/**
Expand Down Expand Up @@ -591,6 +600,10 @@ public int docValueCount() {
return values.docValueCount();
}

@Override
public int advance(int target) throws IOException {
return values.advance(target);
}
}

/**
Expand Down Expand Up @@ -622,6 +635,12 @@ public long longValue() throws IOException {
public int docID() {
return docID;
}

@Override
public int advance(int target) throws IOException {
docID = values.advance(target);
return docID;
}
}

/**
Expand Down Expand Up @@ -683,6 +702,11 @@ public boolean advanceExact(int target) throws IOException {
public long longValue() throws IOException {
return value;
}

@Override
public int advance(int target) throws IOException {
return values.advance(target);
}
};
}

Expand Down Expand Up @@ -715,6 +739,11 @@ public boolean advanceExact(int target) throws IOException {
public long longValue() throws IOException {
return value.longValue();
}

@Override
public int advance(int target) throws IOException {
return values.advance(target);
}
};
}

Expand Down Expand Up @@ -742,6 +771,11 @@ public boolean advanceExact(int target) throws IOException {
public double doubleValue() throws IOException {
return value;
}

@Override
public int advance(int target) throws IOException {
return values.advance(target);
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public long longValue() throws IOException {
public int docID() {
return docID;
}

@Override
public int advance(int target) throws IOException {
return NumericDoubleValues.this.advance(target);
}
};
}

Expand All @@ -95,6 +100,23 @@ public long longValue() throws IOException {
public int docID() {
return docID;
}

@Override
public int advance(int target) throws IOException {
return NumericDoubleValues.this.advance(target);
}
};
}

/**
* Advances to the first beyond the current whose document number is greater than or equal to
* <i>target</i>, and returns the document number itself. Exhausts the iterator and returns {@link
* #NO_MORE_DOCS} if <i>target</i> is greater than the highest document number in the set.
*
* This method is being used by {@link NumericLeafComparator} when point values optimization kicks
* in and is implemented by most numeric types.
*/
public int advance(int target) throws IOException {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,8 @@ public double nextValue() throws IOException {
return in.doubleValue();
}

@Override
public int advance(int target) throws IOException {
return in.advance(target);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,9 @@ public NumericDoubleValues getDoubleValues() {
return values;
}

@Override
public int advance(int target) throws IOException {
return values.advance(target);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,8 @@ public NumericDocValues getLongValues() {
return values;
}

@Override
public int advance(int target) throws IOException {
return values.advance(target);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,8 @@ public SortedNumericDocValues getLongValues() {
return values;
}

@Override
public int advance(int target) throws IOException {
return values.advance(target);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
package org.opensearch.index.fielddata;

import org.apache.lucene.index.SortedNumericDocValues;
import org.apache.lucene.search.comparators.NumericLeafComparator;
import org.opensearch.common.annotation.PublicApi;

import java.io.IOException;
Expand Down Expand Up @@ -70,4 +71,15 @@ protected SortedNumericDoubleValues() {}
*/
public abstract int docValueCount();

/**
* Advances to the first beyond the current whose document number is greater than or equal to
* <i>target</i>, and returns the document number itself. Exhausts the iterator and returns {@link
* #NO_MORE_DOCS} if <i>target</i> is greater than the highest document number in the set.
*
* This method is being used by {@link NumericLeafComparator} when point values optimization kicks
* in and is implemented by most numeric types.
*/
public int advance(int target) throws IOException {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ public NumericDocValues getLongValues() {
return values;
}

@Override
public int advance(int target) throws IOException {
return values.advance(target);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ public SortedNumericDocValues getLongValues() {
return values;
}

@Override
public int advance(int target) throws IOException {
return values.advance(target);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ public double doubleValue() throws IOException {
public boolean advanceExact(int doc) throws IOException {
return in.advanceExact(doc);
}

@Override
public int advance(int target) throws IOException {
return in.advance(target);
}
}

/**
Expand Down Expand Up @@ -364,6 +369,11 @@ public double nextValue() throws IOException {
public int docValueCount() {
return in.docValueCount();
}

@Override
public int advance(int target) throws IOException {
return in.advance(target);
}
}

/**
Expand Down Expand Up @@ -434,6 +444,11 @@ public double doubleValue() throws IOException {
public boolean advanceExact(int doc) throws IOException {
return in.advanceExact(doc);
}

@Override
public int advance(int target) throws IOException {
return in.advance(target);
}
}

/**
Expand Down Expand Up @@ -462,6 +477,11 @@ public double nextValue() throws IOException {
public int docValueCount() {
return in.docValueCount();
}

@Override
public int advance(int target) throws IOException {
return in.advance(target);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,11 @@ public boolean needsScores() {
protected NumericDoubleValues distance(LeafReaderContext context) {
final SortedNumericDoubleValues doubleValues = fieldData.load(context).getDoubleValues();
return FieldData.replaceMissing(mode.select(new SortingNumericDoubleValues() {
@Override
public int advance(int target) throws IOException {
return doubleValues.advance(target);
}

@Override
public boolean advanceExact(int docId) throws IOException {
if (doubleValues.advanceExact(docId)) {
Expand Down
10 changes: 10 additions & 0 deletions server/src/main/java/org/opensearch/search/MultiValueMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,11 @@ public boolean advanceExact(int target) throws IOException {
public double doubleValue() throws IOException {
return this.value;
}

@Override
public int advance(int target) throws IOException {
return values.advance(target);
}
};
}
}
Expand Down Expand Up @@ -745,6 +750,11 @@ public boolean advanceExact(int parentDoc) throws IOException {
public double doubleValue() throws IOException {
return lastEmittedValue;
}

@Override
public int advance(int target) throws IOException {
return values.advance(target);
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ public String toString() {
return "anon SortedNumericDoubleValues of [" + super.toString() + "]";
}

@Override
public int advance(int target) throws IOException {
return values.advance(target);
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,11 @@ public boolean advanceExact(int target) throws IOException {
}
return false;
}

@Override
public int advance(int target) throws IOException {
return doubleValues.advance(target);
}
}
}

Expand Down

0 comments on commit 0d47358

Please sign in to comment.