@@ -430,31 +430,36 @@ void MeanAggregatorData::aggregate(
430
430
) {
431
431
fractions_.resize (unique_values);
432
432
sparse_map_.resize (unique_values);
433
- details::visit_type (input_column.column_ ->type ().data_type (), [&input_column, &groups, this ](auto col_tag) {
434
- using col_type_info = ScalarTypeInfo<decltype (col_tag)>;
435
- if constexpr (is_sequence_type (col_type_info::data_type)) {
436
- util::raise_rte (" String aggregations not currently supported" );
437
- } else if constexpr (is_empty_type (col_type_info::data_type)) {
438
- return ;
439
- }
440
- Column::for_each_enumerated<typename col_type_info::TDT>(
441
- *input_column.column_ ,
442
- [&groups, this ](auto enumerating_it) {
443
- auto & fraction = fractions_[groups[enumerating_it.idx ()]];
444
- if constexpr ((is_floating_point_type (col_type_info ::data_type))) {
445
- if (ARCTICDB_LIKELY (!std::isnan (enumerating_it.value ()))) {
446
- fraction.numerator_ += static_cast <double >(enumerating_it.value ());
447
- ++fraction.denominator_ ;
448
- sparse_map_.set (groups[enumerating_it.idx ()]);
449
- }
450
- } else {
451
- fraction.numerator_ += static_cast <double >(enumerating_it.value ());
452
- ++fraction.denominator_ ;
453
- sparse_map_.set (groups[enumerating_it.idx ()]);
454
- }
433
+ util::BitSet::bulk_insert_iterator inserter (sparse_map_);
434
+ details::visit_type (
435
+ input_column.column_ ->type ().data_type (),
436
+ [&input_column, &groups, &inserter, this ](auto col_tag) {
437
+ using col_type_info = ScalarTypeInfo<decltype (col_tag)>;
438
+ if constexpr (is_sequence_type (col_type_info::data_type)) {
439
+ util::raise_rte (" String aggregations not currently supported" );
440
+ } else if constexpr (is_empty_type (col_type_info::data_type)) {
441
+ return ;
455
442
}
456
- );
457
- });
443
+ Column::for_each_enumerated<typename col_type_info::TDT>(
444
+ *input_column.column_ ,
445
+ [&groups, &inserter, this ](auto enumerating_it) {
446
+ auto & fraction = fractions_[groups[enumerating_it.idx ()]];
447
+ if constexpr ((is_floating_point_type (col_type_info ::data_type))) {
448
+ if (ARCTICDB_LIKELY (!std::isnan (enumerating_it.value ()))) {
449
+ fraction.numerator_ += static_cast <double >(enumerating_it.value ());
450
+ ++fraction.denominator_ ;
451
+ inserter = groups[enumerating_it.idx ()];
452
+ }
453
+ } else {
454
+ fraction.numerator_ += static_cast <double >(enumerating_it.value ());
455
+ ++fraction.denominator_ ;
456
+ inserter = groups[enumerating_it.idx ()];
457
+ }
458
+ }
459
+ );
460
+ }
461
+ );
462
+ inserter.flush ();
458
463
}
459
464
460
465
SegmentInMemory MeanAggregatorData::finalize (const ColumnName& output_column_name, bool , size_t unique_values) {
@@ -500,25 +505,30 @@ void CountAggregatorData::aggregate(
500
505
) {
501
506
aggregated_.resize (unique_values);
502
507
sparse_map_.resize (unique_values);
503
- details::visit_type (input_column.column_ ->type ().data_type (), [&input_column, &groups, this ](auto col_tag) {
504
- using col_type_info = ScalarTypeInfo<decltype (col_tag)>;
505
- Column::for_each_enumerated<typename col_type_info::TDT>(
506
- *input_column.column_ ,
507
- [&groups, this ](auto enumerating_it) {
508
- if constexpr (is_floating_point_type (col_type_info::data_type)) {
509
- if (ARCTICDB_LIKELY (!std::isnan (enumerating_it.value ()))) {
510
- auto & val = aggregated_[groups[enumerating_it.idx ()]];
511
- ++val;
512
- sparse_map_.set (groups[enumerating_it.idx ()]);
508
+ util::BitSet::bulk_insert_iterator inserter (sparse_map_);
509
+ details::visit_type (
510
+ input_column.column_ ->type ().data_type (),
511
+ [&input_column, &groups, &inserter, this ](auto col_tag) {
512
+ using col_type_info = ScalarTypeInfo<decltype (col_tag)>;
513
+ Column::for_each_enumerated<typename col_type_info::TDT>(
514
+ *input_column.column_ ,
515
+ [&groups, &inserter, this ](auto enumerating_it) {
516
+ if constexpr (is_floating_point_type (col_type_info::data_type)) {
517
+ if (ARCTICDB_LIKELY (!std::isnan (enumerating_it.value ()))) {
518
+ auto & val = aggregated_[groups[enumerating_it.idx ()]];
519
+ ++val;
520
+ inserter = groups[enumerating_it.idx ()];
521
+ }
522
+ } else {
523
+ auto & val = aggregated_[groups[enumerating_it.idx ()]];
524
+ ++val;
525
+ inserter = groups[enumerating_it.idx ()];
526
+ }
513
527
}
514
- } else {
515
- auto & val = aggregated_[groups[enumerating_it.idx ()]];
516
- ++val;
517
- sparse_map_.set (groups[enumerating_it.idx ()]);
518
- }
519
- }
520
- );
521
- });
528
+ );
529
+ }
530
+ );
531
+ inserter.flush ();
522
532
}
523
533
524
534
SegmentInMemory CountAggregatorData::finalize (const ColumnName& output_column_name, bool , size_t unique_values) {
@@ -561,11 +571,12 @@ void FirstAggregatorData::aggregate(
561
571
using GlobalRawType = typename GlobalTypeDescriptorTag::DataTypeTag::raw_type;
562
572
aggregated_.resize (sizeof (GlobalRawType) * unique_values);
563
573
sparse_map_.resize (unique_values);
574
+ util::BitSet::bulk_insert_iterator inserter (sparse_map_);
564
575
auto col_data = input_column.column_ ->data ();
565
576
auto out_ptr = reinterpret_cast <GlobalRawType*>(aggregated_.data ());
566
577
details::visit_type (
567
578
input_column.column_ ->type ().data_type (),
568
- [this , &groups, &out_ptr, &col_data](auto col_tag) {
579
+ [this , &groups, &out_ptr, &col_data, &inserter ](auto col_tag) {
569
580
using ColumnTagType = std::decay_t <decltype (col_tag)>;
570
581
using ColumnType = typename ColumnTagType::raw_type;
571
582
auto groups_pos = 0 ;
@@ -580,19 +591,20 @@ void FirstAggregatorData::aggregate(
580
591
if (is_first_group_el || std::isnan (static_cast <ColumnType>(val))) {
581
592
groups_cache_.insert (groups[groups_pos]);
582
593
val = GlobalRawType (*ptr);
583
- sparse_map_. set ( groups[groups_pos]) ;
594
+ inserter = groups[groups_pos];
584
595
}
585
596
} else {
586
597
if (is_first_group_el) {
587
598
groups_cache_.insert (groups[groups_pos]);
588
599
val = GlobalRawType (*ptr);
589
- sparse_map_. set ( groups[groups_pos]) ;
600
+ inserter = groups[groups_pos];
590
601
}
591
602
}
592
603
}
593
604
}
594
605
}
595
606
);
607
+ inserter.flush ();
596
608
});
597
609
}
598
610
}
@@ -641,11 +653,12 @@ void LastAggregatorData::aggregate(
641
653
using GlobalRawType = typename GlobalTypeDescriptorTag::DataTypeTag::raw_type;
642
654
aggregated_.resize (sizeof (GlobalRawType) * unique_values);
643
655
sparse_map_.resize (unique_values);
656
+ util::BitSet::bulk_insert_iterator inserter (sparse_map_);
644
657
auto col_data = input_column.column_ ->data ();
645
658
auto out_ptr = reinterpret_cast <GlobalRawType*>(aggregated_.data ());
646
659
details::visit_type (
647
660
input_column.column_ ->type ().data_type (),
648
- [&groups, &out_ptr, &col_data, this ](auto col_tag) {
661
+ [&groups, &out_ptr, &col_data, &inserter, this ](auto col_tag) {
649
662
using ColumnTagType = std::decay_t <decltype (col_tag)>;
650
663
using ColumnType = typename ColumnTagType::raw_type;
651
664
auto groups_pos = 0 ;
@@ -662,16 +675,17 @@ void LastAggregatorData::aggregate(
662
675
if (is_first_group_el || !std::isnan (static_cast <ColumnType>(curr))) {
663
676
groups_cache_.insert (groups[groups_pos]);
664
677
val = curr;
665
- sparse_map_. set ( groups[groups_pos]) ;
678
+ inserter = groups[groups_pos];
666
679
}
667
680
} else {
668
681
val = GlobalRawType (*ptr);
669
- sparse_map_. set ( groups[groups_pos]) ;
682
+ inserter = groups[groups_pos];
670
683
}
671
684
}
672
685
}
673
686
}
674
687
);
688
+ inserter.flush ();
675
689
});
676
690
}
677
691
}
0 commit comments