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 491da59
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix memory leak issue in ReorganizingLongHash ([#11953](https://github.com/opensearch-project/OpenSearch/issues/11953))
- Prevent setting remote_snapshot store type on index creation ([#11867](https://github.com/opensearch-project/OpenSearch/pull/11867))
- [BUG] Fix remote shards balancer when filtering throttled nodes ([#11724](https://github.com/opensearch-project/OpenSearch/pull/11724))
- Add advance(int) for numeric values in order to allow point based optimization to kick in ([#12089](https://github.com/opensearch-project/OpenSearch/pull/12089))

### Security

Expand Down
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;

Check warning on line 82 in server/src/main/java/org/opensearch/index/fielddata/FieldData.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/fielddata/FieldData.java#L82

Added line #L82 was not covered by tests
}
};
}

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);

Check warning on line 571 in server/src/main/java/org/opensearch/index/fielddata/FieldData.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/fielddata/FieldData.java#L571

Added line #L571 was not covered by tests
}
}

/**
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);

Check warning on line 605 in server/src/main/java/org/opensearch/index/fielddata/FieldData.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/fielddata/FieldData.java#L605

Added line #L605 was not covered by tests
}
}

/**
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;

Check warning on line 642 in server/src/main/java/org/opensearch/index/fielddata/FieldData.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/fielddata/FieldData.java#L641-L642

Added lines #L641 - L642 were not covered by tests
}
}

/**
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);

Check warning on line 708 in server/src/main/java/org/opensearch/index/fielddata/FieldData.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/fielddata/FieldData.java#L708

Added line #L708 was not covered by tests
}
};
}

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);

Check warning on line 745 in server/src/main/java/org/opensearch/index/fielddata/FieldData.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/fielddata/FieldData.java#L745

Added line #L745 was not covered by tests
}
};
}

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);

Check warning on line 777 in server/src/main/java/org/opensearch/index/fielddata/FieldData.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/fielddata/FieldData.java#L777

Added line #L777 was not covered by tests
}
};
}
}
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);

Check warning on line 77 in server/src/main/java/org/opensearch/index/fielddata/NumericDoubleValues.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/fielddata/NumericDoubleValues.java#L77

Added line #L77 was not covered by tests
}
};
}

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);

Check warning on line 106 in server/src/main/java/org/opensearch/index/fielddata/NumericDoubleValues.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/fielddata/NumericDoubleValues.java#L106

Added line #L106 was not covered by tests
}
};
}

/**
* 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
* org.apache.lucene.search.DocIdSetIterator#NO_MORE_DOCS} if <i>target</i> is greater than the highest document number in the set.
*
* This method is being used by {@link org.apache.lucene.search.comparators.NumericComparator.NumericLeafComparator} when point values optimization kicks
* in and is implemented by most numeric types.
*/
public int advance(int target) throws IOException {
throw new UnsupportedOperationException();

Check warning on line 120 in server/src/main/java/org/opensearch/index/fielddata/NumericDoubleValues.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/fielddata/NumericDoubleValues.java#L120

Added line #L120 was not covered by tests
}
}
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);

Check warning on line 74 in server/src/main/java/org/opensearch/index/fielddata/SingletonSortedNumericDoubleValues.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/fielddata/SingletonSortedNumericDoubleValues.java#L74

Added line #L74 was not covered by tests
}
}
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);

Check warning on line 79 in server/src/main/java/org/opensearch/index/fielddata/SortableLongBitsNumericDocValues.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/fielddata/SortableLongBitsNumericDocValues.java#L79

Added line #L79 was not covered by tests
}

}
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);

Check warning on line 72 in server/src/main/java/org/opensearch/index/fielddata/SortableLongBitsToNumericDoubleValues.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/fielddata/SortableLongBitsToNumericDoubleValues.java#L72

Added line #L72 was not covered by tests
}
}
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);

Check warning on line 77 in server/src/main/java/org/opensearch/index/fielddata/SortableLongBitsToSortedNumericDoubleValues.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/fielddata/SortableLongBitsToSortedNumericDoubleValues.java#L77

Added line #L77 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,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
* org.apache.lucene.search.DocIdSetIterator#NO_MORE_DOCS} if <i>target</i> is greater than the highest document number in the set.
*
* This method is being used by {@link org.apache.lucene.search.comparators.NumericComparator.NumericLeafComparator} when point values optimization kicks
* in and is implemented by most numeric types.
*/
public int advance(int target) throws IOException {
throw new UnsupportedOperationException();

Check warning on line 82 in server/src/main/java/org/opensearch/index/fielddata/SortedNumericDoubleValues.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/fielddata/SortedNumericDoubleValues.java#L82

Added line #L82 was not covered by tests
}
}
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);

Check warning on line 47 in server/src/main/java/org/opensearch/index/fielddata/UnsignedLongToNumericDoubleValues.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/fielddata/UnsignedLongToNumericDoubleValues.java#L47

Added line #L47 was not covered by tests
}
}
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);

Check warning on line 52 in server/src/main/java/org/opensearch/index/fielddata/UnsignedLongToSortedNumericDoubleValues.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/fielddata/UnsignedLongToSortedNumericDoubleValues.java#L52

Added line #L52 was not covered by tests
}
}
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);

Check warning on line 342 in server/src/main/java/org/opensearch/index/fielddata/plain/SortedNumericIndexFieldData.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/fielddata/plain/SortedNumericIndexFieldData.java#L342

Added line #L342 was not covered by tests
}
}

/**
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);

Check warning on line 375 in server/src/main/java/org/opensearch/index/fielddata/plain/SortedNumericIndexFieldData.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/fielddata/plain/SortedNumericIndexFieldData.java#L375

Added line #L375 was not covered by tests
}
}

/**
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);

Check warning on line 450 in server/src/main/java/org/opensearch/index/fielddata/plain/SortedNumericIndexFieldData.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/fielddata/plain/SortedNumericIndexFieldData.java#L450

Added line #L450 was not covered by tests
}
}

/**
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);

Check warning on line 483 in server/src/main/java/org/opensearch/index/fielddata/plain/SortedNumericIndexFieldData.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/fielddata/plain/SortedNumericIndexFieldData.java#L483

Added line #L483 was not covered by tests
}
}

/**
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);

Check warning on line 565 in server/src/main/java/org/opensearch/index/query/functionscore/DecayFunctionBuilder.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/query/functionscore/DecayFunctionBuilder.java#L565

Added line #L565 was not covered by tests
}

@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);

Check warning on line 691 in server/src/main/java/org/opensearch/search/MultiValueMode.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/search/MultiValueMode.java#L691

Added line #L691 was not covered by tests
}
};
}
}
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);

Check warning on line 756 in server/src/main/java/org/opensearch/search/MultiValueMode.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/search/MultiValueMode.java#L756

Added line #L756 was not covered by tests
}
};
}

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);

Check warning on line 232 in server/src/main/java/org/opensearch/search/aggregations/support/MissingValues.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/search/aggregations/support/MissingValues.java#L232

Added line #L232 was not covered by tests
}
};
}

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);

Check warning on line 582 in server/src/main/java/org/opensearch/search/aggregations/support/ValuesSource.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/search/aggregations/support/ValuesSource.java#L582

Added line #L582 was not covered by tests
}
}
}

Expand Down

0 comments on commit 491da59

Please sign in to comment.