File tree 1 file changed +8
-1
lines changed
datafusion/physical-plan/src/joins 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -783,6 +783,8 @@ pub(crate) fn estimate_join_statistics(
783
783
join_type : & JoinType ,
784
784
schema : & Schema ,
785
785
) -> Result < Statistics > {
786
+ let l = format ! ( "{left:#?}" ) ;
787
+ let r = format ! ( "{right:#?}" ) ;
786
788
let left_stats = left. statistics ( ) ?;
787
789
let right_stats = right. statistics ( ) ?;
788
790
@@ -955,7 +957,12 @@ fn max_distinct_count(
955
957
let result = match num_rows {
956
958
Precision :: Absent => Precision :: Absent ,
957
959
Precision :: Inexact ( count) => {
958
- Precision :: Inexact ( count - stats. null_count . get_value ( ) . unwrap_or ( & 0 ) )
960
+ // To safeguard against inexact number of rows (e.g. 0) being smaller than
961
+ // an exact null count we need to do a checked subtraction.
962
+ match count. checked_sub ( * stats. null_count . get_value ( ) . unwrap_or ( & 0 ) ) {
963
+ None => Precision :: Inexact ( 0 ) ,
964
+ Some ( non_null_count) => Precision :: Inexact ( non_null_count) ,
965
+ }
959
966
}
960
967
Precision :: Exact ( count) => {
961
968
let count = count - stats. null_count . get_value ( ) . unwrap_or ( & 0 ) ;
You can’t perform that action at this time.
0 commit comments