mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-05-27 05:30:45 +00:00
interim version
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
use std::fmt::Debug;
|
||||
use std::{fmt::Debug, borrow::BorrowMut};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::IntermediateStats;
|
||||
use crate::aggregation::intermediate_agg_result::IntermediateMetricResult;
|
||||
|
||||
use super::{IntermediateStats, IntermediateInnerCollector};
|
||||
|
||||
/// A single-value metric aggregation that computes the minimum of numeric values that are
|
||||
/// extracted from the aggregated documents.
|
||||
@@ -63,3 +65,48 @@ impl IntermediateMin {
|
||||
self.stats.finalize().min
|
||||
}
|
||||
}
|
||||
/*
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct IntermediateMin {
|
||||
min: f64,
|
||||
is_some: bool,
|
||||
}
|
||||
|
||||
impl Default for IntermediateMin {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
min: f64::MAX,
|
||||
is_some: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IntermediateMin {
|
||||
/// Merges the other intermediate result into self.
|
||||
pub fn merge_fruits(&mut self, other: IntermediateMin) {
|
||||
self.min = self.min.min(other.min);
|
||||
}
|
||||
/// Computes the final minimum value.
|
||||
pub fn finalize(&self) -> Option<f64> {
|
||||
if self.is_some {
|
||||
Some(self.min)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
impl IntermediateInnerCollector for IntermediateMin {
|
||||
#[inline]
|
||||
fn collect(&mut self, value: f64) {
|
||||
self.is_some=true;
|
||||
self.min=self.min.min(value);
|
||||
}
|
||||
|
||||
fn into_intermediate_metric_result(self) -> IntermediateMetricResult {
|
||||
IntermediateMetricResult::Min(self)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -303,11 +303,13 @@ impl IntermediateStats {
|
||||
self.count += 1;
|
||||
|
||||
// kahan algorithm for sum
|
||||
|
||||
let y = value - self.delta;
|
||||
let t = self.sum + y;
|
||||
self.delta = (t - self.sum) - y;
|
||||
self.sum = t;
|
||||
|
||||
|
||||
//self.sum+=value;
|
||||
self.min = self.min.min(value);
|
||||
self.max = self.max.max(value);
|
||||
}
|
||||
@@ -396,7 +398,7 @@ impl IntermediateExtendedStats {
|
||||
+ other.intermediate_stats.sum as f64)
|
||||
/ new_count as f64;
|
||||
self.intermediate_stats.sum += other.intermediate_stats.sum;
|
||||
self.intermediate_stats.delta += other.intermediate_stats.delta;
|
||||
//self.intermediate_stats.delta += other.intermediate_stats.delta;
|
||||
self.sum_of_squares_elastic += other.sum_of_squares_elastic;
|
||||
self.delta_sum_for_squares_elastic += other.delta_sum_for_squares_elastic
|
||||
}
|
||||
@@ -545,12 +547,12 @@ impl IntermediateInnerCollector for IntermediateInnerStatsCollector {
|
||||
IntermediateMetricResult::Min(IntermediateMin::from_stats(self.stats))
|
||||
}
|
||||
SegmentStatsType::Stats => IntermediateMetricResult::Stats(self.stats),
|
||||
SegmentStatsType::ExtendedStats => {
|
||||
panic!("cannot create IntermediateMetricResult for ExtendStats from Stats");
|
||||
}
|
||||
SegmentStatsType::Sum => {
|
||||
IntermediateMetricResult::Sum(IntermediateSum::from_stats(self.stats))
|
||||
}
|
||||
_ => {
|
||||
panic!("cannot create IntermediateMetricResult for ExtendStats/Min from Stats");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ use super::metric::{
|
||||
};
|
||||
use crate::aggregation::bucket::TermMissingAgg;
|
||||
use crate::aggregation::metric::{
|
||||
IntermediateInnerExtendedStatsCollector, IntermediateInnerStatsCollector,
|
||||
IntermediateInnerExtendedStatsCollector, IntermediateInnerStatsCollector, IntermediateMin,
|
||||
};
|
||||
|
||||
pub(crate) trait SegmentAggregationCollector: CollectorClone + Debug {
|
||||
|
||||
Reference in New Issue
Block a user