-
-
Notifications
You must be signed in to change notification settings - Fork 721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
alternative mixed field aggregation collection #2135
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,9 +37,6 @@ pub struct AggregationWithAccessor { | |
pub(crate) accessor: Column<u64>, | ||
pub(crate) str_dict_column: Option<StrColumn>, | ||
pub(crate) field_type: ColumnType, | ||
/// In case there are multiple types of fast fields, e.g. string and numeric. | ||
/// Only used for term aggregations currently. | ||
pub(crate) accessor2: Option<(Column<u64>, ColumnType)>, | ||
pub(crate) sub_aggregation: AggregationsWithAccessor, | ||
pub(crate) limits: ResourceLimitGuard, | ||
pub(crate) column_block_accessor: ColumnBlockAccessor<u64>, | ||
|
@@ -52,20 +49,31 @@ impl AggregationWithAccessor { | |
sub_aggregation: &Aggregations, | ||
reader: &SegmentReader, | ||
limits: AggregationLimits, | ||
) -> crate::Result<AggregationWithAccessor> { | ||
) -> crate::Result<Vec<AggregationWithAccessor>> { | ||
let mut str_dict_column = None; | ||
let mut accessor2 = None; | ||
use AggregationVariants::*; | ||
let (accessor, field_type) = match &agg.agg { | ||
let acc_field_types: Vec<(Column, ColumnType)> = match &agg.agg { | ||
Range(RangeAggregation { | ||
field: field_name, .. | ||
}) => get_ff_reader(reader, field_name, Some(get_numeric_or_date_column_types()))?, | ||
}) => vec![get_ff_reader( | ||
reader, | ||
field_name, | ||
Some(get_numeric_or_date_column_types()), | ||
)?], | ||
Histogram(HistogramAggregation { | ||
field: field_name, .. | ||
}) => get_ff_reader(reader, field_name, Some(get_numeric_or_date_column_types()))?, | ||
}) => vec![get_ff_reader( | ||
reader, | ||
field_name, | ||
Some(get_numeric_or_date_column_types()), | ||
)?], | ||
DateHistogram(DateHistogramAggregationReq { | ||
field: field_name, .. | ||
}) => get_ff_reader(reader, field_name, Some(get_numeric_or_date_column_types()))?, | ||
}) => vec![get_ff_reader( | ||
reader, | ||
field_name, | ||
Some(get_numeric_or_date_column_types()), | ||
)?], | ||
Terms(TermsAggregation { | ||
field: field_name, .. | ||
}) => { | ||
|
@@ -80,11 +88,7 @@ impl AggregationWithAccessor { | |
// ColumnType::IpAddr Unsupported | ||
// ColumnType::DateTime Unsupported | ||
]; | ||
let mut columns = | ||
get_all_ff_reader_or_empty(reader, field_name, Some(&allowed_column_types))?; | ||
let first = columns.pop().unwrap(); | ||
accessor2 = columns.pop(); | ||
first | ||
get_all_ff_reader_or_empty(reader, field_name, Some(&allowed_column_types))? | ||
} | ||
Average(AverageAggregation { field: field_name }) | ||
| Count(CountAggregation { field: field_name }) | ||
|
@@ -95,33 +99,37 @@ impl AggregationWithAccessor { | |
let (accessor, field_type) = | ||
get_ff_reader(reader, field_name, Some(get_numeric_or_date_column_types()))?; | ||
|
||
(accessor, field_type) | ||
vec![(accessor, field_type)] | ||
} | ||
Percentiles(percentiles) => { | ||
let (accessor, field_type) = get_ff_reader( | ||
reader, | ||
percentiles.field_name(), | ||
Some(get_numeric_or_date_column_types()), | ||
)?; | ||
(accessor, field_type) | ||
vec![(accessor, field_type)] | ||
} | ||
}; | ||
|
||
let sub_aggregation = sub_aggregation.clone(); | ||
Ok(AggregationWithAccessor { | ||
accessor, | ||
accessor2, | ||
field_type, | ||
sub_aggregation: get_aggs_with_segment_accessor_and_validate( | ||
&sub_aggregation, | ||
reader, | ||
&limits, | ||
)?, | ||
agg: agg.clone(), | ||
str_dict_column, | ||
limits: limits.new_guard(), | ||
column_block_accessor: Default::default(), | ||
}) | ||
let aggs: Vec<AggregationWithAccessor> = acc_field_types | ||
.into_iter() | ||
.map(|(accessor, field_type)| { | ||
Ok(AggregationWithAccessor { | ||
accessor, | ||
field_type, | ||
sub_aggregation: get_aggs_with_segment_accessor_and_validate( | ||
sub_aggregation, | ||
reader, | ||
&limits, | ||
)?, | ||
agg: agg.clone(), | ||
str_dict_column: str_dict_column.clone(), | ||
limits: limits.new_guard(), | ||
column_block_accessor: Default::default(), | ||
}) | ||
}) | ||
.collect::<crate::Result<_>>()?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the return type fixes the types here, so that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand, we need to collect to Result to forward the error There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Certainly, but the extra binding and type hints seem unnecessary because the type that is collected already matches the return type, does it not? So in think the function could just end in acc_field_types
.into_iter()
.map(|(accessor, field_type)| {
Ok(AggregationWithAccessor {
accessor,
field_type,
sub_aggregation: get_aggs_with_segment_accessor_and_validate(
sub_aggregation,
reader,
&limits,
)?,
agg: agg.clone(),
str_dict_column: str_dict_column.clone(),
limits: limits.new_guard(),
column_block_accessor: Default::default(),
})
})
.collect() There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we return a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, which is what you are collecting by giving the type hint (Turning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the binding with type assignment increases readability There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can still spell out the full return type if desired in the turbo-fish if you want to, e.g. .collect::<crate::Result<Vec<AggregationWithAccessor>>>() but the extra binding, error forwarding and ok wrapping are unnecessary. (There is even a Clippy lint for unnecessary let bindings but IIRC it does not firing when ok wrapping is involved because this is sometimes necessary to change the error type via the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't agree, the binding and type serves the purpose of increased readability by giving it a name and a type, which is important if the transformation gets nested There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with @PSeitz . It is more readable when we put the type on the variable side. |
||
Ok(aggs) | ||
} | ||
} | ||
|
||
|
@@ -141,15 +149,15 @@ pub(crate) fn get_aggs_with_segment_accessor_and_validate( | |
) -> crate::Result<AggregationsWithAccessor> { | ||
let mut aggss = Vec::new(); | ||
adamreichold marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for (key, agg) in aggs.iter() { | ||
aggss.push(( | ||
key.to_string(), | ||
AggregationWithAccessor::try_from_agg( | ||
agg, | ||
agg.sub_aggregation(), | ||
reader, | ||
limits.clone(), | ||
)?, | ||
)); | ||
let aggs = AggregationWithAccessor::try_from_agg( | ||
agg, | ||
agg.sub_aggregation(), | ||
reader, | ||
limits.clone(), | ||
)?; | ||
for agg in aggs { | ||
aggss.push((key.to_string(), agg)); | ||
} | ||
} | ||
Ok(AggregationsWithAccessor::from_data( | ||
VecWithNames::from_entries(aggss), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for putting the type!