Skip to content

Commit 6bf185d

Browse files
Merge pull request #2829 from quickwit-oss/cong.xie/add-intermediate-accessors
2 parents 28db952 + bb141ab commit 6bf185d

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

src/aggregation/intermediate_agg_result.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,19 @@ impl From<IntermediateKey> for Key {
9090

9191
impl Eq for IntermediateKey {}
9292

93+
impl std::fmt::Display for IntermediateKey {
94+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
95+
match self {
96+
IntermediateKey::Str(val) => f.write_str(val),
97+
IntermediateKey::F64(val) => f.write_str(&val.to_string()),
98+
IntermediateKey::U64(val) => f.write_str(&val.to_string()),
99+
IntermediateKey::I64(val) => f.write_str(&val.to_string()),
100+
IntermediateKey::Bool(val) => f.write_str(&val.to_string()),
101+
IntermediateKey::IpAddr(val) => f.write_str(&val.to_string()),
102+
}
103+
}
104+
}
105+
93106
impl std::hash::Hash for IntermediateKey {
94107
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
95108
core::mem::discriminant(self).hash(state);
@@ -105,6 +118,21 @@ impl std::hash::Hash for IntermediateKey {
105118
}
106119

107120
impl IntermediateAggregationResults {
121+
/// Returns a reference to the intermediate aggregation result for the given key.
122+
pub fn get(&self, key: &str) -> Option<&IntermediateAggregationResult> {
123+
self.aggs_res.get(key)
124+
}
125+
126+
/// Removes and returns the intermediate aggregation result for the given key.
127+
pub fn remove(&mut self, key: &str) -> Option<IntermediateAggregationResult> {
128+
self.aggs_res.remove(key)
129+
}
130+
131+
/// Returns an iterator over the keys in the intermediate aggregation results.
132+
pub fn keys(&self) -> impl Iterator<Item = &String> {
133+
self.aggs_res.keys()
134+
}
135+
108136
/// Add a result
109137
pub fn push(&mut self, key: String, value: IntermediateAggregationResult) -> crate::Result<()> {
110138
let entry = self.aggs_res.entry(key);
@@ -639,6 +667,21 @@ pub struct IntermediateTermBucketResult {
639667
}
640668

641669
impl IntermediateTermBucketResult {
670+
/// Returns a reference to the map of bucket entries keyed by [`IntermediateKey`].
671+
pub fn entries(&self) -> &FxHashMap<IntermediateKey, IntermediateTermBucketEntry> {
672+
&self.entries
673+
}
674+
675+
/// Returns the count of documents not included in the returned buckets.
676+
pub fn sum_other_doc_count(&self) -> u64 {
677+
self.sum_other_doc_count
678+
}
679+
680+
/// Returns the upper bound of the error on document counts in the returned buckets.
681+
pub fn doc_count_error_upper_bound(&self) -> u64 {
682+
self.doc_count_error_upper_bound
683+
}
684+
642685
pub(crate) fn into_final_result(
643686
self,
644687
req: &TermsAggregation,

src/aggregation/metric/average.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ impl IntermediateAverage {
5555
pub(crate) fn from_stats(stats: IntermediateStats) -> Self {
5656
Self { stats }
5757
}
58+
59+
/// Returns a reference to the underlying [`IntermediateStats`].
60+
pub fn stats(&self) -> &IntermediateStats {
61+
&self.stats
62+
}
63+
5864
/// Merges the other intermediate result into self.
5965
pub fn merge_fruits(&mut self, other: IntermediateAverage) {
6066
self.stats.merge_fruits(other.stats);

src/aggregation/metric/stats.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ impl Default for IntermediateStats {
110110
}
111111

112112
impl IntermediateStats {
113+
/// Returns the number of values collected.
114+
pub fn count(&self) -> u64 {
115+
self.count
116+
}
117+
118+
/// Returns the sum of all values collected.
119+
pub fn sum(&self) -> f64 {
120+
self.sum
121+
}
122+
113123
/// Merges the other stats intermediate result into self.
114124
pub fn merge_fruits(&mut self, other: IntermediateStats) {
115125
self.count += other.count;

0 commit comments

Comments
 (0)