Skip to content

Commit

Permalink
Spotless apply
Browse files Browse the repository at this point in the history
Signed-off-by: Harsha Vamsi Kalluri <[email protected]>
  • Loading branch information
harshavamsi committed Jul 24, 2024
1 parent 46f9587 commit 80a30b5
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -490,22 +490,22 @@ public Query rangeQuery(

private Query createPointRangeQuery(long l, long u) {
return new ApproximateScoreQuery(
new PointRangeQuery(name(), pack(new long[]{l}).bytes, pack(new long[]{u}).bytes, new long[]{l}.length) {
protected String toString(int dimension, byte[] value) {
return Long.toString(LongPoint.decodeDimension(value, 0));
}
},
new ApproximatePointRangeQuery(
name(),
pack(new long[]{l}).bytes,
pack(new long[]{u}).bytes,
new long[]{l}.length
) {
@Override
protected String toString(int dimension, byte[] value) {
return Long.toString(LongPoint.decodeDimension(value, 0));
}
new PointRangeQuery(name(), pack(new long[] { l }).bytes, pack(new long[] { u }).bytes, new long[] { l }.length) {
protected String toString(int dimension, byte[] value) {
return Long.toString(LongPoint.decodeDimension(value, 0));
}
},
new ApproximatePointRangeQuery(
name(),
pack(new long[] { l }).bytes,
pack(new long[] { u }).bytes,
new long[] { l }.length
) {
@Override
protected String toString(int dimension, byte[] value) {
return Long.toString(LongPoint.decodeDimension(value, 0));
}
}
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected ApproximateConstantScoreWeight(Query query, float score) {
super(query, score);
}

protected abstract long intersectLeft(PointValues.IntersectVisitor visitor, PointValues.PointTree pointTree) throws IOException;
protected abstract long intersectLeft(PointValues.IntersectVisitor visitor, PointValues.PointTree pointTree) throws IOException;

protected abstract long intersectRight(PointValues.IntersectVisitor visitor, PointValues.PointTree pointTree) throws IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.PointValues;
import org.apache.lucene.search.ConstantScoreScorer;
import org.apache.lucene.search.ConstantScoreWeight;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.PointRangeQuery;
Expand All @@ -30,8 +29,6 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Predicate;

/**
* An approximate-able version of {@link PointRangeQuery}. It creates an instance of {@link PointRangeQuery} but short-circuits the intersect logic
Expand Down Expand Up @@ -90,7 +87,6 @@ public void visit(QueryVisitor visitor) {
public final ApproximateConstantScoreWeight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException {
Weight pointRangeQueryWeight = pointRangeQuery.createWeight(searcher, scoreMode, boost);


return new ApproximateConstantScoreWeight(this, boost) {

private final ArrayUtil.ByteArrayComparator comparator = ArrayUtil.getUnsignedComparator(pointRangeQuery.getBytesPerDim());
Expand Down Expand Up @@ -204,21 +200,18 @@ private boolean checkValidPointValues(PointValues values) throws IOException {
return true;
}

private void intersectLeft(PointValues.PointTree pointTree, PointValues.IntersectVisitor visitor)
throws IOException {
private void intersectLeft(PointValues.PointTree pointTree, PointValues.IntersectVisitor visitor) throws IOException {
intersectLeft(visitor, pointTree);
assert pointTree.moveToParent() == false;
}

private void intersectRight(PointValues.PointTree pointTree, PointValues.IntersectVisitor visitor)
throws IOException {
private void intersectRight(PointValues.PointTree pointTree, PointValues.IntersectVisitor visitor) throws IOException {
intersectRight(visitor, pointTree);
assert pointTree.moveToParent() == false;
}

// custom intersect visitor to walk the left of the tree
public long intersectLeft(PointValues.IntersectVisitor visitor, PointValues.PointTree pointTree)
throws IOException {
public long intersectLeft(PointValues.IntersectVisitor visitor, PointValues.PointTree pointTree) throws IOException {
PointValues.Relation r = visitor.compare(pointTree.getMinPackedValue(), pointTree.getMaxPackedValue());
if (docCount[0] >= size) {
return 0;
Expand Down Expand Up @@ -269,8 +262,7 @@ public long intersectLeft(PointValues.IntersectVisitor visitor, PointValues.Poin
}

// custom intersect visitor to walk the right of tree
public long intersectRight(PointValues.IntersectVisitor visitor, PointValues.PointTree pointTree)
throws IOException {
public long intersectRight(PointValues.IntersectVisitor visitor, PointValues.PointTree pointTree) throws IOException {
PointValues.Relation r = visitor.compare(pointTree.getMinPackedValue(), pointTree.getMaxPackedValue());
if (docCount[0] >= size) {
return 0;
Expand Down Expand Up @@ -316,7 +308,8 @@ public long intersectRight(PointValues.IntersectVisitor visitor, PointValues.Poi
default:
throw new IllegalArgumentException("Unreachable code");
}
// docCount can be updated by the local visitor, so we ensure that we return docCount after pointTree.visitDocValues(visitor)
// docCount can be updated by the local visitor, so we ensure that we return docCount after
// pointTree.visitDocValues(visitor)
return docCount[0] > 0 ? docCount[0] : 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -862,14 +862,8 @@ public void testToQueryDateWithTimeZone() throws Exception {
long upper = 86399999; // 1970-01-01T23:59:59.999 UTC
assertEquals(calculateExpectedDateQuery(lower, upper), query);
int msPerHour = 3600000;
assertEquals(
calculateExpectedDateQuery(lower - msPerHour, upper - msPerHour),
qsq.timeZone("+01:00").toQuery(context)
);
assertEquals(
calculateExpectedDateQuery(lower + msPerHour, upper + msPerHour),
qsq.timeZone("-01:00").toQuery(context)
);
assertEquals(calculateExpectedDateQuery(lower - msPerHour, upper - msPerHour), qsq.timeZone("+01:00").toQuery(context));
assertEquals(calculateExpectedDateQuery(lower + msPerHour, upper + msPerHour), qsq.timeZone("-01:00").toQuery(context));
}

private IndexOrDocValuesQuery calculateExpectedDateQuery(long lower, long upper) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,17 @@
import org.apache.lucene.search.PointRangeQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.ScorerSupplier;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.search.TotalHits;
import org.apache.lucene.search.Weight;
import org.apache.lucene.store.Directory;
import org.apache.lucene.tests.index.RandomIndexWriter;
import org.apache.lucene.util.DocIdSetBuilder;
import org.opensearch.search.sort.SortOrder;
import org.opensearch.test.OpenSearchTestCase;

import java.io.IOException;
import java.lang.reflect.Method;

import static org.apache.lucene.document.LongPoint.pack;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.*;

public class ApproximatePointRangeQueryTests extends OpenSearchTestCase {

Expand Down Expand Up @@ -106,12 +100,7 @@ public void testApproximateRangeWithDefaultSize() throws IOException {
try {
long lower = 0;
long upper = 1000;
Query approximateQuery = new ApproximatePointRangeQuery(
"point",
pack(lower).bytes,
pack(upper).bytes,
dims
) {
Query approximateQuery = new ApproximatePointRangeQuery("point", pack(lower).bytes, pack(upper).bytes, dims) {
protected String toString(int dimension, byte[] value) {
return Long.toString(LongPoint.decodeDimension(value, 0));
}
Expand Down Expand Up @@ -149,13 +138,7 @@ public void testApproximateRangeWithSizeUnderDefault() throws IOException {
try {
long lower = 0;
long upper = 45;
Query approximateQuery = new ApproximatePointRangeQuery(
"point",
pack(lower).bytes,
pack(upper).bytes,
dims,
10
) {
Query approximateQuery = new ApproximatePointRangeQuery("point", pack(lower).bytes, pack(upper).bytes, dims, 10) {
protected String toString(int dimension, byte[] value) {
return Long.toString(LongPoint.decodeDimension(value, 0));
}
Expand Down Expand Up @@ -193,11 +176,11 @@ public void testApproximateRangeWithSizeOverDefault() throws IOException {
long lower = 0;
long upper = 12000;
Query approximateQuery = new ApproximatePointRangeQuery(
"point",
pack(lower).bytes,
pack(upper).bytes,
dims,
11_000
"point",
pack(lower).bytes,
pack(upper).bytes,
dims,
11_000
) {
protected String toString(int dimension, byte[] value) {
return Long.toString(LongPoint.decodeDimension(value, 0));
Expand Down Expand Up @@ -285,12 +268,12 @@ public void testApproximateRangeShortCircuitAscSort() throws IOException {
long lower = 0;
long upper = 20;
Query approximateQuery = new ApproximatePointRangeQuery(
"point",
pack(lower).bytes,
pack(upper).bytes,
dims,
10,
SortOrder.ASC
"point",
pack(lower).bytes,
pack(upper).bytes,
dims,
10,
SortOrder.ASC
) {
protected String toString(int dimension, byte[] value) {
return Long.toString(LongPoint.decodeDimension(value, 0));
Expand Down Expand Up @@ -346,18 +329,22 @@ public void testIntersectLeft() throws IOException {
long lower = 0;
long upper = 20;
ApproximatePointRangeQuery approximatePointRangeQuery = new ApproximatePointRangeQuery(
"point",
pack(lower).bytes,
pack(upper).bytes,
dims,
10
"point",
pack(lower).bytes,
pack(upper).bytes,
dims,
10
) {
protected String toString(int dimension, byte[] value) {
return Long.toString(LongPoint.decodeDimension(value, 0));
}
};
IndexSearcher searcher = new IndexSearcher(reader);
ApproximateConstantScoreWeight approximatePointRangeQueryWeight = approximatePointRangeQuery.createWeight(searcher, ScoreMode.TOP_SCORES, 1.0F);
ApproximateConstantScoreWeight approximatePointRangeQueryWeight = approximatePointRangeQuery.createWeight(
searcher,
ScoreMode.TOP_SCORES,
1.0F
);
LeafReaderContext lrc = reader.leaves().get(0);
PointValues values = lrc.reader().getPointValues("point");
final DocIdSetBuilder result = new DocIdSetBuilder(reader.maxDoc(), values, "point");
Expand Down Expand Up @@ -396,18 +383,22 @@ public void testIntersectRight() throws IOException {
long lower = 0;
long upper = 20;
ApproximatePointRangeQuery approximatePointRangeQuery = new ApproximatePointRangeQuery(
"point",
pack(lower).bytes,
pack(upper).bytes,
dims,
10
"point",
pack(lower).bytes,
pack(upper).bytes,
dims,
10
) {
protected String toString(int dimension, byte[] value) {
return Long.toString(LongPoint.decodeDimension(value, 0));
}
};
IndexSearcher searcher = new IndexSearcher(reader);
ApproximateConstantScoreWeight approximatePointRangeQueryWeight = approximatePointRangeQuery.createWeight(searcher, ScoreMode.TOP_SCORES, 1.0F);
ApproximateConstantScoreWeight approximatePointRangeQueryWeight = approximatePointRangeQuery.createWeight(
searcher,
ScoreMode.TOP_SCORES,
1.0F
);
LeafReaderContext lrc = reader.leaves().get(0);
PointValues values = lrc.reader().getPointValues("point");
final DocIdSetBuilder result = new DocIdSetBuilder(reader.maxDoc(), values, "point");
Expand Down

0 comments on commit 80a30b5

Please sign in to comment.