From 1f8dcc6503b6d18ed2ae771204342bcb1e103186 Mon Sep 17 00:00:00 2001 From: expani Date: Fri, 25 Oct 2024 14:45:41 +0530 Subject: [PATCH 01/12] Changes to unmapped fields in metric aggregation factory Signed-off-by: expani --- .../datacube/startree/utils/StarTreeQueryHelper.java | 2 +- .../aggregations/support/ValuesSourceAggregatorFactory.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/utils/StarTreeQueryHelper.java b/server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/utils/StarTreeQueryHelper.java index e538be5d5bece..e46cf6f56b36e 100644 --- a/server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/utils/StarTreeQueryHelper.java +++ b/server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/utils/StarTreeQueryHelper.java @@ -152,7 +152,7 @@ private static MetricStat validateStarTreeMetricSupport( MetricStat metricStat = ((MetricAggregatorFactory) aggregatorFactory).getMetricStat(); field = ((MetricAggregatorFactory) aggregatorFactory).getField(); - if (supportedMetrics.containsKey(field) && supportedMetrics.get(field).contains(metricStat)) { + if (field != null && supportedMetrics.containsKey(field) && supportedMetrics.get(field).contains(metricStat)) { return metricStat; } } diff --git a/server/src/main/java/org/opensearch/search/aggregations/support/ValuesSourceAggregatorFactory.java b/server/src/main/java/org/opensearch/search/aggregations/support/ValuesSourceAggregatorFactory.java index d862b2c2784de..41344fd06cbbc 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/support/ValuesSourceAggregatorFactory.java +++ b/server/src/main/java/org/opensearch/search/aggregations/support/ValuesSourceAggregatorFactory.java @@ -104,6 +104,6 @@ public String getStatsSubtype() { } public String getField() { - return config.fieldContext().field(); + return config.fieldContext() != null ? config.fieldContext().field() : null; } } From 47b2996d1056b97bf5187a6bad5231d147f2be19 Mon Sep 17 00:00:00 2001 From: expani Date: Wed, 11 Dec 2024 14:51:55 -0800 Subject: [PATCH 02/12] Added unit test for unmapped fields Signed-off-by: expani --- .../ValuesSourceAggregatorFactory.java | 3 +- .../startree/MetricAggregatorTests.java | 47 ++++++++++++++++--- .../startree/StarTreeFilterTests.java | 32 ++++++++++++- .../aggregations/AggregatorTestCase.java | 24 +++++++--- 4 files changed, 89 insertions(+), 17 deletions(-) diff --git a/server/src/main/java/org/opensearch/search/aggregations/support/ValuesSourceAggregatorFactory.java b/server/src/main/java/org/opensearch/search/aggregations/support/ValuesSourceAggregatorFactory.java index 41344fd06cbbc..ed18874d09677 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/support/ValuesSourceAggregatorFactory.java +++ b/server/src/main/java/org/opensearch/search/aggregations/support/ValuesSourceAggregatorFactory.java @@ -104,6 +104,7 @@ public String getStatsSubtype() { } public String getField() { - return config.fieldContext() != null ? config.fieldContext().field() : null; + return config.fieldContext().field(); + //return config.fieldContext() != null ? config.fieldContext().field() : null; } } diff --git a/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java b/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java index 12e83cbbadd5d..2cfdd2eb4a388 100644 --- a/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java +++ b/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java @@ -9,7 +9,6 @@ package org.opensearch.search.aggregations.startree; import com.carrotsearch.randomizedtesting.RandomizedTest; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.lucene.codecs.Codec; @@ -25,9 +24,15 @@ import org.apache.lucene.search.Query; import org.apache.lucene.store.Directory; import org.apache.lucene.tests.index.RandomIndexWriter; +import org.junit.After; +import org.junit.Before; import org.opensearch.common.lucene.Lucene; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.FeatureFlags; +import org.opensearch.common.util.MockBigArrays; +import org.opensearch.common.util.MockPageCacheRecycler; +import org.opensearch.core.indices.breaker.CircuitBreakerService; +import org.opensearch.core.indices.breaker.NoneCircuitBreakerService; import org.opensearch.index.codec.composite.CompositeIndexFieldInfo; import org.opensearch.index.codec.composite.CompositeIndexReader; import org.opensearch.index.codec.composite.composite912.Composite912Codec; @@ -38,8 +43,10 @@ import org.opensearch.index.mapper.MapperService; import org.opensearch.index.mapper.NumberFieldMapper; import org.opensearch.index.query.QueryBuilder; +import org.opensearch.index.query.QueryShardContext; import org.opensearch.index.query.TermQueryBuilder; import org.opensearch.search.aggregations.AggregationBuilder; +import org.opensearch.search.aggregations.AggregatorFactory; import org.opensearch.search.aggregations.AggregatorTestCase; import org.opensearch.search.aggregations.InternalAggregation; import org.opensearch.search.aggregations.metrics.AvgAggregationBuilder; @@ -52,8 +59,6 @@ import org.opensearch.search.aggregations.metrics.MinAggregationBuilder; import org.opensearch.search.aggregations.metrics.SumAggregationBuilder; import org.opensearch.search.aggregations.metrics.ValueCountAggregationBuilder; -import org.junit.After; -import org.junit.Before; import java.io.IOException; import java.util.ArrayList; @@ -63,11 +68,12 @@ import java.util.function.BiConsumer; import java.util.function.Function; -import static org.opensearch.search.aggregations.AggregationBuilders.avg; -import static org.opensearch.search.aggregations.AggregationBuilders.count; -import static org.opensearch.search.aggregations.AggregationBuilders.max; -import static org.opensearch.search.aggregations.AggregationBuilders.min; + import static org.opensearch.search.aggregations.AggregationBuilders.sum; +import static org.opensearch.search.aggregations.AggregationBuilders.min; +import static org.opensearch.search.aggregations.AggregationBuilders.max; +import static org.opensearch.search.aggregations.AggregationBuilders.count; +import static org.opensearch.search.aggregations.AggregationBuilders.avg; import static org.opensearch.test.InternalAggregationTestCase.DEFAULT_MAX_BUCKETS; public class MetricAggregatorTests extends AggregatorTestCase { @@ -267,6 +273,18 @@ public void testStarTreeDocValues() throws IOException { ); } + CircuitBreakerService circuitBreakerService = new NoneCircuitBreakerService(); + + QueryShardContext queryShardContext = queryShardContextMock( + indexSearcher, + mapperServiceMock(), + createIndexSettings(), + circuitBreakerService, + new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), circuitBreakerService).withCircuitBreaking() + ); + + testCase(indexSearcher, query, queryBuilder, sumAggregationBuilder, starTree, supportedDimensions, verifyAggregation(InternalSum::getValue), new SumAggregationBuilder("sumaggs").field("hello").build(queryShardContext, null)); + ir.close(); directory.close(); } @@ -287,6 +305,19 @@ private void testC CompositeIndexFieldInfo starTree, List supportedDimensions, BiConsumer verify + ) throws IOException { + testCase(searcher, query, queryBuilder, aggBuilder, starTree, supportedDimensions, verify, null); + } + + private void testCase( + IndexSearcher searcher, + Query query, + QueryBuilder queryBuilder, + T aggBuilder, + CompositeIndexFieldInfo starTree, + List supportedDimensions, + BiConsumer verify, + AggregatorFactory aggregatorFactory ) throws IOException { V starTreeAggregation = searchAndReduceStarTree( createIndexSettings(), @@ -298,6 +329,7 @@ private void testC supportedDimensions, DEFAULT_MAX_BUCKETS, false, + aggregatorFactory, DEFAULT_MAPPED_FIELD ); V expectedAggregation = searchAndReduceStarTree( @@ -310,6 +342,7 @@ private void testC null, DEFAULT_MAX_BUCKETS, false, + aggregatorFactory, DEFAULT_MAPPED_FIELD ); verify.accept(expectedAggregation, starTreeAggregation); diff --git a/server/src/test/java/org/opensearch/search/aggregations/startree/StarTreeFilterTests.java b/server/src/test/java/org/opensearch/search/aggregations/startree/StarTreeFilterTests.java index b03cb5ac7bb9d..a074f43ccf73f 100644 --- a/server/src/test/java/org/opensearch/search/aggregations/startree/StarTreeFilterTests.java +++ b/server/src/test/java/org/opensearch/search/aggregations/startree/StarTreeFilterTests.java @@ -87,7 +87,27 @@ public void testStarTreeFilterWithDocsInSVDFieldButNoStarNode() throws IOExcepti testStarTreeFilter(10, false); } - private void testStarTreeFilter(int maxLeafDoc, boolean skipStarNodeCreationForSDVDimension) throws IOException { + public void testStarTreeFilterUnmappedField() throws IOException { + List docs = new ArrayList<>(); + try(Directory dir = createStarTreeIndex(1, false, docs); + DirectoryReader ir = DirectoryReader.open(dir)) { + int totalDocs = docs.size(); + + initValuesSourceRegistry(); + LeafReaderContext context = ir.leaves().get(0); + SegmentReader reader = Lucene.segmentReader(context.reader()); + CompositeIndexReader starTreeDocValuesReader = (CompositeIndexReader) reader.getDocValuesReader(); + + long starTreeDocCount, docCount; + starTreeDocCount = getDocCountFromStarTree(starTreeDocValuesReader, Map.of(), context); + docCount = getDocCount(docs, Map.of()); + assertEquals(totalDocs, starTreeDocCount); + assertEquals(docCount, starTreeDocCount); + } + + } + + private Directory createStarTreeIndex(int maxLeafDoc, boolean skipStarNodeCreationForSDVDimension, List docs) throws IOException { Directory directory = newDirectory(); IndexWriterConfig conf = newIndexWriterConfig(null); conf.setCodec(getCodec(maxLeafDoc, skipStarNodeCreationForSDVDimension)); @@ -95,7 +115,6 @@ private void testStarTreeFilter(int maxLeafDoc, boolean skipStarNodeCreationForS RandomIndexWriter iw = new RandomIndexWriter(random(), directory, conf); int totalDocs = 100; - List docs = new ArrayList<>(); for (int i = 0; i < totalDocs; i++) { Document doc = new Document(); doc.add(new SortedNumericDocValuesField(SNDV, i)); @@ -110,6 +129,15 @@ private void testStarTreeFilter(int maxLeafDoc, boolean skipStarNodeCreationForS } iw.forceMerge(1); iw.close(); + return directory; + } + + private void testStarTreeFilter(int maxLeafDoc, boolean skipStarNodeCreationForSDVDimension) throws IOException { + List docs = new ArrayList<>(); + + Directory directory = createStarTreeIndex(maxLeafDoc, skipStarNodeCreationForSDVDimension, docs); + + int totalDocs = docs.size(); DirectoryReader ir = DirectoryReader.open(directory); initValuesSourceRegistry(); diff --git a/test/framework/src/main/java/org/opensearch/search/aggregations/AggregatorTestCase.java b/test/framework/src/main/java/org/opensearch/search/aggregations/AggregatorTestCase.java index e1728c4476699..59dfa5c82c114 100644 --- a/test/framework/src/main/java/org/opensearch/search/aggregations/AggregatorTestCase.java +++ b/test/framework/src/main/java/org/opensearch/search/aggregations/AggregatorTestCase.java @@ -61,6 +61,8 @@ import org.apache.lucene.tests.search.AssertingIndexSearcher; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.NumericUtils; +import org.junit.After; +import org.junit.Before; import org.opensearch.Version; import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.common.CheckedConsumer; @@ -151,8 +153,6 @@ import org.opensearch.search.startree.StarTreeQueryContext; import org.opensearch.test.InternalAggregationTestCase; import org.opensearch.test.OpenSearchTestCase; -import org.junit.After; -import org.junit.Before; import java.io.IOException; import java.net.InetAddress; @@ -171,16 +171,16 @@ import java.util.stream.Collectors; import static java.util.Collections.emptyMap; -import static java.util.Collections.singletonList; import static java.util.Collections.singletonMap; -import static org.opensearch.test.InternalAggregationTestCase.DEFAULT_MAX_BUCKETS; +import static java.util.Collections.singletonList; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.opensearch.test.InternalAggregationTestCase.DEFAULT_MAX_BUCKETS; /** * Base class for testing {@link Aggregator} implementations. @@ -349,6 +349,7 @@ protected CountingAggregator createCountingAggregator( CompositeIndexFieldInfo starTree, List supportedDimensions, MultiBucketConsumer bucketConsumer, + AggregatorFactory aggregatorFactory, MappedFieldType... fieldTypes ) throws IOException { SearchContext searchContext; @@ -361,6 +362,7 @@ protected CountingAggregator createCountingAggregator( starTree, supportedDimensions, bucketConsumer, + aggregatorFactory, fieldTypes ); } else { @@ -390,6 +392,7 @@ protected SearchContext createSearchContextWithStarTreeContext( CompositeIndexFieldInfo starTree, List supportedDimensions, MultiBucketConsumer bucketConsumer, + AggregatorFactory aggregatorFactory, MappedFieldType... fieldTypes ) throws IOException { SearchContext searchContext = createSearchContext( @@ -406,7 +409,12 @@ protected SearchContext createSearchContextWithStarTreeContext( AggregatorFactories aggregatorFactories = mock(AggregatorFactories.class); when(searchContext.aggregations()).thenReturn(searchContextAggregations); when(searchContextAggregations.factories()).thenReturn(aggregatorFactories); - when(aggregatorFactories.getFactories()).thenReturn(new AggregatorFactory[] {}); + + if (aggregatorFactory != null) { + when(aggregatorFactories.getFactories()).thenReturn(new AggregatorFactory[] {aggregatorFactory}); + } else { + when(aggregatorFactories.getFactories()).thenReturn(new AggregatorFactory[] {}); + } CompositeDataCubeFieldType compositeMappedFieldType = mock(CompositeDataCubeFieldType.class); when(compositeMappedFieldType.name()).thenReturn(starTree.getField()); @@ -742,6 +750,7 @@ protected A searchAndReduc List supportedDimensions, int maxBucket, boolean hasNested, + AggregatorFactory aggregatorFactory, MappedFieldType... fieldTypes ) throws IOException { query = query.rewrite(searcher); @@ -765,6 +774,7 @@ protected A searchAndReduc compositeIndexFieldInfo, supportedDimensions, bucketConsumer, + aggregatorFactory, fieldTypes ); From 8986c89df2a0191843001b5638abe24326892e6c Mon Sep 17 00:00:00 2001 From: expani Date: Wed, 11 Dec 2024 15:14:41 -0800 Subject: [PATCH 03/12] Removed unused test case Signed-off-by: expani --- .../startree/MetricAggregatorTests.java | 4 +++- .../startree/StarTreeFilterTests.java | 20 ------------------- 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java b/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java index 2cfdd2eb4a388..25a4f4172a73e 100644 --- a/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java +++ b/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java @@ -283,7 +283,9 @@ public void testStarTreeDocValues() throws IOException { new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), circuitBreakerService).withCircuitBreaking() ); - testCase(indexSearcher, query, queryBuilder, sumAggregationBuilder, starTree, supportedDimensions, verifyAggregation(InternalSum::getValue), new SumAggregationBuilder("sumaggs").field("hello").build(queryShardContext, null)); + // Test that feature parity is maintained for unmapped field names. + sumAggregationBuilder = new SumAggregationBuilder("sumaggs").field("hello"); + testCase(indexSearcher, query, queryBuilder, sumAggregationBuilder, starTree, supportedDimensions, verifyAggregation(InternalSum::getValue), sumAggregationBuilder.build(queryShardContext, null)); ir.close(); directory.close(); diff --git a/server/src/test/java/org/opensearch/search/aggregations/startree/StarTreeFilterTests.java b/server/src/test/java/org/opensearch/search/aggregations/startree/StarTreeFilterTests.java index a074f43ccf73f..8611d20c05f8c 100644 --- a/server/src/test/java/org/opensearch/search/aggregations/startree/StarTreeFilterTests.java +++ b/server/src/test/java/org/opensearch/search/aggregations/startree/StarTreeFilterTests.java @@ -87,26 +87,6 @@ public void testStarTreeFilterWithDocsInSVDFieldButNoStarNode() throws IOExcepti testStarTreeFilter(10, false); } - public void testStarTreeFilterUnmappedField() throws IOException { - List docs = new ArrayList<>(); - try(Directory dir = createStarTreeIndex(1, false, docs); - DirectoryReader ir = DirectoryReader.open(dir)) { - int totalDocs = docs.size(); - - initValuesSourceRegistry(); - LeafReaderContext context = ir.leaves().get(0); - SegmentReader reader = Lucene.segmentReader(context.reader()); - CompositeIndexReader starTreeDocValuesReader = (CompositeIndexReader) reader.getDocValuesReader(); - - long starTreeDocCount, docCount; - starTreeDocCount = getDocCountFromStarTree(starTreeDocValuesReader, Map.of(), context); - docCount = getDocCount(docs, Map.of()); - assertEquals(totalDocs, starTreeDocCount); - assertEquals(docCount, starTreeDocCount); - } - - } - private Directory createStarTreeIndex(int maxLeafDoc, boolean skipStarNodeCreationForSDVDimension, List docs) throws IOException { Directory directory = newDirectory(); IndexWriterConfig conf = newIndexWriterConfig(null); From f2d00915b164292e6bb5004bd7b306a108eeae1d Mon Sep 17 00:00:00 2001 From: expani Date: Wed, 11 Dec 2024 15:16:24 -0800 Subject: [PATCH 04/12] Removed unused test case Signed-off-by: expani --- .../aggregations/support/ValuesSourceAggregatorFactory.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/src/main/java/org/opensearch/search/aggregations/support/ValuesSourceAggregatorFactory.java b/server/src/main/java/org/opensearch/search/aggregations/support/ValuesSourceAggregatorFactory.java index ed18874d09677..41344fd06cbbc 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/support/ValuesSourceAggregatorFactory.java +++ b/server/src/main/java/org/opensearch/search/aggregations/support/ValuesSourceAggregatorFactory.java @@ -104,7 +104,6 @@ public String getStatsSubtype() { } public String getField() { - return config.fieldContext().field(); - //return config.fieldContext() != null ? config.fieldContext().field() : null; + return config.fieldContext() != null ? config.fieldContext().field() : null; } } From 88c33c58e0210f10443aa3bc5f8799b6151cbfa1 Mon Sep 17 00:00:00 2001 From: expani Date: Wed, 11 Dec 2024 15:40:32 -0800 Subject: [PATCH 05/12] Spotless Applied Signed-off-by: expani --- .../search/aggregations/AggregatorTestCase.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/framework/src/main/java/org/opensearch/search/aggregations/AggregatorTestCase.java b/test/framework/src/main/java/org/opensearch/search/aggregations/AggregatorTestCase.java index 59dfa5c82c114..ee1cb7aa1a234 100644 --- a/test/framework/src/main/java/org/opensearch/search/aggregations/AggregatorTestCase.java +++ b/test/framework/src/main/java/org/opensearch/search/aggregations/AggregatorTestCase.java @@ -61,8 +61,6 @@ import org.apache.lucene.tests.search.AssertingIndexSearcher; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.NumericUtils; -import org.junit.After; -import org.junit.Before; import org.opensearch.Version; import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.common.CheckedConsumer; @@ -153,6 +151,8 @@ import org.opensearch.search.startree.StarTreeQueryContext; import org.opensearch.test.InternalAggregationTestCase; import org.opensearch.test.OpenSearchTestCase; +import org.junit.After; +import org.junit.Before; import java.io.IOException; import java.net.InetAddress; @@ -171,16 +171,16 @@ import java.util.stream.Collectors; import static java.util.Collections.emptyMap; -import static java.util.Collections.singletonMap; import static java.util.Collections.singletonList; +import static java.util.Collections.singletonMap; +import static org.opensearch.test.InternalAggregationTestCase.DEFAULT_MAX_BUCKETS; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; -import static org.mockito.Mockito.when; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.doAnswer; -import static org.opensearch.test.InternalAggregationTestCase.DEFAULT_MAX_BUCKETS; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; /** * Base class for testing {@link Aggregator} implementations. @@ -411,7 +411,7 @@ protected SearchContext createSearchContextWithStarTreeContext( when(searchContextAggregations.factories()).thenReturn(aggregatorFactories); if (aggregatorFactory != null) { - when(aggregatorFactories.getFactories()).thenReturn(new AggregatorFactory[] {aggregatorFactory}); + when(aggregatorFactories.getFactories()).thenReturn(new AggregatorFactory[] { aggregatorFactory }); } else { when(aggregatorFactories.getFactories()).thenReturn(new AggregatorFactory[] {}); } From b3c736b9f63d01cd3b3964822e3b99baec6485f4 Mon Sep 17 00:00:00 2001 From: expani Date: Wed, 11 Dec 2024 15:53:01 -0800 Subject: [PATCH 06/12] Fixed spotless again Signed-off-by: expani --- .../startree/MetricAggregatorTests.java | 25 +++++++++++++------ .../startree/StarTreeFilterTests.java | 3 ++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java b/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java index 25a4f4172a73e..531847707330d 100644 --- a/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java +++ b/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java @@ -9,6 +9,7 @@ package org.opensearch.search.aggregations.startree; import com.carrotsearch.randomizedtesting.RandomizedTest; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.lucene.codecs.Codec; @@ -24,8 +25,6 @@ import org.apache.lucene.search.Query; import org.apache.lucene.store.Directory; import org.apache.lucene.tests.index.RandomIndexWriter; -import org.junit.After; -import org.junit.Before; import org.opensearch.common.lucene.Lucene; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.FeatureFlags; @@ -59,6 +58,8 @@ import org.opensearch.search.aggregations.metrics.MinAggregationBuilder; import org.opensearch.search.aggregations.metrics.SumAggregationBuilder; import org.opensearch.search.aggregations.metrics.ValueCountAggregationBuilder; +import org.junit.After; +import org.junit.Before; import java.io.IOException; import java.util.ArrayList; @@ -68,12 +69,11 @@ import java.util.function.BiConsumer; import java.util.function.Function; - -import static org.opensearch.search.aggregations.AggregationBuilders.sum; -import static org.opensearch.search.aggregations.AggregationBuilders.min; -import static org.opensearch.search.aggregations.AggregationBuilders.max; -import static org.opensearch.search.aggregations.AggregationBuilders.count; import static org.opensearch.search.aggregations.AggregationBuilders.avg; +import static org.opensearch.search.aggregations.AggregationBuilders.count; +import static org.opensearch.search.aggregations.AggregationBuilders.max; +import static org.opensearch.search.aggregations.AggregationBuilders.min; +import static org.opensearch.search.aggregations.AggregationBuilders.sum; import static org.opensearch.test.InternalAggregationTestCase.DEFAULT_MAX_BUCKETS; public class MetricAggregatorTests extends AggregatorTestCase { @@ -285,7 +285,16 @@ public void testStarTreeDocValues() throws IOException { // Test that feature parity is maintained for unmapped field names. sumAggregationBuilder = new SumAggregationBuilder("sumaggs").field("hello"); - testCase(indexSearcher, query, queryBuilder, sumAggregationBuilder, starTree, supportedDimensions, verifyAggregation(InternalSum::getValue), sumAggregationBuilder.build(queryShardContext, null)); + testCase( + indexSearcher, + query, + queryBuilder, + sumAggregationBuilder, + starTree, + supportedDimensions, + verifyAggregation(InternalSum::getValue), + sumAggregationBuilder.build(queryShardContext, null) + ); ir.close(); directory.close(); diff --git a/server/src/test/java/org/opensearch/search/aggregations/startree/StarTreeFilterTests.java b/server/src/test/java/org/opensearch/search/aggregations/startree/StarTreeFilterTests.java index 8611d20c05f8c..c1cb19b9576e4 100644 --- a/server/src/test/java/org/opensearch/search/aggregations/startree/StarTreeFilterTests.java +++ b/server/src/test/java/org/opensearch/search/aggregations/startree/StarTreeFilterTests.java @@ -87,7 +87,8 @@ public void testStarTreeFilterWithDocsInSVDFieldButNoStarNode() throws IOExcepti testStarTreeFilter(10, false); } - private Directory createStarTreeIndex(int maxLeafDoc, boolean skipStarNodeCreationForSDVDimension, List docs) throws IOException { + private Directory createStarTreeIndex(int maxLeafDoc, boolean skipStarNodeCreationForSDVDimension, List docs) + throws IOException { Directory directory = newDirectory(); IndexWriterConfig conf = newIndexWriterConfig(null); conf.setCodec(getCodec(maxLeafDoc, skipStarNodeCreationForSDVDimension)); From a2f8d87cee67eabd0594ee182df92ae7e26f3952 Mon Sep 17 00:00:00 2001 From: expani Date: Thu, 2 Jan 2025 11:01:05 -0800 Subject: [PATCH 07/12] Fixed assertion failure for unit test Signed-off-by: expani --- .../search/aggregations/startree/MetricAggregatorTests.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java b/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java index 531847707330d..ec9fffc89e7aa 100644 --- a/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java +++ b/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java @@ -41,6 +41,7 @@ import org.opensearch.index.mapper.MappedFieldType; import org.opensearch.index.mapper.MapperService; import org.opensearch.index.mapper.NumberFieldMapper; +import org.opensearch.index.query.MatchAllQueryBuilder; import org.opensearch.index.query.QueryBuilder; import org.opensearch.index.query.QueryShardContext; import org.opensearch.index.query.TermQueryBuilder; @@ -285,6 +286,7 @@ public void testStarTreeDocValues() throws IOException { // Test that feature parity is maintained for unmapped field names. sumAggregationBuilder = new SumAggregationBuilder("sumaggs").field("hello"); + queryBuilder = new MatchAllQueryBuilder(); testCase( indexSearcher, query, From ea6929eb62ee445859bf51bc622ea8a9cb5cf8d4 Mon Sep 17 00:00:00 2001 From: expani Date: Thu, 2 Jan 2025 13:47:11 -0800 Subject: [PATCH 08/12] Added check to not assert early termination in case of invalid field names Signed-off-by: expani --- .../startree/MetricAggregatorTests.java | 14 ++++++++------ .../search/aggregations/AggregatorTestCase.java | 3 ++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java b/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java index ec9fffc89e7aa..77e0f49fbef31 100644 --- a/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java +++ b/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java @@ -41,7 +41,6 @@ import org.opensearch.index.mapper.MappedFieldType; import org.opensearch.index.mapper.MapperService; import org.opensearch.index.mapper.NumberFieldMapper; -import org.opensearch.index.query.MatchAllQueryBuilder; import org.opensearch.index.query.QueryBuilder; import org.opensearch.index.query.QueryShardContext; import org.opensearch.index.query.TermQueryBuilder; @@ -285,8 +284,7 @@ public void testStarTreeDocValues() throws IOException { ); // Test that feature parity is maintained for unmapped field names. - sumAggregationBuilder = new SumAggregationBuilder("sumaggs").field("hello"); - queryBuilder = new MatchAllQueryBuilder(); + sumAggregationBuilder = sum("sumaggs").field("hello"); testCase( indexSearcher, query, @@ -295,7 +293,8 @@ public void testStarTreeDocValues() throws IOException { starTree, supportedDimensions, verifyAggregation(InternalSum::getValue), - sumAggregationBuilder.build(queryShardContext, null) + sumAggregationBuilder.build(queryShardContext, null), + false // Invalid fields will return null Star Query Context which will not cause early termination for leaf collector ); ir.close(); @@ -319,7 +318,7 @@ private void testC List supportedDimensions, BiConsumer verify ) throws IOException { - testCase(searcher, query, queryBuilder, aggBuilder, starTree, supportedDimensions, verify, null); + testCase(searcher, query, queryBuilder, aggBuilder, starTree, supportedDimensions, verify, null, true); } private void testCase( @@ -330,7 +329,8 @@ private void testC CompositeIndexFieldInfo starTree, List supportedDimensions, BiConsumer verify, - AggregatorFactory aggregatorFactory + AggregatorFactory aggregatorFactory, + boolean assertCollectorEarlyTermination ) throws IOException { V starTreeAggregation = searchAndReduceStarTree( createIndexSettings(), @@ -343,6 +343,7 @@ private void testC DEFAULT_MAX_BUCKETS, false, aggregatorFactory, + assertCollectorEarlyTermination, DEFAULT_MAPPED_FIELD ); V expectedAggregation = searchAndReduceStarTree( @@ -356,6 +357,7 @@ private void testC DEFAULT_MAX_BUCKETS, false, aggregatorFactory, + assertCollectorEarlyTermination, DEFAULT_MAPPED_FIELD ); verify.accept(expectedAggregation, starTreeAggregation); diff --git a/test/framework/src/main/java/org/opensearch/search/aggregations/AggregatorTestCase.java b/test/framework/src/main/java/org/opensearch/search/aggregations/AggregatorTestCase.java index ee1cb7aa1a234..3bf1b1aea5fc4 100644 --- a/test/framework/src/main/java/org/opensearch/search/aggregations/AggregatorTestCase.java +++ b/test/framework/src/main/java/org/opensearch/search/aggregations/AggregatorTestCase.java @@ -751,6 +751,7 @@ protected A searchAndReduc int maxBucket, boolean hasNested, AggregatorFactory aggregatorFactory, + boolean assertCollectorEarlyTermination, MappedFieldType... fieldTypes ) throws IOException { query = query.rewrite(searcher); @@ -782,7 +783,7 @@ protected A searchAndReduc searcher.search(query, countingAggregator); countingAggregator.postCollection(); aggs.add(countingAggregator.buildTopLevel()); - if (compositeIndexFieldInfo != null) { + if (compositeIndexFieldInfo != null && assertCollectorEarlyTermination) { assertEquals(0, countingAggregator.collectCounter.get()); } From 330088ce9d8190e0e5096b46f67b2352be2163a5 Mon Sep 17 00:00:00 2001 From: expani Date: Thu, 2 Jan 2025 23:23:52 -0800 Subject: [PATCH 09/12] Covered more cases fo rvalidateStarTreeMetricSupport Signed-off-by: expani --- .../startree/MetricAggregatorTests.java | 54 +++++++++++++++++-- .../aggregations/AggregatorTestCase.java | 8 +++ 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java b/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java index 77e0f49fbef31..05b7cea65273d 100644 --- a/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java +++ b/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java @@ -37,6 +37,8 @@ import org.opensearch.index.codec.composite.composite912.Composite912Codec; import org.opensearch.index.codec.composite912.datacube.startree.StarTreeDocValuesFormatTests; import org.opensearch.index.compositeindex.datacube.Dimension; +import org.opensearch.index.compositeindex.datacube.Metric; +import org.opensearch.index.compositeindex.datacube.MetricStat; import org.opensearch.index.compositeindex.datacube.NumericDimension; import org.opensearch.index.mapper.MappedFieldType; import org.opensearch.index.mapper.MapperService; @@ -45,6 +47,7 @@ import org.opensearch.index.query.QueryShardContext; import org.opensearch.index.query.TermQueryBuilder; import org.opensearch.search.aggregations.AggregationBuilder; +import org.opensearch.search.aggregations.AggregatorFactories; import org.opensearch.search.aggregations.AggregatorFactory; import org.opensearch.search.aggregations.AggregatorTestCase; import org.opensearch.search.aggregations.InternalAggregation; @@ -55,6 +58,7 @@ import org.opensearch.search.aggregations.metrics.InternalSum; import org.opensearch.search.aggregations.metrics.InternalValueCount; import org.opensearch.search.aggregations.metrics.MaxAggregationBuilder; +import org.opensearch.search.aggregations.metrics.MetricAggregatorFactory; import org.opensearch.search.aggregations.metrics.MinAggregationBuilder; import org.opensearch.search.aggregations.metrics.SumAggregationBuilder; import org.opensearch.search.aggregations.metrics.ValueCountAggregationBuilder; @@ -63,12 +67,15 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Random; import java.util.function.BiConsumer; import java.util.function.Function; +import org.mockito.Mockito; + import static org.opensearch.search.aggregations.AggregationBuilders.avg; import static org.opensearch.search.aggregations.AggregationBuilders.count; import static org.opensearch.search.aggregations.AggregationBuilders.max; @@ -283,8 +290,41 @@ public void testStarTreeDocValues() throws IOException { new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), circuitBreakerService).withCircuitBreaking() ); - // Test that feature parity is maintained for unmapped field names. - sumAggregationBuilder = sum("sumaggs").field("hello"); + MetricAggregatorFactory aggregatorFactory = Mockito.mock(MetricAggregatorFactory.class); + Mockito.when(aggregatorFactory.getSubFactories()).thenReturn(AggregatorFactories.EMPTY); + Mockito.when(aggregatorFactory.getField()).thenReturn(FIELD_NAME); + Mockito.when(aggregatorFactory.getMetricStat()).thenReturn(MetricStat.SUM); + + // Case when field and metric type in aggregation are fully supported by star tree. + testCase( + indexSearcher, + query, + queryBuilder, + sumAggregationBuilder, + starTree, + supportedDimensions, + List.of(new Metric(FIELD_NAME, List.of(MetricStat.SUM, MetricStat.MAX, MetricStat.MIN, MetricStat.AVG))), + verifyAggregation(InternalSum::getValue), + aggregatorFactory, + true + ); + + // Case when the field is not supported by star tree + SumAggregationBuilder invalidFieldSumAggBuilder = sum("_name").field("hello"); + testCase( + indexSearcher, + query, + queryBuilder, + invalidFieldSumAggBuilder, + starTree, + supportedDimensions, + Collections.emptyList(), + verifyAggregation(InternalSum::getValue), + invalidFieldSumAggBuilder.build(queryShardContext, null), + false // Invalid fields will return null StarTreeQueryContext which will not cause early termination by leaf collector + ); + + // Case when metric type in aggregation is not supported by star tree but the field is supported. testCase( indexSearcher, query, @@ -292,9 +332,10 @@ public void testStarTreeDocValues() throws IOException { sumAggregationBuilder, starTree, supportedDimensions, + List.of(new Metric(FIELD_NAME, List.of(MetricStat.MAX, MetricStat.MIN, MetricStat.AVG))), verifyAggregation(InternalSum::getValue), - sumAggregationBuilder.build(queryShardContext, null), - false // Invalid fields will return null Star Query Context which will not cause early termination for leaf collector + aggregatorFactory, + false ); ir.close(); @@ -318,7 +359,7 @@ private void testC List supportedDimensions, BiConsumer verify ) throws IOException { - testCase(searcher, query, queryBuilder, aggBuilder, starTree, supportedDimensions, verify, null, true); + testCase(searcher, query, queryBuilder, aggBuilder, starTree, supportedDimensions, Collections.emptyList(), verify, null, true); } private void testCase( @@ -328,6 +369,7 @@ private void testC T aggBuilder, CompositeIndexFieldInfo starTree, List supportedDimensions, + List supportedMetrics, BiConsumer verify, AggregatorFactory aggregatorFactory, boolean assertCollectorEarlyTermination @@ -340,6 +382,7 @@ private void testC aggBuilder, starTree, supportedDimensions, + supportedMetrics, DEFAULT_MAX_BUCKETS, false, aggregatorFactory, @@ -354,6 +397,7 @@ private void testC aggBuilder, null, null, + null, DEFAULT_MAX_BUCKETS, false, aggregatorFactory, diff --git a/test/framework/src/main/java/org/opensearch/search/aggregations/AggregatorTestCase.java b/test/framework/src/main/java/org/opensearch/search/aggregations/AggregatorTestCase.java index 3bf1b1aea5fc4..50be0c9ea142c 100644 --- a/test/framework/src/main/java/org/opensearch/search/aggregations/AggregatorTestCase.java +++ b/test/framework/src/main/java/org/opensearch/search/aggregations/AggregatorTestCase.java @@ -93,6 +93,8 @@ import org.opensearch.index.cache.query.DisabledQueryCache; import org.opensearch.index.codec.composite.CompositeIndexFieldInfo; import org.opensearch.index.compositeindex.datacube.Dimension; +import org.opensearch.index.compositeindex.datacube.Metric; +import org.opensearch.index.compositeindex.datacube.MetricStat; import org.opensearch.index.compositeindex.datacube.startree.utils.StarTreeQueryHelper; import org.opensearch.index.fielddata.IndexFieldData; import org.opensearch.index.fielddata.IndexFieldDataCache; @@ -348,6 +350,7 @@ protected CountingAggregator createCountingAggregator( IndexSettings indexSettings, CompositeIndexFieldInfo starTree, List supportedDimensions, + List supportedMetrics, MultiBucketConsumer bucketConsumer, AggregatorFactory aggregatorFactory, MappedFieldType... fieldTypes @@ -361,6 +364,7 @@ protected CountingAggregator createCountingAggregator( queryBuilder, starTree, supportedDimensions, + supportedMetrics, bucketConsumer, aggregatorFactory, fieldTypes @@ -391,6 +395,7 @@ protected SearchContext createSearchContextWithStarTreeContext( QueryBuilder queryBuilder, CompositeIndexFieldInfo starTree, List supportedDimensions, + List supportedMetrics, MultiBucketConsumer bucketConsumer, AggregatorFactory aggregatorFactory, MappedFieldType... fieldTypes @@ -422,6 +427,7 @@ protected SearchContext createSearchContextWithStarTreeContext( Set compositeFieldTypes = Set.of(compositeMappedFieldType); when((compositeMappedFieldType).getDimensions()).thenReturn(supportedDimensions); + when((compositeMappedFieldType).getMetrics()).thenReturn(supportedMetrics); MapperService mapperService = mock(MapperService.class); when(mapperService.getCompositeFieldTypes()).thenReturn(compositeFieldTypes); when(searchContext.mapperService()).thenReturn(mapperService); @@ -748,6 +754,7 @@ protected A searchAndReduc AggregationBuilder builder, CompositeIndexFieldInfo compositeIndexFieldInfo, List supportedDimensions, + List supportedMetrics, int maxBucket, boolean hasNested, AggregatorFactory aggregatorFactory, @@ -774,6 +781,7 @@ protected A searchAndReduc indexSettings, compositeIndexFieldInfo, supportedDimensions, + supportedMetrics, bucketConsumer, aggregatorFactory, fieldTypes From 6432da42a1d724ed34f25afbbce571f0903cac90 Mon Sep 17 00:00:00 2001 From: expani Date: Fri, 3 Jan 2025 00:02:35 -0800 Subject: [PATCH 10/12] SpotlessApply Test files Signed-off-by: expani --- .../org/opensearch/search/aggregations/AggregatorTestCase.java | 1 - 1 file changed, 1 deletion(-) diff --git a/test/framework/src/main/java/org/opensearch/search/aggregations/AggregatorTestCase.java b/test/framework/src/main/java/org/opensearch/search/aggregations/AggregatorTestCase.java index 50be0c9ea142c..27142b298db52 100644 --- a/test/framework/src/main/java/org/opensearch/search/aggregations/AggregatorTestCase.java +++ b/test/framework/src/main/java/org/opensearch/search/aggregations/AggregatorTestCase.java @@ -94,7 +94,6 @@ import org.opensearch.index.codec.composite.CompositeIndexFieldInfo; import org.opensearch.index.compositeindex.datacube.Dimension; import org.opensearch.index.compositeindex.datacube.Metric; -import org.opensearch.index.compositeindex.datacube.MetricStat; import org.opensearch.index.compositeindex.datacube.startree.utils.StarTreeQueryHelper; import org.opensearch.index.fielddata.IndexFieldData; import org.opensearch.index.fielddata.IndexFieldDataCache; From 6bf70e42edf594dfd321792af9429bab875681de Mon Sep 17 00:00:00 2001 From: expani Date: Fri, 3 Jan 2025 11:23:14 -0800 Subject: [PATCH 11/12] Added more cases to improve coverage Signed-off-by: expani --- .../startree/MetricAggregatorTests.java | 59 +++++++++++++++++-- 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java b/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java index 05b7cea65273d..9eb8273710b2a 100644 --- a/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java +++ b/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java @@ -64,6 +64,7 @@ import org.opensearch.search.aggregations.metrics.ValueCountAggregationBuilder; import org.junit.After; import org.junit.Before; +import org.opensearch.search.aggregations.support.ValuesSourceAggregatorFactory; import java.io.IOException; import java.util.ArrayList; @@ -74,8 +75,8 @@ import java.util.function.BiConsumer; import java.util.function.Function; -import org.mockito.Mockito; - +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import static org.opensearch.search.aggregations.AggregationBuilders.avg; import static org.opensearch.search.aggregations.AggregationBuilders.count; import static org.opensearch.search.aggregations.AggregationBuilders.max; @@ -290,10 +291,10 @@ public void testStarTreeDocValues() throws IOException { new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), circuitBreakerService).withCircuitBreaking() ); - MetricAggregatorFactory aggregatorFactory = Mockito.mock(MetricAggregatorFactory.class); - Mockito.when(aggregatorFactory.getSubFactories()).thenReturn(AggregatorFactories.EMPTY); - Mockito.when(aggregatorFactory.getField()).thenReturn(FIELD_NAME); - Mockito.when(aggregatorFactory.getMetricStat()).thenReturn(MetricStat.SUM); + MetricAggregatorFactory aggregatorFactory = mock(MetricAggregatorFactory.class); + when(aggregatorFactory.getSubFactories()).thenReturn(AggregatorFactories.EMPTY); + when(aggregatorFactory.getField()).thenReturn(FIELD_NAME); + when(aggregatorFactory.getMetricStat()).thenReturn(MetricStat.SUM); // Case when field and metric type in aggregation are fully supported by star tree. testCase( @@ -338,6 +339,52 @@ public void testStarTreeDocValues() throws IOException { false ); + // Case when field is not present in supported metrics + testCase( + indexSearcher, + query, + queryBuilder, + sumAggregationBuilder, + starTree, + supportedDimensions, + List.of(new Metric("hello", List.of(MetricStat.MAX, MetricStat.MIN, MetricStat.AVG))), + verifyAggregation(InternalSum::getValue), + aggregatorFactory, + false + ); + + AggregatorFactories aggregatorFactories = mock(AggregatorFactories.class); + when(aggregatorFactories.getFactories()).thenReturn(new AggregatorFactory[]{mock(MetricAggregatorFactory.class)}); + when(aggregatorFactory.getSubFactories()).thenReturn(aggregatorFactories); + + // Case when sub aggregations are present + testCase( + indexSearcher, + query, + queryBuilder, + sumAggregationBuilder, + starTree, + supportedDimensions, + List.of(new Metric("hello", List.of(MetricStat.MAX, MetricStat.MIN, MetricStat.AVG))), + verifyAggregation(InternalSum::getValue), + aggregatorFactory, + false + ); + + // Case when aggregation factory is not metric aggregation + testCase( + indexSearcher, + query, + queryBuilder, + sumAggregationBuilder, + starTree, + supportedDimensions, + List.of(new Metric("hello", List.of(MetricStat.MAX, MetricStat.MIN, MetricStat.AVG))), + verifyAggregation(InternalSum::getValue), + mock(ValuesSourceAggregatorFactory.class), + false + ); + ir.close(); directory.close(); } From e7445458c9192f186e27723181334146e36a0632 Mon Sep 17 00:00:00 2001 From: expani Date: Fri, 3 Jan 2025 12:17:07 -0800 Subject: [PATCH 12/12] Spotless apply Signed-off-by: expani --- .../aggregations/startree/MetricAggregatorTests.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java b/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java index 9eb8273710b2a..05f48eb9243af 100644 --- a/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java +++ b/server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java @@ -62,9 +62,9 @@ import org.opensearch.search.aggregations.metrics.MinAggregationBuilder; import org.opensearch.search.aggregations.metrics.SumAggregationBuilder; import org.opensearch.search.aggregations.metrics.ValueCountAggregationBuilder; +import org.opensearch.search.aggregations.support.ValuesSourceAggregatorFactory; import org.junit.After; import org.junit.Before; -import org.opensearch.search.aggregations.support.ValuesSourceAggregatorFactory; import java.io.IOException; import java.util.ArrayList; @@ -75,14 +75,14 @@ import java.util.function.BiConsumer; import java.util.function.Function; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; import static org.opensearch.search.aggregations.AggregationBuilders.avg; import static org.opensearch.search.aggregations.AggregationBuilders.count; import static org.opensearch.search.aggregations.AggregationBuilders.max; import static org.opensearch.search.aggregations.AggregationBuilders.min; import static org.opensearch.search.aggregations.AggregationBuilders.sum; import static org.opensearch.test.InternalAggregationTestCase.DEFAULT_MAX_BUCKETS; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class MetricAggregatorTests extends AggregatorTestCase { @@ -354,7 +354,7 @@ public void testStarTreeDocValues() throws IOException { ); AggregatorFactories aggregatorFactories = mock(AggregatorFactories.class); - when(aggregatorFactories.getFactories()).thenReturn(new AggregatorFactory[]{mock(MetricAggregatorFactory.class)}); + when(aggregatorFactories.getFactories()).thenReturn(new AggregatorFactory[] { mock(MetricAggregatorFactory.class) }); when(aggregatorFactory.getSubFactories()).thenReturn(aggregatorFactories); // Case when sub aggregations are present