From 6b2acaf1c6b825c5e60195beca0d7157f091e3e6 Mon Sep 17 00:00:00 2001 From: Harsha Vamsi Kalluri Date: Tue, 11 Jun 2024 00:19:36 +0000 Subject: [PATCH] Spotless Signed-off-by: Harsha Vamsi Kalluri --- .../index/mapper/DateFieldMapper.java | 20 ++-- .../index/mapper/DateFieldTypeTests.java | 54 +++++++---- ...angeFieldQueryStringQueryBuilderTests.java | 18 ++-- .../index/query/RangeQueryBuilderTests.java | 96 +++++++++++-------- .../ApproximatePointRangeQueryTests.java | 16 +++- 5 files changed, 130 insertions(+), 74 deletions(-) diff --git a/server/src/main/java/org/opensearch/index/mapper/DateFieldMapper.java b/server/src/main/java/org/opensearch/index/mapper/DateFieldMapper.java index c4b94e9830584..05786050cedd9 100644 --- a/server/src/main/java/org/opensearch/index/mapper/DateFieldMapper.java +++ b/server/src/main/java/org/opensearch/index/mapper/DateFieldMapper.java @@ -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) { @@ -495,7 +495,7 @@ 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); @@ -503,16 +503,16 @@ protected String toString(int dimension, byte[] value) { 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) { diff --git a/server/src/test/java/org/opensearch/index/mapper/DateFieldTypeTests.java b/server/src/test/java/org/opensearch/index/mapper/DateFieldTypeTests.java index 8dfc30ad93654..02c923acca290 100644 --- a/server/src/test/java/org/opensearch/index/mapper/DateFieldTypeTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/DateFieldTypeTests.java @@ -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; @@ -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) { @@ -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) { @@ -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) { @@ -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) { diff --git a/server/src/test/java/org/opensearch/index/mapper/RangeFieldQueryStringQueryBuilderTests.java b/server/src/test/java/org/opensearch/index/mapper/RangeFieldQueryStringQueryBuilderTests.java index dd00cd2f5bca4..725b6e6ef6238 100644 --- a/server/src/test/java/org/opensearch/index/mapper/RangeFieldQueryStringQueryBuilderTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/RangeFieldQueryStringQueryBuilderTests.java @@ -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 { @@ -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) { diff --git a/server/src/test/java/org/opensearch/index/query/RangeQueryBuilderTests.java b/server/src/test/java/org/opensearch/index/query/RangeQueryBuilderTests.java index ce6dc1fa1ba0d..0c3e0c4c6bb4c 100644 --- a/server/src/test/java/org/opensearch/index/query/RangeQueryBuilderTests.java +++ b/server/src/test/java/org/opensearch/index/query/RangeQueryBuilderTests.java @@ -66,11 +66,11 @@ import java.util.HashMap; import java.util.Map; -import static org.apache.lucene.document.LongPoint.pack; import static org.opensearch.index.query.QueryBuilders.rangeQuery; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.sameInstance; +import static org.apache.lucene.document.LongPoint.pack; public class RangeQueryBuilderTests extends AbstractQueryTestCase { @Override @@ -188,7 +188,7 @@ protected void doAssertLuceneQuery(RangeQueryBuilder queryBuilder, Query query, } else if (expectedFieldName.equals(DATE_FIELD_NAME)) { assertThat(query, instanceOf(IndexOrDocValuesQuery.class)); query = ((IndexOrDocValuesQuery) query).getIndexQuery(); - assertThat(query, instanceOf(ApproximateableQuery.class)); + assertThat(query, instanceOf(ApproximateableQuery.class)); MapperService mapperService = context.getMapperService(); MappedFieldType mappedFieldType = mapperService.fieldType(expectedFieldName); final Long fromInMillis; @@ -237,27 +237,32 @@ protected void doAssertLuceneQuery(RangeQueryBuilder queryBuilder, Query query, maxLong--; } } - assertEquals( - new ApproximateableQuery( - new PointRangeQuery(DATE_FIELD_NAME, pack(new long[]{minLong}).bytes, pack(new long[]{maxLong}).bytes, new long[]{minLong}.length) { - protected String toString(int dimension, byte[] value) { - return Long.toString(LongPoint.decodeDimension(value, 0)); - } - }, - new ApproximatePointRangeQuery( - DATE_FIELD_NAME, - pack(new long[]{minLong}).bytes, - pack(new long[]{maxLong}).bytes, - new long[]{minLong}.length - ) { - @Override - protected String toString(int dimension, byte[] value) { - return Long.toString(LongPoint.decodeDimension(value, 0)); + assertEquals( + new ApproximateableQuery( + new PointRangeQuery( + DATE_FIELD_NAME, + pack(new long[] { minLong }).bytes, + pack(new long[] { maxLong }).bytes, + new long[] { minLong }.length + ) { + protected String toString(int dimension, byte[] value) { + return Long.toString(LongPoint.decodeDimension(value, 0)); + } + }, + new ApproximatePointRangeQuery( + DATE_FIELD_NAME, + pack(new long[] { minLong }).bytes, + pack(new long[] { maxLong }).bytes, + new long[] { minLong }.length + ) { + @Override + protected String toString(int dimension, byte[] value) { + return Long.toString(LongPoint.decodeDimension(value, 0)); + } } - } - ).toString(), - query.toString() - ); + ).toString(), + query.toString() + ); } else if (expectedFieldName.equals(INT_FIELD_NAME)) { assertThat(query, instanceOf(IndexOrDocValuesQuery.class)); query = ((IndexOrDocValuesQuery) query).getIndexQuery(); @@ -330,16 +335,21 @@ public void testDateRangeQueryFormat() throws IOException { long upper = DateTime.parse("2030-01-01T00:00:00.000+00").getMillis() - 1; assertEquals( new ApproximateableQuery( - new PointRangeQuery(DATE_FIELD_NAME, pack(new long[]{lower}).bytes, pack(new long[]{upper}).bytes, new long[]{lower}.length) { + new PointRangeQuery( + DATE_FIELD_NAME, + pack(new long[] { lower }).bytes, + pack(new long[] { upper }).bytes, + new long[] { lower }.length + ) { protected String toString(int dimension, byte[] value) { return Long.toString(LongPoint.decodeDimension(value, 0)); } }, new ApproximatePointRangeQuery( DATE_FIELD_NAME, - pack(new long[]{lower}).bytes, - pack(new long[]{upper}).bytes, - new long[]{lower}.length + pack(new long[] { lower }).bytes, + pack(new long[] { upper }).bytes, + new long[] { lower }.length ) { @Override protected String toString(int dimension, byte[] value) { @@ -381,20 +391,25 @@ public void testDateRangeBoundaries() throws IOException { parsedQuery = ((IndexOrDocValuesQuery) parsedQuery).getIndexQuery(); assertThat(parsedQuery, instanceOf(ApproximateableQuery.class)); - long lower = DateTime.parse("2014-11-01T00:00:00.000+00").getMillis(); - long upper = DateTime.parse("2014-12-08T23:59:59.999+00").getMillis(); + long lower = DateTime.parse("2014-11-01T00:00:00.000+00").getMillis(); + long upper = DateTime.parse("2014-12-08T23:59:59.999+00").getMillis(); assertEquals( new ApproximateableQuery( - new PointRangeQuery(DATE_FIELD_NAME, pack(new long[]{lower}).bytes, pack(new long[]{upper}).bytes, new long[]{lower}.length) { + new PointRangeQuery( + DATE_FIELD_NAME, + pack(new long[] { lower }).bytes, + pack(new long[] { upper }).bytes, + new long[] { lower }.length + ) { protected String toString(int dimension, byte[] value) { return Long.toString(LongPoint.decodeDimension(value, 0)); } }, new ApproximatePointRangeQuery( DATE_FIELD_NAME, - pack(new long[]{lower}).bytes, - pack(new long[]{upper}).bytes, - new long[]{lower}.length + pack(new long[] { lower }).bytes, + pack(new long[] { upper }).bytes, + new long[] { lower }.length ) { @Override protected String toString(int dimension, byte[] value) { @@ -419,20 +434,25 @@ protected String toString(int dimension, byte[] value) { assertThat(parsedQuery, instanceOf(IndexOrDocValuesQuery.class)); parsedQuery = ((IndexOrDocValuesQuery) parsedQuery).getIndexQuery(); assertThat(parsedQuery, instanceOf(ApproximateableQuery.class)); - lower = DateTime.parse("2014-11-30T23:59:59.999+00").getMillis() + 1; - upper = DateTime.parse("2014-12-08T00:00:00.000+00").getMillis() - 1; + lower = DateTime.parse("2014-11-30T23:59:59.999+00").getMillis() + 1; + upper = DateTime.parse("2014-12-08T00:00:00.000+00").getMillis() - 1; assertEquals( new ApproximateableQuery( - new PointRangeQuery(DATE_FIELD_NAME, pack(new long[]{lower}).bytes, pack(new long[]{upper}).bytes, new long[]{lower}.length) { + new PointRangeQuery( + DATE_FIELD_NAME, + pack(new long[] { lower }).bytes, + pack(new long[] { upper }).bytes, + new long[] { lower }.length + ) { protected String toString(int dimension, byte[] value) { return Long.toString(LongPoint.decodeDimension(value, 0)); } }, new ApproximatePointRangeQuery( DATE_FIELD_NAME, - pack(new long[]{lower}).bytes, - pack(new long[]{upper}).bytes, - new long[]{lower}.length + pack(new long[] { lower }).bytes, + pack(new long[] { upper }).bytes, + new long[] { lower }.length ) { @Override protected String toString(int dimension, byte[] value) { diff --git a/server/src/test/java/org/opensearch/search/approximate/ApproximatePointRangeQueryTests.java b/server/src/test/java/org/opensearch/search/approximate/ApproximatePointRangeQueryTests.java index 2f952494fc010..f376bc22ff057 100644 --- a/server/src/test/java/org/opensearch/search/approximate/ApproximatePointRangeQueryTests.java +++ b/server/src/test/java/org/opensearch/search/approximate/ApproximatePointRangeQueryTests.java @@ -95,12 +95,24 @@ public void testApproximateRangeWithSize() throws IOException { try { long lower = 0; long upper = 100; - Query approximateQuerySmall = new ApproximatePointRangeQuery("point", pack(lower).bytes, pack(upper).bytes, dims, 10) { + Query approximateQuerySmall = 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)); } }; - Query approximateQueryBig = new ApproximatePointRangeQuery("point", pack(lower).bytes, pack(upper).bytes, dims, 100) { + Query approximateQueryBig = new ApproximatePointRangeQuery( + "point", + pack(lower).bytes, + pack(upper).bytes, + dims, + 100 + ) { protected String toString(int dimension, byte[] value) { return Long.toString(LongPoint.decodeDimension(value, 0)); }