From 0d7abe5d239b0dd6d7a8b5e01eacfa6a3cad7209 Mon Sep 17 00:00:00 2001 From: "cong.xie" Date: Fri, 6 Feb 2026 10:28:59 -0500 Subject: [PATCH 1/3] feat(aggregation): add public accessors for intermediate aggregation results Add accessor methods to allow external crates to read intermediate aggregation results without accessing pub(crate) fields: - IntermediateAggregationResults: get(), get_mut(), remove() - IntermediateTermBucketResult: entries(), sum_other_doc_count(), doc_count_error_upper_bound() - IntermediateAverage: stats() - IntermediateStats: count(), sum() - IntermediateKey: Display impl for string conversion --- src/aggregation/intermediate_agg_result.rs | 43 ++++++++++++++++++++++ src/aggregation/metric/average.rs | 6 +++ src/aggregation/metric/stats.rs | 10 +++++ 3 files changed, 59 insertions(+) diff --git a/src/aggregation/intermediate_agg_result.rs b/src/aggregation/intermediate_agg_result.rs index cbc921060..d55f893b8 100644 --- a/src/aggregation/intermediate_agg_result.rs +++ b/src/aggregation/intermediate_agg_result.rs @@ -90,6 +90,19 @@ impl From for Key { impl Eq for IntermediateKey {} +impl std::fmt::Display for IntermediateKey { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + IntermediateKey::Str(val) => f.write_str(val), + IntermediateKey::F64(val) => write!(f, "{val}"), + IntermediateKey::U64(val) => write!(f, "{val}"), + IntermediateKey::I64(val) => write!(f, "{val}"), + IntermediateKey::Bool(val) => write!(f, "{val}"), + IntermediateKey::IpAddr(val) => write!(f, "{val}"), + } + } +} + impl std::hash::Hash for IntermediateKey { fn hash(&self, state: &mut H) { core::mem::discriminant(self).hash(state); @@ -105,6 +118,21 @@ impl std::hash::Hash for IntermediateKey { } impl IntermediateAggregationResults { + /// Returns a reference to the intermediate result for the given aggregation key. + pub fn get(&self, key: &str) -> Option<&IntermediateAggregationResult> { + self.aggs_res.get(key) + } + + /// Returns a mutable reference to the intermediate result for the given aggregation key. + pub fn get_mut(&mut self, key: &str) -> Option<&mut IntermediateAggregationResult> { + self.aggs_res.get_mut(key) + } + + /// Removes and returns the intermediate result for the given aggregation key. + pub fn remove(&mut self, key: &str) -> Option { + self.aggs_res.remove(key) + } + /// Add a result pub fn push(&mut self, key: String, value: IntermediateAggregationResult) -> crate::Result<()> { let entry = self.aggs_res.entry(key); @@ -639,6 +667,21 @@ pub struct IntermediateTermBucketResult { } impl IntermediateTermBucketResult { + /// Returns a reference to the term bucket entries. + pub fn entries(&self) -> &FxHashMap { + &self.entries + } + + /// Returns the count of documents not included in the returned buckets. + pub fn sum_other_doc_count(&self) -> u64 { + self.sum_other_doc_count + } + + /// Returns the upper bound of the document count error for each term. + pub fn doc_count_error_upper_bound(&self) -> u64 { + self.doc_count_error_upper_bound + } + pub(crate) fn into_final_result( self, req: &TermsAggregation, diff --git a/src/aggregation/metric/average.rs b/src/aggregation/metric/average.rs index 57f694984..f205be389 100644 --- a/src/aggregation/metric/average.rs +++ b/src/aggregation/metric/average.rs @@ -55,6 +55,12 @@ impl IntermediateAverage { pub(crate) fn from_stats(stats: IntermediateStats) -> Self { Self { stats } } + + /// Returns a reference to the underlying intermediate stats. + pub fn stats(&self) -> &IntermediateStats { + &self.stats + } + /// Merges the other intermediate result into self. pub fn merge_fruits(&mut self, other: IntermediateAverage) { self.stats.merge_fruits(other.stats); diff --git a/src/aggregation/metric/stats.rs b/src/aggregation/metric/stats.rs index c43a6a259..319a8e978 100644 --- a/src/aggregation/metric/stats.rs +++ b/src/aggregation/metric/stats.rs @@ -110,6 +110,16 @@ impl Default for IntermediateStats { } impl IntermediateStats { + /// Returns the number of extracted values. + pub fn count(&self) -> u64 { + self.count + } + + /// Returns the sum of the extracted values. + pub fn sum(&self) -> f64 { + self.sum + } + /// Merges the other stats intermediate result into self. pub fn merge_fruits(&mut self, other: IntermediateStats) { self.count += other.count; From ae0554a6a5fad9511a8ed5d0a3fa09e803516469 Mon Sep 17 00:00:00 2001 From: "cong.xie" Date: Fri, 6 Feb 2026 10:28:59 -0500 Subject: [PATCH 2/3] feat(aggregation): add public accessors for intermediate aggregation results Add accessor methods to allow external crates to read intermediate aggregation results without accessing pub(crate) fields: - IntermediateAggregationResults: get(), remove() - IntermediateTermBucketResult: entries(), sum_other_doc_count(), doc_count_error_upper_bound() - IntermediateAverage: stats() - IntermediateStats: count(), sum() - IntermediateKey: Display impl for string conversion --- src/aggregation/intermediate_agg_result.rs | 33 ++++++++++++++++++++++ src/aggregation/metric/average.rs | 5 ++++ src/aggregation/metric/stats.rs | 8 ++++++ 3 files changed, 46 insertions(+) diff --git a/src/aggregation/intermediate_agg_result.rs b/src/aggregation/intermediate_agg_result.rs index cbc921060..c580e1d0f 100644 --- a/src/aggregation/intermediate_agg_result.rs +++ b/src/aggregation/intermediate_agg_result.rs @@ -90,6 +90,19 @@ impl From for Key { impl Eq for IntermediateKey {} +impl std::fmt::Display for IntermediateKey { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + IntermediateKey::Str(val) => f.write_str(val), + IntermediateKey::F64(val) => f.write_str(&val.to_string()), + IntermediateKey::U64(val) => f.write_str(&val.to_string()), + IntermediateKey::I64(val) => f.write_str(&val.to_string()), + IntermediateKey::Bool(val) => f.write_str(&val.to_string()), + IntermediateKey::IpAddr(val) => f.write_str(&val.to_string()), + } + } +} + impl std::hash::Hash for IntermediateKey { fn hash(&self, state: &mut H) { core::mem::discriminant(self).hash(state); @@ -105,6 +118,14 @@ impl std::hash::Hash for IntermediateKey { } impl IntermediateAggregationResults { + pub fn get(&self, key: &str) -> Option<&IntermediateAggregationResult> { + self.aggs_res.get(key) + } + + pub fn remove(&mut self, key: &str) -> Option { + self.aggs_res.remove(key) + } + /// Add a result pub fn push(&mut self, key: String, value: IntermediateAggregationResult) -> crate::Result<()> { let entry = self.aggs_res.entry(key); @@ -639,6 +660,18 @@ pub struct IntermediateTermBucketResult { } impl IntermediateTermBucketResult { + pub fn entries(&self) -> &FxHashMap { + &self.entries + } + + pub fn sum_other_doc_count(&self) -> u64 { + self.sum_other_doc_count + } + + pub fn doc_count_error_upper_bound(&self) -> u64 { + self.doc_count_error_upper_bound + } + pub(crate) fn into_final_result( self, req: &TermsAggregation, diff --git a/src/aggregation/metric/average.rs b/src/aggregation/metric/average.rs index 57f694984..b7edc1add 100644 --- a/src/aggregation/metric/average.rs +++ b/src/aggregation/metric/average.rs @@ -55,6 +55,11 @@ impl IntermediateAverage { pub(crate) fn from_stats(stats: IntermediateStats) -> Self { Self { stats } } + + pub fn stats(&self) -> &IntermediateStats { + &self.stats + } + /// Merges the other intermediate result into self. pub fn merge_fruits(&mut self, other: IntermediateAverage) { self.stats.merge_fruits(other.stats); diff --git a/src/aggregation/metric/stats.rs b/src/aggregation/metric/stats.rs index c43a6a259..f0da8ad94 100644 --- a/src/aggregation/metric/stats.rs +++ b/src/aggregation/metric/stats.rs @@ -110,6 +110,14 @@ impl Default for IntermediateStats { } impl IntermediateStats { + pub fn count(&self) -> u64 { + self.count + } + + pub fn sum(&self) -> f64 { + self.sum + } + /// Merges the other stats intermediate result into self. pub fn merge_fruits(&mut self, other: IntermediateStats) { self.count += other.count; From bb141abe22671474f4912075e2f969c249684289 Mon Sep 17 00:00:00 2001 From: "cong.xie" Date: Mon, 9 Feb 2026 15:38:35 -0500 Subject: [PATCH 3/3] feat(aggregation): add keys() accessor to IntermediateAggregationResults --- src/aggregation/intermediate_agg_result.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/aggregation/intermediate_agg_result.rs b/src/aggregation/intermediate_agg_result.rs index 5a3cddd1c..bdc7a0cb0 100644 --- a/src/aggregation/intermediate_agg_result.rs +++ b/src/aggregation/intermediate_agg_result.rs @@ -128,6 +128,11 @@ impl IntermediateAggregationResults { self.aggs_res.remove(key) } + /// Returns an iterator over the keys in the intermediate aggregation results. + pub fn keys(&self) -> impl Iterator { + self.aggs_res.keys() + } + /// Add a result pub fn push(&mut self, key: String, value: IntermediateAggregationResult) -> crate::Result<()> { let entry = self.aggs_res.entry(key);