@@ -11,9 +11,7 @@ use crate::aggregation::agg_req_with_accessor::{
11
11
use crate :: aggregation:: intermediate_agg_result:: {
12
12
IntermediateBucketResult , IntermediateTermBucketEntry , IntermediateTermBucketResult ,
13
13
} ;
14
- use crate :: aggregation:: segment_agg_result:: {
15
- validate_bucket_count, SegmentAggregationResultsCollector ,
16
- } ;
14
+ use crate :: aggregation:: segment_agg_result:: { BucketCount , SegmentAggregationResultsCollector } ;
17
15
use crate :: error:: DataCorruption ;
18
16
use crate :: fastfield:: MultiValuedFastFieldReader ;
19
17
use crate :: schema:: Type ;
@@ -246,23 +244,23 @@ impl TermBuckets {
246
244
& mut self ,
247
245
term_ids : & [ u64 ] ,
248
246
doc : DocId ,
249
- bucket_with_accessor : & BucketAggregationWithAccessor ,
247
+ sub_aggregation : & AggregationsWithAccessor ,
248
+ bucket_count : & BucketCount ,
250
249
blueprint : & Option < SegmentAggregationResultsCollector > ,
251
250
) -> crate :: Result < ( ) > {
252
251
for & term_id in term_ids {
253
252
let entry = self . entries . entry ( term_id as u32 ) . or_insert_with ( || {
254
- bucket_with_accessor
255
- . bucket_count
256
- . fetch_add ( 1 , std:: sync:: atomic:: Ordering :: Relaxed ) ;
253
+ bucket_count. add_count ( 1 ) ;
257
254
258
255
TermBucketEntry :: from_blueprint ( blueprint)
259
256
} ) ;
260
257
entry. doc_count += 1 ;
261
258
if let Some ( sub_aggregations) = entry. sub_aggregations . as_mut ( ) {
262
- sub_aggregations. collect ( doc, & bucket_with_accessor . sub_aggregation ) ?;
259
+ sub_aggregations. collect ( doc, & sub_aggregation) ?;
263
260
}
264
261
}
265
- validate_bucket_count ( & bucket_with_accessor. bucket_count ) ?;
262
+ bucket_count. validate_bucket_count ( ) ?;
263
+
266
264
Ok ( ( ) )
267
265
}
268
266
@@ -447,25 +445,29 @@ impl SegmentTermCollector {
447
445
self . term_buckets . increment_bucket (
448
446
& vals1,
449
447
docs[ 0 ] ,
450
- bucket_with_accessor,
448
+ & bucket_with_accessor. sub_aggregation ,
449
+ & bucket_with_accessor. bucket_count ,
451
450
& self . blueprint ,
452
451
) ?;
453
452
self . term_buckets . increment_bucket (
454
453
& vals2,
455
454
docs[ 1 ] ,
456
- bucket_with_accessor,
455
+ & bucket_with_accessor. sub_aggregation ,
456
+ & bucket_with_accessor. bucket_count ,
457
457
& self . blueprint ,
458
458
) ?;
459
459
self . term_buckets . increment_bucket (
460
460
& vals3,
461
461
docs[ 2 ] ,
462
- bucket_with_accessor,
462
+ & bucket_with_accessor. sub_aggregation ,
463
+ & bucket_with_accessor. bucket_count ,
463
464
& self . blueprint ,
464
465
) ?;
465
466
self . term_buckets . increment_bucket (
466
467
& vals4,
467
468
docs[ 3 ] ,
468
- bucket_with_accessor,
469
+ & bucket_with_accessor. sub_aggregation ,
470
+ & bucket_with_accessor. bucket_count ,
469
471
& self . blueprint ,
470
472
) ?;
471
473
}
@@ -475,7 +477,8 @@ impl SegmentTermCollector {
475
477
self . term_buckets . increment_bucket (
476
478
& vals1,
477
479
doc,
478
- bucket_with_accessor,
480
+ & bucket_with_accessor. sub_aggregation ,
481
+ & bucket_with_accessor. bucket_count ,
479
482
& self . blueprint ,
480
483
) ?;
481
484
}
@@ -1326,9 +1329,15 @@ mod bench {
1326
1329
let mut collector = get_collector_with_buckets ( total_terms) ;
1327
1330
let vals = get_rand_terms ( total_terms, num_terms) ;
1328
1331
let aggregations_with_accessor: AggregationsWithAccessor = Default :: default ( ) ;
1332
+ let bucket_count: BucketCount = BucketCount {
1333
+ bucket_count : Default :: default ( ) ,
1334
+ max_bucket_count : 1_000_001u32 ,
1335
+ } ;
1329
1336
b. iter ( || {
1330
1337
for & val in & vals {
1331
- collector. increment_bucket ( & [ val] , 0 , & aggregations_with_accessor, & None ) ;
1338
+ collector
1339
+ . increment_bucket ( & [ val] , 0 , & aggregations_with_accessor, & bucket_count, & None )
1340
+ . unwrap ( ) ;
1332
1341
}
1333
1342
} )
1334
1343
}
0 commit comments