1919import org .elasticsearch .search .aggregations .InternalAggregation ;
2020import org .elasticsearch .search .aggregations .InternalAggregations ;
2121import org .elasticsearch .search .aggregations .InternalMultiBucketAggregation ;
22- import org .elasticsearch .search .aggregations .KeyComparable ;
2322import org .elasticsearch .search .aggregations .bucket .BucketReducer ;
2423import org .elasticsearch .search .aggregations .bucket .IteratorAndCurrent ;
2524import org .elasticsearch .search .aggregations .support .SamplingContext ;
@@ -103,7 +102,7 @@ public InternalComposite(StreamInput in) throws IOException {
103102 }
104103 this .reverseMuls = in .readIntArray ();
105104 this .missingOrders = in .readArray (MissingOrder ::readFromStream , MissingOrder []::new );
106- this .buckets = in .readCollectionAsList ((input ) -> new InternalBucket (input , sourceNames , formats , reverseMuls , missingOrders ));
105+ this .buckets = in .readCollectionAsList ((input ) -> new InternalBucket (input , sourceNames , formats ));
107106 this .afterKey = in .readOptionalWriteable (CompositeKey ::new );
108107 this .earlyTerminated = in .readBoolean ();
109108 }
@@ -155,15 +154,7 @@ public InternalComposite create(List<InternalBucket> newBuckets) {
155154
156155 @ Override
157156 public InternalBucket createBucket (InternalAggregations aggregations , InternalBucket prototype ) {
158- return new InternalBucket (
159- prototype .sourceNames ,
160- prototype .formats ,
161- prototype .key ,
162- prototype .reverseMuls ,
163- prototype .missingOrders ,
164- prototype .docCount ,
165- aggregations
166- );
157+ return new InternalBucket (prototype .sourceNames , prototype .formats , prototype .key , prototype .docCount , aggregations );
167158 }
168159
169160 public int getSize () {
@@ -206,7 +197,7 @@ protected AggregatorReducer getLeaderReducer(AggregationReduceContext reduceCont
206197 private final PriorityQueue <IteratorAndCurrent <InternalBucket >> pq = new PriorityQueue <>(size ) {
207198 @ Override
208199 protected boolean lessThan (IteratorAndCurrent <InternalBucket > a , IteratorAndCurrent <InternalBucket > b ) {
209- return a .current ().compareKey (b .current ()) < 0 ;
200+ return a .current ().compareKey (b .current (), reverseMuls , missingOrders ) < 0 ;
210201 }
211202 };
212203 private boolean earlyTerminated = false ;
@@ -227,7 +218,7 @@ public InternalAggregation get() {
227218 final List <InternalBucket > result = new ArrayList <>();
228219 while (pq .size () > 0 ) {
229220 IteratorAndCurrent <InternalBucket > top = pq .top ();
230- if (lastBucket != null && top .current ().compareKey (lastBucket ) != 0 ) {
221+ if (lastBucket != null && top .current ().compareKey (lastBucket , reverseMuls , missingOrders ) != 0 ) {
231222 InternalBucket reduceBucket = reduceBucket (buckets , reduceContext );
232223 buckets .clear ();
233224 result .add (reduceBucket );
@@ -306,7 +297,7 @@ private InternalBucket reduceBucket(List<InternalBucket> buckets, AggregationRed
306297 final var reducedFormats = reducer .getProto ().formats ;
307298 final long docCount = reducer .getDocCount ();
308299 final InternalAggregations aggs = reducer .getAggregations ();
309- return new InternalBucket (sourceNames , reducedFormats , reducer .getProto ().key , reverseMuls , missingOrders , docCount , aggs );
300+ return new InternalBucket (sourceNames , reducedFormats , reducer .getProto ().key , docCount , aggs );
310301 }
311302 }
312303
@@ -329,49 +320,32 @@ public int hashCode() {
329320 return Objects .hash (super .hashCode (), size , buckets , afterKey , Arrays .hashCode (reverseMuls ), Arrays .hashCode (missingOrders ));
330321 }
331322
332- public static class InternalBucket extends InternalMultiBucketAggregation .InternalBucket
333- implements
334- CompositeAggregation .Bucket ,
335- KeyComparable <InternalBucket > {
323+ public static class InternalBucket extends InternalMultiBucketAggregation .InternalBucket implements CompositeAggregation .Bucket {
336324
337325 private final CompositeKey key ;
338326 private final long docCount ;
339327 private final InternalAggregations aggregations ;
340- private final transient int [] reverseMuls ;
341- private final transient MissingOrder [] missingOrders ;
342328 private final transient List <String > sourceNames ;
343329 private final transient List <DocValueFormat > formats ;
344330
345331 InternalBucket (
346332 List <String > sourceNames ,
347333 List <DocValueFormat > formats ,
348334 CompositeKey key ,
349- int [] reverseMuls ,
350- MissingOrder [] missingOrders ,
351335 long docCount ,
352336 InternalAggregations aggregations
353337 ) {
354338 this .key = key ;
355339 this .docCount = docCount ;
356340 this .aggregations = aggregations ;
357- this .reverseMuls = reverseMuls ;
358- this .missingOrders = missingOrders ;
359341 this .sourceNames = sourceNames ;
360342 this .formats = formats ;
361343 }
362344
363- InternalBucket (
364- StreamInput in ,
365- List <String > sourceNames ,
366- List <DocValueFormat > formats ,
367- int [] reverseMuls ,
368- MissingOrder [] missingOrders
369- ) throws IOException {
345+ InternalBucket (StreamInput in , List <String > sourceNames , List <DocValueFormat > formats ) throws IOException {
370346 this .key = new CompositeKey (in );
371347 this .docCount = in .readVLong ();
372348 this .aggregations = InternalAggregations .readFrom (in );
373- this .reverseMuls = reverseMuls ;
374- this .missingOrders = missingOrders ;
375349 this .sourceNames = sourceNames ;
376350 this .formats = formats ;
377351 }
@@ -444,8 +418,7 @@ List<DocValueFormat> getFormats() {
444418 return formats ;
445419 }
446420
447- @ Override
448- public int compareKey (InternalBucket other ) {
421+ int compareKey (InternalBucket other , int [] reverseMuls , MissingOrder [] missingOrders ) {
449422 for (int i = 0 ; i < key .size (); i ++) {
450423 if (key .get (i ) == null ) {
451424 if (other .key .get (i ) == null ) {
@@ -470,8 +443,6 @@ InternalBucket finalizeSampling(SamplingContext samplingContext) {
470443 sourceNames ,
471444 formats ,
472445 key ,
473- reverseMuls ,
474- missingOrders ,
475446 samplingContext .scaleUp (docCount ),
476447 InternalAggregations .finalizeSampling (aggregations , samplingContext )
477448 );
0 commit comments