pub fn merge(
        mut self,
        mut other: ReadAggregateResult<'row_group>,
    ) -> ReadAggregateResult<'row_group> {
        assert_eq!(self.schema(), other.schema());

        if self.is_empty() {
            return other;
        } else if other.is_empty() {
            return self;
        }

        // `read_aggregate` uses a variety of ways to generate results. It is
        // not safe to assume any particular ordering, so we will sort self and
        // other and do a merge.
        if !self.group_keys_sorted() {
            self.sort();
        }

        if !other.group_keys_sorted() {
            other.sort();
        }

        let self_group_keys = self.cardinality();
        let self_len = self.rows();
        let other_len = other.rows();
        let mut result = Self::with_capacity(self.schema, self_len.max(other_len));

        let mut i: usize = 0;
        let mut j: usize = 0;
        while i < self_len || j < other_len {
            if i >= self_len {
                // drained self, add the rest of other
                result
                    .group_keys
                    .extend(other.group_keys.iter().skip(j).cloned());
                result
                    .aggregates
                    .extend(other.aggregates.iter().skip(j).cloned());
                return result;
            } else if j >= other_len {
                // drained other, add the rest of self
                result
                    .group_keys
                    .extend(self.group_keys.iter().skip(j).cloned());
                result
                    .aggregates
                    .extend(self.aggregates.iter().skip(j).cloned());
                return result;
            }

            // just merge the aggregate if there are no group keys
            if self_group_keys == 0 {
                assert!((self_len == other_len) && self_len == 1); // there should be a single aggregate row
                self.aggregates[i].merge(&other.aggregates[j]);
                result.aggregates.push(self.aggregates[i].clone());
                return result;
            }

            // there are group keys so merge them.
            match self.group_keys[i].cmp(&other.group_keys[j]) {
                Ordering::Less => {
                    result.group_keys.push(self.group_keys[i].clone());
                    result.aggregates.push(self.aggregates[i].clone());
                    i += 1;
                }
                Ordering::Equal => {
                    // merge aggregates
                    self.aggregates[i].merge(&other.aggregates[j]);
                    result.group_keys.push(self.group_keys[i].clone());
                    result.aggregates.push(self.aggregates[i].clone());
                    i += 1;
                    j += 1;
                }
                Ordering::Greater => {
                    result.group_keys.push(other.group_keys[j].clone());
                    result.aggregates.push(other.aggregates[j].clone());
                    j += 1;
                }
            }
        }

        result
    }
/// Merges `other` and self, returning a new set of results.
///
/// NOTE: This is slow! Not expected to be the final type of implementation
Merges `other` and self, returning a new set of results.
NOTE: This is slow. Not expected to be the final type of implementation
Merges ` other ` and self returning a new set of results . NOTE : This is slow . Not expected to be the final type of implementation
pub fn merge(
        mut self,
        mut other: ReadAggregateResult<'row_group>,
    ) -> ReadAggregateResult<'row_group> {
        assert_eq!(self.schema(), other.schema());
        if self.is_empty() {
            return other;
        } else if other.is_empty() {
            return self;
        }
        // `read_aggregate` uses a variety of ways to generate results. It is
        // not safe to assume any particular ordering, so we will sort self and
        // other and do a merge.
        if !self.group_keys_sorted() {
            self.sort();
        }
        if !other.group_keys_sorted() {
            other.sort();
        }
        let self_group_keys = self.cardinality();
        let self_len = self.rows();
        let other_len = other.rows();
        let mut result = Self::with_capacity(self.schema, self_len.max(other_len));
        let mut i: usize = 0;
        let mut j: usize = 0;
        while i < self_len || j < other_len {
            if i >= self_len {
                // drained self, add the rest of other
                result
                    .group_keys
                    .extend(other.group_keys.iter().skip(j).cloned());
                result
                    .aggregates
                    .extend(other.aggregates.iter().skip(j).cloned());
                return result;
            } else if j >= other_len {
                // drained other, add the rest of self
                result
                    .group_keys
                    .extend(self.group_keys.iter().skip(j).cloned());
                result
                    .aggregates
                    .extend(self.aggregates.iter().skip(j).cloned());
                return result;
            }
            // just merge the aggregate if there are no group keys
            if self_group_keys == 0 {
                assert!((self_len == other_len) && self_len == 1); // there should be a single aggregate row
                self.aggregates[i].merge(&other.aggregates[j]);
                result.aggregates.push(self.aggregates[i].clone());
                return result;
            }
            // there are group keys so merge them.
            match self.group_keys[i].cmp(&other.group_keys[j]) {
                Ordering::Less => {
                    result.group_keys.push(self.group_keys[i].clone());
                    result.aggregates.push(self.aggregates[i].clone());
                    i += 1;
                }
                Ordering::Equal => {
                    // merge aggregates
                    self.aggregates[i].merge(&other.aggregates[j]);
                    result.group_keys.push(self.group_keys[i].clone());
                    result.aggregates.push(self.aggregates[i].clone());
                    i += 1;
                    j += 1;
                }
                Ordering::Greater => {
                    result.group_keys.push(other.group_keys[j].clone());
                    result.aggregates.push(other.aggregates[j].clone());
                    j += 1;
                }
            }
        }
        result
    }
