Skip to content

Commit

Permalink
add date_histogram
Browse files Browse the repository at this point in the history
  • Loading branch information
PSeitz committed Feb 23, 2023
1 parent 5f23bb7 commit 1efc451
Show file tree
Hide file tree
Showing 10 changed files with 335 additions and 30 deletions.
17 changes: 14 additions & 3 deletions src/aggregation/agg_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use std::collections::{HashMap, HashSet};
use serde::{Deserialize, Serialize};

pub use super::bucket::RangeAggregation;
use super::bucket::{HistogramAggregation, TermsAggregation};
use super::bucket::{DateHistogramAggregationReq, HistogramAggregation, TermsAggregation};
use super::metric::{
AverageAggregation, CountAggregation, MaxAggregation, MinAggregation, StatsAggregation,
SumAggregation,
Expand Down Expand Up @@ -110,9 +110,14 @@ impl BucketAggregationInternal {
_ => None,
}
}
pub(crate) fn as_histogram(&self) -> Option<&HistogramAggregation> {
pub(crate) fn as_histogram(&self) -> Option<HistogramAggregation> {
match &self.bucket_agg {
BucketAggregationType::Histogram(histogram) => Some(histogram),
BucketAggregationType::Histogram(histogram) => Some(histogram.clone()),
BucketAggregationType::DateHistogram(histogram) => Some(
histogram
.to_histogram_req()
.expect("could not convert date histogram req to histogram req"),
),
_ => None,
}
}
Expand Down Expand Up @@ -214,6 +219,9 @@ pub enum BucketAggregationType {
/// Put data into buckets of user-defined ranges.
#[serde(rename = "histogram")]
Histogram(HistogramAggregation),
/// Put data into buckets of user-defined ranges.
#[serde(rename = "date_histogram")]
DateHistogram(DateHistogramAggregationReq),
/// Put data into buckets of terms.
#[serde(rename = "terms")]
Terms(TermsAggregation),
Expand All @@ -227,6 +235,9 @@ impl BucketAggregationType {
BucketAggregationType::Histogram(histogram) => {
fast_field_names.insert(histogram.field.to_string())
}
BucketAggregationType::DateHistogram(histogram) => {
fast_field_names.insert(histogram.field.to_string())
}
};
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/aggregation/agg_req_with_accessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use std::sync::atomic::AtomicU32;
use columnar::{Column, ColumnType, StrColumn};

use super::agg_req::{Aggregation, Aggregations, BucketAggregationType, MetricAggregation};
use super::bucket::{HistogramAggregation, RangeAggregation, TermsAggregation};
use super::bucket::{
DateHistogramAggregationReq, HistogramAggregation, RangeAggregation, TermsAggregation,
};
use super::metric::{
AverageAggregation, CountAggregation, MaxAggregation, MinAggregation, StatsAggregation,
SumAggregation,
Expand Down Expand Up @@ -62,6 +64,10 @@ impl BucketAggregationWithAccessor {
BucketAggregationType::Histogram(HistogramAggregation {
field: field_name, ..
}) => get_ff_reader_and_validate(reader, field_name)?,
BucketAggregationType::DateHistogram(DateHistogramAggregationReq {
field: field_name,
..
}) => get_ff_reader_and_validate(reader, field_name)?,
BucketAggregationType::Terms(TermsAggregation {
field: field_name, ..
}) => {
Expand Down
Loading

0 comments on commit 1efc451

Please sign in to comment.