-
-
Notifications
You must be signed in to change notification settings - Fork 695
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
Conversation
instead of having multiple accessor in one AggregationWithAccessor split it into multiple independent AggregationWithAccessor
column_block_accessor: Default::default(), | ||
}) | ||
}) | ||
.collect::<crate::Result<_>>()?; |
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.
I think the return type fixes the types here, so that let aggs: ...
, Ok(aggs)
and the ?
are unnecessary, i.e. it could just end in }).collect()
.
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.
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
we return a Result<Vec>
not Vec<Result>
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.
Yes, which is what you are collecting by giving the type hint ::<crate::Result<_>>
but that type hint just matches the return type. I am not suggesting to change any types, just to drop the unnecessary temporary binding and error forwarding because the collection already produces exactly the required type.
(Turning Iterator<Item=Result<S>>
into Result<T> where T: FromIterator<Item=S>
is the usual FromIterator
impl which you invoke either way.)
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.
I think the binding with type assignment increases readability
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.
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 From
invocation hidding in ?
.)
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.
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 comment
The 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.
use AggregationVariants::*; | ||
let (accessor, field_type) = match &agg.agg { | ||
let acc_field_types: Vec<(Column, ColumnType)> = match &agg.agg { |
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!
Co-authored-by: Paul Masurel <[email protected]>
instead of having multiple accessor in one AggregationWithAccessor split it into
multiple independent AggregationWithAccessor
Performance seems unchanged