Skip to content

Commit 2fb0a43

Browse files
committed
simplify
Signed-off-by: Adam Gutglick <[email protected]>
1 parent 4e420d6 commit 2fb0a43

1 file changed

Lines changed: 18 additions & 29 deletions

File tree

‎datafusion/common/src/stats.rs‎

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -912,36 +912,25 @@ fn precision_add_for_sum_in_place(
912912
lhs: &mut Precision<ScalarValue>,
913913
rhs: &Precision<ScalarValue>,
914914
) {
915-
match rhs {
916-
Precision::Exact(value) => {
917-
let source_type = value.data_type();
918-
let target_type = Precision::<ScalarValue>::sum_data_type(&source_type);
919-
if source_type == target_type {
920-
precision_add(lhs, rhs);
921-
} else {
922-
let rhs = value
923-
.cast_to(&target_type)
924-
.map(Precision::Exact)
925-
.unwrap_or(Precision::Absent);
926-
precision_add(lhs, &rhs);
927-
}
928-
}
929-
Precision::Inexact(value) => {
930-
let source_type = value.data_type();
931-
let target_type = Precision::<ScalarValue>::sum_data_type(&source_type);
932-
if source_type == target_type {
933-
precision_add(lhs, rhs);
934-
} else {
935-
let rhs = value
936-
.cast_to(&target_type)
937-
.map(Precision::Inexact)
938-
.unwrap_or(Precision::Absent);
939-
precision_add(lhs, &rhs);
915+
let (value, wrap_fn): (&ScalarValue, fn(ScalarValue) -> Precision<ScalarValue>) =
916+
match rhs {
917+
Precision::Exact(v) => (v, Precision::Exact),
918+
Precision::Inexact(v) => (v, Precision::Inexact),
919+
Precision::Absent => {
920+
*lhs = Precision::Absent;
921+
return;
940922
}
941-
}
942-
Precision::Absent => {
943-
*lhs = Precision::Absent;
944-
}
923+
};
924+
let source_type = value.data_type();
925+
let target_type = Precision::<ScalarValue>::sum_data_type(&source_type);
926+
if source_type == target_type {
927+
precision_add(lhs, rhs);
928+
} else {
929+
let rhs = value
930+
.cast_to(&target_type)
931+
.map(wrap_fn)
932+
.unwrap_or(Precision::Absent);
933+
precision_add(lhs, &rhs);
945934
}
946935
}
947936

0 commit comments

Comments
 (0)