Skip to content

Commit

Permalink
Merge pull request #118 from alamb/alamb/less_clone
Browse files Browse the repository at this point in the history
Reduce cloneing in ApproxPercentileAccumulator
  • Loading branch information
Ted-Jiang authored Apr 16, 2024
2 parents ed4c1a8 + 0444e72 commit 2677e7f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,8 @@ impl ApproxPercentileAccumulator {
}

pub(crate) fn merge_digests(&mut self, digests: &[TDigest]) {
let mut input_digests = digests.to_vec();
input_digests.push(self.digest.clone());
self.digest = TDigest::merge_digests(input_digests.as_slice());
let digests = digests.iter().chain(std::iter::once(&self.digest));
self.digest = TDigest::merge_digests(digests)
}

pub(crate) fn convert_to_float(values: &ArrayRef) -> Result<Vec<f64>> {
Expand Down
5 changes: 4 additions & 1 deletion datafusion/physical-expr/src/aggregate/tdigest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,10 @@ impl TDigest {
}

// Merge multiple T-Digests
pub(crate) fn merge_digests(digests: &[TDigest]) -> TDigest {
pub(crate) fn merge_digests<'a>(
digests: impl IntoIterator<Item = &'a TDigest>,
) -> TDigest {
let digests = digests.into_iter().collect::<Vec<_>>();
let n_centroids: usize = digests.iter().map(|d| d.centroids.len()).sum();
if n_centroids == 0 {
return TDigest::default();
Expand Down

0 comments on commit 2677e7f

Please sign in to comment.