pub fn merge ( mut self , mut other : ReadAggregateResult < ' row_group > , ) -> ReadAggregateResult < ' row_group > { assert_eq ! ( self schema ( ) other schema ( ) ) ; if self . is_empty ( ) { return other ; } else if other . is_empty ( ) { return self ; } // `read_aggregate` uses a variety of ways to generate results. It is // not safe to assume any particular ordering, so we will sort self and // other and do a merge. if ! self . group_keys_sorted ( ) { self . sort ( ) ; } if ! other . group_keys_sorted ( ) { other . sort ( ) ; } let self_group_keys = self . cardinality ( ) ; let self_len = self . rows ( ) ; let other_len = other . rows ( ) ; let mut result = Self :: with_capacity ( self . schema , self_len . max ( other_len ) ) ; let mut i : usize = 0 ; let mut j : usize = 0 ; while i < self_len || j < other_len { if i >= self_len { // drained self, add the rest of other result . group_keys . extend ( other . group_keys . iter ( ) . skip ( j ) . cloned ( ) ) ; result . aggregates . extend ( other . aggregates . iter ( ) . skip ( j ) . cloned ( ) ) ; return result ; } else if j >= other_len { // drained other, add the rest of self result . group_keys . extend ( self . group_keys . iter ( ) . skip ( j ) . cloned ( ) ) ; result . aggregates . extend ( self . aggregates . iter ( ) . skip ( j ) . cloned ( ) ) ; return result ; } // just merge the aggregate if there are no group keys if self_group_keys == 0 { assert ! ( ( self_len other_len ) self_len 1 ) ; // there should be a single aggregate row self . aggregates [ i ] . merge ( & other . aggregates [ j ] ) ; result . aggregates . push ( self . aggregates [ i ] . clone ( ) ) ; return result ; } // there are group keys so merge them. match self . group_keys [ i ] . cmp ( & other . group_keys [ j ] ) { Ordering :: Less => { result . group_keys . push ( self . group_keys [ i ] . clone ( ) ) ; result . aggregates . push ( self . aggregates [ i ] . clone ( ) ) ; i += 1 ; } Ordering :: Equal => { // merge aggregates self . aggregates [ i ] . merge ( & other . aggregates [ j ] ) ; result . group_keys . push ( self . group_keys [ i ] . clone ( ) ) ; result . aggregates . push ( self . aggregates [ i ] . clone ( ) ) ; i += 1 ; j += 1 ; } Ordering :: Greater => { result . group_keys . push ( other . group_keys [ j ] . clone ( ) ) ; result . aggregates . push ( other . aggregates [ j ] . clone ( ) ) ; j += 1 ; } } } result }
Merges `other` and self, returning a new set of results.
Merges ` other ` and self returning a new set of results .
mut self
other
ReadAggregateResult<'row_group>
mut self
other
ReadAggregateResult<'row_group>