fn read_group_single_group_column<'a>(
        &'a self,
        dst: &mut ReadAggregateResult<'a>,
        groupby_encoded_ids: &[u32],
        aggregate_columns_data: Vec<Values<'a>>,
    ) {
        assert_eq!(dst.schema().group_columns.len(), 1);
        let column = self.column_by_name(dst.schema.group_column_names_iter().next().unwrap());

        // Allocate a vector to hold aggregates that can be updated as rows are
        // processed. An extra group is required because encoded ids are
        // 0-indexed.
        let required_groups = groupby_encoded_ids.iter().max().unwrap() + 1;
        let mut groups: Vec<Option<Vec<AggregateResult<'_>>>> =
            vec![None; required_groups as usize];

        for (row, encoded_id) in groupby_encoded_ids.iter().enumerate() {
            let idx = *encoded_id as usize;
            match &mut groups[idx] {
                Some(group_key_aggs) => {
                    // Update all aggregates for the group key
                    for (i, values) in aggregate_columns_data.iter().enumerate() {
                        group_key_aggs[i].update(values.value(row));
                    }
                }
                None => {
                    let mut group_key_aggs = dst
                        .schema
                        .aggregate_columns
                        .iter()
                        .map(|(_, agg_type, _)| AggregateResult::from(agg_type))
                        .collect::<Vec<_>>();

                    for (i, values) in aggregate_columns_data.iter().enumerate() {
                        group_key_aggs[i].update(values.value(row));
                    }

                    groups[idx] = Some(group_key_aggs);
                }
            }
        }

        // Finally, build results set. Each encoded group key needs to be
        // materialised into a logical group key
        let mut group_key_vec: Vec<GroupKey<'_>> = Vec::with_capacity(groups.len());
        let mut aggregate_vec = Vec::with_capacity(groups.len());

        for (group_key, aggs) in groups.into_iter().enumerate() {
            if let Some(aggs) = aggs {
                group_key_vec.push(GroupKey(vec![column.decode_id(group_key as u32)]));
                aggregate_vec.push(AggregateResults(aggs));
            }
        }

        dst.group_keys = group_key_vec;
        dst.aggregates = aggregate_vec;
    }
// Optimised `read_group` path for queries where only a single column is
// being grouped on. In this case building a hash table is not necessary,
// and the group keys can be used as indexes into a vector whose values
// contain aggregates. As rows are processed these aggregates can be updated
// in constant time.
Optimised `read_group` path for queries where only a single column is
being grouped on. In this case building a hash table is not necessary,
and the group keys can be used as indexes into a vector whose values
contain aggregates. As rows are processed these aggregates can be updated
in constant time.
Optimised ` read_group ` path for queries where only a single column is being grouped on . In this case building a hash table is not necessary and the group keys can be used as indexes into a vector whose values contain aggregates . As rows are processed these aggregates can be updated in constant time .
fn read_group_single_group_column<'a>(
        &'a self,
        dst: &mut ReadAggregateResult<'a>,
        groupby_encoded_ids: &[u32],
        aggregate_columns_data: Vec<Values<'a>>,
    ) {
        assert_eq!(dst.schema().group_columns.len(), 1);
        let column = self.column_by_name(dst.schema.group_column_names_iter().next().unwrap());
        // Allocate a vector to hold aggregates that can be updated as rows are
        // processed. An extra group is required because encoded ids are
        // 0-indexed.
        let required_groups = groupby_encoded_ids.iter().max().unwrap() + 1;
        let mut groups: Vec<Option<Vec<AggregateResult<'_>>>> =
            vec![None; required_groups as usize];
        for (row, encoded_id) in groupby_encoded_ids.iter().enumerate() {
            let idx = *encoded_id as usize;
            match &mut groups[idx] {
                Some(group_key_aggs) => {
                    // Update all aggregates for the group key
                    for (i, values) in aggregate_columns_data.iter().enumerate() {
                        group_key_aggs[i].update(values.value(row));
                    }
                }
                None => {
                    let mut group_key_aggs = dst
                        .schema
                        .aggregate_columns
                        .iter()
                        .map(|(_, agg_type, _)| AggregateResult::from(agg_type))
                        .collect::<Vec<_>>();
                    for (i, values) in aggregate_columns_data.iter().enumerate() {
                        group_key_aggs[i].update(values.value(row));
                    }
                    groups[idx] = Some(group_key_aggs);
                }
            }
        }
        // Finally, build results set. Each encoded group key needs to be
        // materialised into a logical group key
        let mut group_key_vec: Vec<GroupKey<'_>> = Vec::with_capacity(groups.len());
        let mut aggregate_vec = Vec::with_capacity(groups.len());
        for (group_key, aggs) in groups.into_iter().enumerate() {
            if let Some(aggs) = aggs {
                group_key_vec.push(GroupKey(vec![column.decode_id(group_key as u32)]));
                aggregate_vec.push(AggregateResults(aggs));
            }
        }
        dst.group_keys = group_key_vec;
        dst.aggregates = aggregate_vec;
    }
