@@ -463,16 +463,15 @@ pub(crate) fn group_aggregate_batch(
463
463
// 1.2
464
464
. or_insert_with ( || {
465
465
batch_keys. append_value ( & key) . expect ( "must not fail" ) ;
466
+ // Note that we still use plain String objects in GroupByScalar. Thus flattened_group_by_values isn't that great.
466
467
let _ = create_group_by_values ( & group_values, row, & mut group_by_values) ;
467
- let mut taken_values =
468
- smallvec ! [ GroupByScalar :: UInt32 ( 0 ) ; group_values. len( ) ] ;
469
- std:: mem:: swap ( & mut taken_values, & mut group_by_values) ;
468
+ accumulation_state. flattened_group_by_values . extend (
469
+ group_by_values. iter_mut ( ) . map ( |x| std:: mem:: replace ( x, GroupByScalar :: UInt32 ( 0 ) ) ) ) ;
470
470
let group_index = accumulation_state. next_group_index ;
471
471
accumulation_state. next_group_index += 1 ;
472
472
(
473
473
key. clone ( ) ,
474
474
AccumulationGroupState {
475
- group_by_values : taken_values,
476
475
indices : smallvec ! [ row as u32 ] ,
477
476
group_index,
478
477
} ,
@@ -884,7 +883,6 @@ pub type Accumulators = HashMap<KeyVec, AccumulationGroupState, RandomState>;
884
883
885
884
#[ allow( missing_docs) ]
886
885
pub struct AccumulationGroupState {
887
- group_by_values : SmallVec < [ GroupByScalar ; 2 ] > ,
888
886
indices : SmallVec < [ u32 ; 4 ] > ,
889
887
group_index : usize ,
890
888
}
@@ -893,6 +891,8 @@ pub struct AccumulationGroupState {
893
891
#[ derive( Default ) ]
894
892
pub struct AccumulationState {
895
893
accumulators : HashMap < KeyVec , AccumulationGroupState , RandomState > ,
894
+ // Of length accumulators.len() * N where N is the number of group by columns.
895
+ flattened_group_by_values : Vec < GroupByScalar > ,
896
896
groups_accumulators : Vec < Box < dyn GroupsAccumulator > > ,
897
897
// For now, always equal to accumulators.len()
898
898
next_group_index : usize ,
@@ -905,6 +905,7 @@ impl AccumulationState {
905
905
) -> AccumulationState {
906
906
AccumulationState {
907
907
accumulators : HashMap :: new ( ) ,
908
+ flattened_group_by_values : Vec :: new ( ) ,
908
909
groups_accumulators,
909
910
next_group_index : 0 ,
910
911
}
@@ -1174,12 +1175,13 @@ pub(crate) fn create_batch_from_map(
1174
1175
for (
1175
1176
_,
1176
1177
AccumulationGroupState {
1177
- group_by_values,
1178
1178
group_index,
1179
1179
..
1180
1180
} ,
1181
1181
) in & accumulation_state. accumulators
1182
1182
{
1183
+ let group_by_values: & [ GroupByScalar ] = & accumulation_state. flattened_group_by_values [ num_group_expr * group_index..num_group_expr * ( group_index + 1 ) ] ;
1184
+
1183
1185
// 2 and 3.
1184
1186
write_group_result_row_with_groups_accumulator (
1185
1187
* mode,
0 commit comments