This commit is contained in:
Pascal Seitz
2022-03-17 16:37:02 +08:00
parent aa391bf843
commit f619658e2c
4 changed files with 18 additions and 17 deletions

View File

@@ -61,12 +61,12 @@ pub type Aggregations = HashMap<String, Aggregation>;
/// Like Aggregations, but optimized to work with the aggregation result
#[derive(Clone, Debug)]
pub(crate) struct CollectorAggregations {
pub(crate) struct AggregationsInternal {
pub(crate) metrics: VecWithNames<MetricAggregation>,
pub(crate) buckets: VecWithNames<CollectorBucketAggregation>,
pub(crate) buckets: VecWithNames<BucketAggregationInternal>,
}
impl From<Aggregations> for CollectorAggregations {
impl From<Aggregations> for AggregationsInternal {
fn from(aggs: Aggregations) -> Self {
let mut metrics = vec![];
let mut buckets = vec![];
@@ -74,7 +74,7 @@ impl From<Aggregations> for CollectorAggregations {
match agg {
Aggregation::Bucket(bucket) => buckets.push((
key,
CollectorBucketAggregation {
BucketAggregationInternal {
bucket_agg: bucket.bucket_agg,
sub_aggregation: bucket.sub_aggregation.into(),
},
@@ -90,15 +90,16 @@ impl From<Aggregations> for CollectorAggregations {
}
#[derive(Clone, Debug)]
pub(crate) struct CollectorBucketAggregation {
// Like BucketAggregation, but optimized to work with the result
pub(crate) struct BucketAggregationInternal {
/// Bucket aggregation strategy to group documents.
pub bucket_agg: BucketAggregationType,
/// The sub_aggregations in the buckets. Each bucket will aggregate on the document set in the
/// bucket.
pub sub_aggregation: CollectorAggregations,
pub sub_aggregation: AggregationsInternal,
}
impl CollectorBucketAggregation {
impl BucketAggregationInternal {
pub(crate) fn as_histogram(&self) -> &HistogramAggregation {
match &self.bucket_agg {
BucketAggregationType::Range(_) => panic!("unexpected aggregation"),

View File

@@ -10,7 +10,7 @@ use std::collections::HashMap;
use itertools::Itertools;
use serde::{Deserialize, Serialize};
use super::agg_req::{Aggregations, CollectorAggregations, CollectorBucketAggregation};
use super::agg_req::{Aggregations, AggregationsInternal, BucketAggregationInternal};
use super::bucket::intermediate_buckets_to_final_buckets;
use super::intermediate_agg_result::{
IntermediateAggregationResults, IntermediateBucketResult, IntermediateHistogramBucketEntry,
@@ -37,7 +37,7 @@ impl AggregationResults {
/// for internal processing
fn from_intermediate_and_req_internal(
results: IntermediateAggregationResults,
req: &CollectorAggregations,
req: &AggregationsInternal,
) -> Self {
let mut result = HashMap::default();
@@ -145,7 +145,7 @@ pub enum BucketResult {
impl BucketResult {
fn from_intermediate_and_req(
bucket_result: IntermediateBucketResult,
req: &CollectorBucketAggregation,
req: &BucketAggregationInternal,
) -> Self {
match bucket_result {
IntermediateBucketResult::Range(range_map) => {
@@ -217,7 +217,7 @@ pub struct BucketEntry {
impl BucketEntry {
pub(crate) fn from_intermediate_and_req(
entry: IntermediateHistogramBucketEntry,
req: &CollectorAggregations,
req: &AggregationsInternal,
) -> Self {
BucketEntry {
key: Key::F64(entry.key),
@@ -280,7 +280,7 @@ pub struct RangeBucketEntry {
impl RangeBucketEntry {
fn from_intermediate_and_req(
entry: IntermediateRangeBucketEntry,
req: &CollectorAggregations,
req: &AggregationsInternal,
) -> Self {
RangeBucketEntry {
key: entry.key,

View File

@@ -4,7 +4,7 @@ use std::fmt::Display;
use itertools::Itertools;
use serde::{Deserialize, Serialize};
use crate::aggregation::agg_req::CollectorAggregations;
use crate::aggregation::agg_req::AggregationsInternal;
use crate::aggregation::agg_req_with_accessor::{
AggregationsWithAccessor, BucketAggregationWithAccessor,
};
@@ -389,7 +389,7 @@ fn get_bucket_val(val: f64, interval: f64, offset: f64) -> f64 {
fn intermediate_buckets_to_final_buckets_fill_gaps(
buckets: Vec<IntermediateHistogramBucketEntry>,
histogram_req: &HistogramAggregation,
sub_aggregation: &CollectorAggregations,
sub_aggregation: &AggregationsInternal,
) -> Vec<BucketEntry> {
// Generate the the full list of buckets without gaps.
//
@@ -440,7 +440,7 @@ fn intermediate_buckets_to_final_buckets_fill_gaps(
pub(crate) fn intermediate_buckets_to_final_buckets(
buckets: Vec<IntermediateHistogramBucketEntry>,
histogram_req: &HistogramAggregation,
sub_aggregation: &CollectorAggregations,
sub_aggregation: &AggregationsInternal,
) -> Vec<BucketEntry> {
if histogram_req.min_doc_count() == 0 {
// With min_doc_count != 0, we may need to add buckets, so that there are no

View File

@@ -8,7 +8,7 @@ use fnv::FnvHashMap;
use itertools::Itertools;
use serde::{Deserialize, Serialize};
use super::agg_req::{BucketAggregationType, CollectorAggregations, MetricAggregation};
use super::agg_req::{AggregationsInternal, BucketAggregationType, MetricAggregation};
use super::metric::{IntermediateAverage, IntermediateStats};
use super::segment_agg_result::{
SegmentAggregationResultsCollector, SegmentBucketResultCollector, SegmentHistogramBucketEntry,
@@ -34,7 +34,7 @@ impl From<SegmentAggregationResultsCollector> for IntermediateAggregationResults
}
impl IntermediateAggregationResults {
pub(crate) fn empty_from_req(req: &CollectorAggregations) -> Self {
pub(crate) fn empty_from_req(req: &AggregationsInternal) -> Self {
let metrics = if req.metrics.is_empty() {
None
} else {