fn read_group_single_group_column < ' a > ( & ' a self , dst : & mut ReadAggregateResult < ' a > , groupby_encoded_ids : & [ u32 ] , aggregate_columns_data : Vec < Values < ' a > > , ) { assert_eq ! ( dst schema ( ) group_columns len ( ) 1 ) ; let column = self . column_by_name ( dst . schema . group_column_names_iter ( ) . next ( ) . unwrap ( ) ) ; // Allocate a vector to hold aggregates that can be updated as rows are // processed. An extra group is required because encoded ids are // 0-indexed. let required_groups = groupby_encoded_ids . iter ( ) . max ( ) . unwrap ( ) + 1 ; let mut groups : Vec < Option < Vec < AggregateResult < ' _ > > > > = vec ! [ None required_groups as usize ] ; for ( row , encoded_id ) in groupby_encoded_ids . iter ( ) . enumerate ( ) { let idx = * encoded_id as usize ; match & mut groups [ idx ] { Some ( group_key_aggs ) => { // Update all aggregates for the group key for ( i , values ) in aggregate_columns_data . iter ( ) . enumerate ( ) { group_key_aggs [ i ] . update ( values . value ( row ) ) ; } } None => { let mut group_key_aggs = dst . schema . aggregate_columns . iter ( ) . map ( | ( _ , agg_type , _ ) | AggregateResult :: from ( agg_type ) ) . collect :: < Vec < _ > > ( ) ; for ( i , values ) in aggregate_columns_data . iter ( ) . enumerate ( ) { group_key_aggs [ i ] . update ( values . value ( row ) ) ; } groups [ idx ] = Some ( group_key_aggs ) ; } } } // Finally, build results set. Each encoded group key needs to be // materialised into a logical group key let mut group_key_vec : Vec < GroupKey < ' _ > > = Vec :: with_capacity ( groups . len ( ) ) ; let mut aggregate_vec = Vec :: with_capacity ( groups . len ( ) ) ; for ( group_key , aggs ) in groups . into_iter ( ) . enumerate ( ) { if let Some ( aggs ) = aggs { group_key_vec . push ( GroupKey ( vec ! [ column decode_id ( group_key as u32 ) ] ) ) ; aggregate_vec . push ( AggregateResults ( aggs ) ) ; } } dst . group_keys = group_key_vec ; dst . aggregates = aggregate_vec ; }
Optimised `read_group` path for queries where only a single column is
being grouped on.
Optimised ` read_group ` path for queries where only a single column is being grouped on .
&'a self
dst
&mut ReadAggregateResult<'a>
groupby_encoded_ids
&[u32]
aggregate_columns_data
Vec<Values<'a>>
&'a self
dst
&mut ReadAggregateResult<'a>
groupby_encoded_ids
&[u32]
aggregate_columns_data
Vec<Values<'a>>