Skip to content

Commit

Permalink
Spotless
Browse files Browse the repository at this point in the history
Signed-off-by: Harsha Vamsi Kalluri <[email protected]>
  • Loading branch information
harshavamsi committed Jun 11, 2024
1 parent 2068f43 commit 6b2acaf
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -467,18 +467,18 @@ public Query rangeQuery(
}
DateMathParser parser = forcedDateParser == null ? dateMathParser : forcedDateParser;
return dateRangeQuery(lowerTerm, upperTerm, includeLower, includeUpper, timeZone, parser, context, resolution, (l, u) -> {
if(isSearchable() && hasDocValues()) {
if (isSearchable() && hasDocValues()) {
Query query = new ApproximateableQuery(
new PointRangeQuery(name(), pack(new long[]{l}).bytes, pack(new long[]{u}).bytes, new long[]{l}.length) {
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
pack(new long[] { l }).bytes,
pack(new long[] { u }).bytes,
new long[] { l }.length
) {
@Override
protected String toString(int dimension, byte[] value) {
Expand All @@ -495,24 +495,24 @@ protected String toString(int dimension, byte[] value) {
}
return query;
}
if(hasDocValues()){
if (hasDocValues()) {
Query query = SortedNumericDocValuesField.newSlowRangeQuery(name(), l, u);
if (context.indexSortedOnField(name())) {
query = new IndexSortSortedNumericDocValuesRangeQuery(name(), l, u, query);
}
return query;
}
return new ApproximateableQuery(
new PointRangeQuery(name(), pack(new long[]{l}).bytes, pack(new long[]{u}).bytes, new long[]{l}.length) {
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
pack(new long[] { l }).bytes,
pack(new long[] { u }).bytes,
new long[] { l }.length
) {
@Override
protected String toString(int dimension, byte[] value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@
import org.opensearch.index.query.DateRangeIncludingNowQuery;
import org.opensearch.index.query.QueryRewriteContext;
import org.opensearch.index.query.QueryShardContext;
import org.joda.time.DateTimeZone;
import org.opensearch.search.approximate.ApproximatePointRangeQuery;
import org.opensearch.search.approximate.ApproximateableQuery;
import org.joda.time.DateTimeZone;

import java.io.IOException;
import java.time.ZoneOffset;
Expand Down Expand Up @@ -213,16 +213,21 @@ public void testTermQuery() {
long instant = DateFormatters.from(DateFieldMapper.getDefaultDateTimeFormatter().parse(date)).toInstant().toEpochMilli();
Query expected = new IndexOrDocValuesQuery(
new ApproximateableQuery(
new PointRangeQuery("field", pack(new long[]{instant}).bytes, pack(new long[]{instant + 999}).bytes, new long[]{instant}.length) {
new PointRangeQuery(
"field",
pack(new long[] { instant }).bytes,
pack(new long[] { instant + 999 }).bytes,
new long[] { instant }.length
) {
protected String toString(int dimension, byte[] value) {
return Long.toString(LongPoint.decodeDimension(value, 0));
}
},
new ApproximatePointRangeQuery(
"field",
pack(new long[]{instant}).bytes,
pack(new long[]{instant + 999}).bytes,
new long[]{instant}.length
pack(new long[] { instant }).bytes,
pack(new long[] { instant + 999 }).bytes,
new long[] { instant }.length
) {
@Override
protected String toString(int dimension, byte[] value) {
Expand Down Expand Up @@ -280,16 +285,21 @@ public void testRangeQuery() throws IOException {
long instant2 = DateFormatters.from(DateFieldMapper.getDefaultDateTimeFormatter().parse(date2)).toInstant().toEpochMilli() + 999;
Query expected = new IndexOrDocValuesQuery(
new ApproximateableQuery(
new PointRangeQuery("field", pack(new long[]{instant1}).bytes, pack(new long[]{instant2}).bytes, new long[]{instant1}.length) {
new PointRangeQuery(
"field",
pack(new long[] { instant1 }).bytes,
pack(new long[] { instant2 }).bytes,
new long[] { instant1 }.length
) {
protected String toString(int dimension, byte[] value) {
return Long.toString(LongPoint.decodeDimension(value, 0));
}
},
new ApproximatePointRangeQuery(
"field",
pack(new long[]{instant1}).bytes,
pack(new long[]{instant2}).bytes,
new long[]{instant1}.length
pack(new long[] { instant1 }).bytes,
pack(new long[] { instant2 }).bytes,
new long[] { instant1 }.length
) {
@Override
protected String toString(int dimension, byte[] value) {
Expand All @@ -309,16 +319,21 @@ protected String toString(int dimension, byte[] value) {
expected = new DateRangeIncludingNowQuery(
new IndexOrDocValuesQuery(
new ApproximateableQuery(
new PointRangeQuery("field", pack(new long[]{instant1}).bytes, pack(new long[]{instant2}).bytes, new long[]{instant1}.length) {
new PointRangeQuery(
"field",
pack(new long[] { instant1 }).bytes,
pack(new long[] { instant2 }).bytes,
new long[] { instant1 }.length
) {
protected String toString(int dimension, byte[] value) {
return Long.toString(LongPoint.decodeDimension(value, 0));
}
},
new ApproximatePointRangeQuery(
"field",
pack(new long[]{instant1}).bytes,
pack(new long[]{instant2}).bytes,
new long[]{instant1}.length
pack(new long[] { instant1 }).bytes,
pack(new long[] { instant2 }).bytes,
new long[] { instant1 }.length
) {
@Override
protected String toString(int dimension, byte[] value) {
Expand Down Expand Up @@ -386,16 +401,21 @@ public void testRangeQueryWithIndexSort() {
long instant2 = DateFormatters.from(DateFieldMapper.getDefaultDateTimeFormatter().parse(date2)).toInstant().toEpochMilli() + 999;

Query pointQuery = new ApproximateableQuery(
new PointRangeQuery("field", pack(new long[]{instant1}).bytes, pack(new long[]{instant2}).bytes, new long[]{instant1}.length) {
new PointRangeQuery(
"field",
pack(new long[] { instant1 }).bytes,
pack(new long[] { instant2 }).bytes,
new long[] { instant1 }.length
) {
protected String toString(int dimension, byte[] value) {
return Long.toString(LongPoint.decodeDimension(value, 0));
}
},
new ApproximatePointRangeQuery(
"field",
pack(new long[]{instant1}).bytes,
pack(new long[]{instant2}).bytes,
new long[]{instant1}.length
pack(new long[] { instant1 }).bytes,
pack(new long[] { instant2 }).bytes,
new long[] { instant1 }.length
) {
@Override
protected String toString(int dimension, byte[] value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
import java.io.IOException;
import java.net.InetAddress;

import static org.apache.lucene.document.LongPoint.pack;
import static org.hamcrest.Matchers.either;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.apache.lucene.document.LongPoint.pack;

public class RangeFieldQueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStringQueryBuilder> {

Expand Down Expand Up @@ -176,18 +176,22 @@ public void testDateRangeQuery() throws Exception {
DateFieldMapper.DateFieldType dateType = (DateFieldMapper.DateFieldType) context.fieldMapper(DATE_FIELD_NAME);
parser = dateType.dateMathParser;
Query queryOnDateField = new QueryStringQueryBuilder(DATE_FIELD_NAME + ":[2010-01-01 TO 2018-01-01]").toQuery(createShardContext());
Query controlQuery =
new ApproximateableQuery(
new PointRangeQuery(DATE_FIELD_NAME, pack(new long[]{parser.parse(lowerBoundExact, () -> 0).toEpochMilli()}).bytes, pack(new long[]{parser.parse(upperBoundExact, () -> 0).toEpochMilli() }).bytes, new long[]{parser.parse(lowerBoundExact, () -> 0).toEpochMilli()}.length) {
Query controlQuery = new ApproximateableQuery(
new PointRangeQuery(
DATE_FIELD_NAME,
pack(new long[] { parser.parse(lowerBoundExact, () -> 0).toEpochMilli() }).bytes,
pack(new long[] { parser.parse(upperBoundExact, () -> 0).toEpochMilli() }).bytes,
new long[] { parser.parse(lowerBoundExact, () -> 0).toEpochMilli() }.length
) {
protected String toString(int dimension, byte[] value) {
return Long.toString(LongPoint.decodeDimension(value, 0));
}
},
new ApproximatePointRangeQuery(
DATE_FIELD_NAME,
pack(new long[]{parser.parse(lowerBoundExact, () -> 0).toEpochMilli()}).bytes,
pack(new long[]{parser.parse(upperBoundExact, () -> 0).toEpochMilli() }).bytes,
new long[]{parser.parse(lowerBoundExact, () -> 0).toEpochMilli()}.length
pack(new long[] { parser.parse(lowerBoundExact, () -> 0).toEpochMilli() }).bytes,
pack(new long[] { parser.parse(upperBoundExact, () -> 0).toEpochMilli() }).bytes,
new long[] { parser.parse(lowerBoundExact, () -> 0).toEpochMilli() }.length
) {
@Override
protected String toString(int dimension, byte[] value) {
Expand Down
Loading

0 comments on commit 6b2acaf

Please sign in to comment.