Rachelint commented on code in PR #11802:
URL: https://github.com/apache/datafusion/pull/11802#discussion_r1705074900
##########
datafusion/core/src/datasource/statistics.rs:
##########
@@ -238,45 +214,61 @@ fn min_max_aggregate_data_type(input_type: &DataType) ->
&DataType {
/// If the given value is numerically greater than the original maximum value,
/// return the new maximum value with appropriate exactness information.
fn set_max_if_greater(
- max_nominee: Precision<ScalarValue>,
- max_values: Precision<ScalarValue>,
-) -> Precision<ScalarValue> {
- match (&max_values, &max_nominee) {
- (Precision::Exact(val1), Precision::Exact(val2)) if val1 < val2 =>
max_nominee,
+ max_nominee: &Precision<ScalarValue>,
+ max_value: &mut Precision<ScalarValue>,
+) {
+ match (&max_value, max_nominee) {
+ (Precision::Exact(val1), Precision::Exact(val2)) if val1 < val2 => {
+ *max_value = max_nominee.clone();
+ }
(Precision::Exact(val1), Precision::Inexact(val2))
| (Precision::Inexact(val1), Precision::Inexact(val2))
| (Precision::Inexact(val1), Precision::Exact(val2))
if val1 < val2 =>
{
- max_nominee.to_inexact()
+ *max_value = max_nominee.clone().to_inexact();
+ }
+ (Precision::Exact(_), Precision::Absent) => {
+ let exact_max = mem::take(max_value);
+ *max_value = exact_max.to_inexact();
+ }
+ (Precision::Absent, Precision::Exact(_)) => {
+ *max_value = max_nominee.clone().to_inexact();
+ }
+ (Precision::Absent, Precision::Inexact(_)) => {
+ *max_value = max_nominee.clone();
}
- (Precision::Exact(_), Precision::Absent) => max_values.to_inexact(),
- (Precision::Absent, Precision::Exact(_)) => max_nominee.to_inexact(),
- (Precision::Absent, Precision::Inexact(_)) => max_nominee,
- (Precision::Absent, Precision::Absent) => Precision::Absent,
- _ => max_values,
+ _ => {}
}
}
/// If the given value is numerically lesser than the original minimum value,
/// return the new minimum value with appropriate exactness information.
fn set_min_if_lesser(
- min_nominee: Precision<ScalarValue>,
- min_values: Precision<ScalarValue>,
-) -> Precision<ScalarValue> {
- match (&min_values, &min_nominee) {
- (Precision::Exact(val1), Precision::Exact(val2)) if val1 > val2 =>
min_nominee,
+ min_nominee: &Precision<ScalarValue>,
Review Comment:
> 💯 to reduce this copy
I think the alternative may be that we refactor the clone expensive scalars
to the clone cheap impl (like `String` to `Arc<str>`)?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]