3232
3333package org .opensearch .search .aggregations .metrics ;
3434
35- import org .apache .lucene .document .*;
35+ import org .apache .lucene .document .BinaryDocValuesField ;
36+ import org .apache .lucene .document .Field ;
37+ import org .apache .lucene .document .IntPoint ;
38+ import org .apache .lucene .document .KeywordField ;
39+ import org .apache .lucene .document .NumericDocValuesField ;
40+ import org .apache .lucene .document .SortedDocValuesField ;
41+ import org .apache .lucene .document .SortedNumericDocValuesField ;
42+ import org .apache .lucene .document .SortedSetDocValuesField ;
3643import org .apache .lucene .index .DirectoryReader ;
3744import org .apache .lucene .index .IndexReader ;
3845import org .apache .lucene .index .IndexWriter ;
5259import org .opensearch .common .geo .GeoPoint ;
5360import org .opensearch .core .common .breaker .CircuitBreaker ;
5461import org .opensearch .core .indices .breaker .NoneCircuitBreakerService ;
55- import org .opensearch .index .mapper .*;
56- import org .opensearch .search .aggregations .*;
62+ import org .opensearch .index .mapper .KeywordFieldMapper ;
63+ import org .opensearch .index .mapper .MappedFieldType ;
64+ import org .opensearch .index .mapper .NumberFieldMapper ;
65+ import org .opensearch .index .mapper .RangeFieldMapper ;
66+ import org .opensearch .index .mapper .RangeType ;
67+ import org .opensearch .search .aggregations .AggregationBuilder ;
68+ import org .opensearch .search .aggregations .AggregatorTestCase ;
69+ import org .opensearch .search .aggregations .InternalAggregation ;
70+ import org .opensearch .search .aggregations .LeafBucketCollector ;
71+ import org .opensearch .search .aggregations .MultiBucketConsumerService ;
5772import org .opensearch .search .aggregations .pipeline .PipelineAggregator ;
5873import org .opensearch .search .aggregations .support .AggregationInspectionHelper ;
5974
@@ -501,7 +516,10 @@ private void testAggregationExecutionHint(
501516 try (IndexReader indexReader = DirectoryReader .open (directory )) {
502517 IndexSearcher indexSearcher = newSearcher (indexReader , true , true );
503518
504- CountingAggregator aggregator = new CountingAggregator (new AtomicInteger (), createAggregator (aggregationBuilder , indexSearcher , fieldType ));
519+ CountingAggregator aggregator = new CountingAggregator (
520+ new AtomicInteger (),
521+ createAggregator (aggregationBuilder , indexSearcher , fieldType )
522+ );
505523 aggregator .preCollection ();
506524 indexSearcher .search (query , aggregator );
507525 aggregator .postCollection ();
@@ -528,17 +546,16 @@ private void testAggregationExecutionHint(
528546
529547 public void testInvalidExecutionHint () throws IOException {
530548 MappedFieldType fieldType = new NumberFieldMapper .NumberFieldType ("number" , NumberFieldMapper .NumberType .LONG );
531- final CardinalityAggregationBuilder aggregationBuilder = new CardinalityAggregationBuilder ("_name" ).field ("number" ).executionHint ("invalid" );
549+ final CardinalityAggregationBuilder aggregationBuilder = new CardinalityAggregationBuilder ("_name" ).field ("number" )
550+ .executionHint ("invalid" );
532551 assertThrows (IllegalArgumentException .class , () -> testAggregationExecutionHint (aggregationBuilder , new MatchAllDocsQuery (), iw -> {
533552 iw .addDocument (singleton (new NumericDocValuesField ("number" , 7 )));
534553 iw .addDocument (singleton (new NumericDocValuesField ("number" , 8 )));
535554 iw .addDocument (singleton (new NumericDocValuesField ("number" , 9 )));
536555 }, card -> {
537556 assertEquals (3 , card .getValue (), 0 );
538557 assertTrue (AggregationInspectionHelper .hasValue (card ));
539- }, collector -> {
540- assertTrue (collector instanceof CardinalityAggregator .DirectCollector );
541- }, fieldType ));
558+ }, collector -> { assertTrue (collector instanceof CardinalityAggregator .DirectCollector ); }, fieldType ));
542559 }
543560
544561 public void testNoExecutionHintWithNumericDocValues () throws IOException {
@@ -551,77 +568,70 @@ public void testNoExecutionHintWithNumericDocValues() throws IOException {
551568 }, card -> {
552569 assertEquals (3 , card .getValue (), 0 );
553570 assertTrue (AggregationInspectionHelper .hasValue (card ));
554- }, collector -> {
555- assertTrue (collector instanceof CardinalityAggregator .DirectCollector );
556- }, fieldType );
571+ }, collector -> { assertTrue (collector instanceof CardinalityAggregator .DirectCollector ); }, fieldType );
557572 }
558573
559574 public void testDirectExecutionHintWithNumericDocValues () throws IOException {
560575 MappedFieldType fieldType = new NumberFieldMapper .NumberFieldType ("number" , NumberFieldMapper .NumberType .LONG );
561- final CardinalityAggregationBuilder aggregationBuilder = new CardinalityAggregationBuilder ("_name" ).field ("number" ).executionHint ("direct" );
576+ final CardinalityAggregationBuilder aggregationBuilder = new CardinalityAggregationBuilder ("_name" ).field ("number" )
577+ .executionHint ("direct" );
562578 testAggregationExecutionHint (aggregationBuilder , new MatchAllDocsQuery (), iw -> {
563579 iw .addDocument (singleton (new NumericDocValuesField ("number" , 7 )));
564580 iw .addDocument (singleton (new NumericDocValuesField ("number" , 8 )));
565581 iw .addDocument (singleton (new NumericDocValuesField ("number" , 9 )));
566582 }, card -> {
567583 assertEquals (3 , card .getValue (), 0 );
568584 assertTrue (AggregationInspectionHelper .hasValue (card ));
569- }, collector -> {
570- assertTrue (collector instanceof CardinalityAggregator .DirectCollector );
571- }, fieldType );
585+ }, collector -> { assertTrue (collector instanceof CardinalityAggregator .DirectCollector ); }, fieldType );
572586 }
573587
574588 public void testOrdinalsExecutionHintWithNumericDocValues () throws IOException {
575589 MappedFieldType fieldType = new NumberFieldMapper .NumberFieldType ("number" , NumberFieldMapper .NumberType .LONG );
576- final CardinalityAggregationBuilder aggregationBuilder = new CardinalityAggregationBuilder ("_name" ).field ("number" ).executionHint ("ordinals" );
590+ final CardinalityAggregationBuilder aggregationBuilder = new CardinalityAggregationBuilder ("_name" ).field ("number" )
591+ .executionHint ("ordinals" );
577592 testAggregationExecutionHint (aggregationBuilder , new MatchAllDocsQuery (), iw -> {
578593 iw .addDocument (singleton (new NumericDocValuesField ("number" , 7 )));
579594 iw .addDocument (singleton (new NumericDocValuesField ("number" , 8 )));
580595 iw .addDocument (singleton (new NumericDocValuesField ("number" , 9 )));
581596 }, card -> {
582597 assertEquals (3 , card .getValue (), 0 );
583598 assertTrue (AggregationInspectionHelper .hasValue (card ));
584- }, collector -> {
585- assertTrue (collector instanceof CardinalityAggregator .DirectCollector );
586- }, fieldType );
599+ }, collector -> { assertTrue (collector instanceof CardinalityAggregator .DirectCollector ); }, fieldType );
587600 }
588601
589602 public void testNoExecutionHintWithByteValues () throws IOException {
590603 MappedFieldType fieldType = new KeywordFieldMapper .KeywordFieldType ("field" );
591- final CardinalityAggregationBuilder aggregationBuilder = new CardinalityAggregationBuilder ("_name" ).field ("field" ).executionHint ("direct" );
604+ final CardinalityAggregationBuilder aggregationBuilder = new CardinalityAggregationBuilder ("_name" ).field ("field" )
605+ .executionHint ("direct" );
592606 testAggregationExecutionHint (aggregationBuilder , new MatchAllDocsQuery (), iw -> {
593607 iw .addDocument (singleton (new SortedDocValuesField ("field" , new BytesRef ())));
594608 }, card -> {
595609 assertEquals (1 , card .getValue (), 0 );
596610 assertTrue (AggregationInspectionHelper .hasValue (card ));
597- }, collector -> {
598- assertTrue (collector instanceof CardinalityAggregator .OrdinalsCollector );
599- }, fieldType );
611+ }, collector -> { assertTrue (collector instanceof CardinalityAggregator .OrdinalsCollector ); }, fieldType );
600612 }
601613
602614 public void testDirectExecutionHintWithByteValues () throws IOException {
603615 MappedFieldType fieldType = new KeywordFieldMapper .KeywordFieldType ("field" );
604- final CardinalityAggregationBuilder aggregationBuilder = new CardinalityAggregationBuilder ("_name" ).field ("field" ).executionHint ("direct" );
616+ final CardinalityAggregationBuilder aggregationBuilder = new CardinalityAggregationBuilder ("_name" ).field ("field" )
617+ .executionHint ("direct" );
605618 testAggregationExecutionHint (aggregationBuilder , new MatchAllDocsQuery (), iw -> {
606619 iw .addDocument (singleton (new SortedDocValuesField ("field" , new BytesRef ())));
607620 }, card -> {
608621 assertEquals (1 , card .getValue (), 0 );
609622 assertTrue (AggregationInspectionHelper .hasValue (card ));
610- }, collector -> {
611- assertTrue (collector instanceof CardinalityAggregator .OrdinalsCollector );
612- }, fieldType );
623+ }, collector -> { assertTrue (collector instanceof CardinalityAggregator .OrdinalsCollector ); }, fieldType );
613624 }
614625
615626 public void testOrdinalsExecutionHintWithByteValues () throws IOException {
616627 MappedFieldType fieldType = new KeywordFieldMapper .KeywordFieldType ("field" );
617- final CardinalityAggregationBuilder aggregationBuilder = new CardinalityAggregationBuilder ("_name" ).field ("field" ).executionHint ("ordinals" );
628+ final CardinalityAggregationBuilder aggregationBuilder = new CardinalityAggregationBuilder ("_name" ).field ("field" )
629+ .executionHint ("ordinals" );
618630 testAggregationExecutionHint (aggregationBuilder , new MatchAllDocsQuery (), iw -> {
619631 iw .addDocument (singleton (new SortedDocValuesField ("field" , new BytesRef ())));
620632 }, card -> {
621633 assertEquals (1 , card .getValue (), 0 );
622634 assertTrue (AggregationInspectionHelper .hasValue (card ));
623- }, collector -> {
624- assertTrue (collector instanceof CardinalityAggregator .OrdinalsCollector );
625- }, fieldType );
635+ }, collector -> { assertTrue (collector instanceof CardinalityAggregator .OrdinalsCollector ); }, fieldType );
626636 }
627637}
0 commit comments