Skip to content

Commit

Permalink
Safeguard against potential inexact row count being smaller than exac…
Browse files Browse the repository at this point in the history
…t null count
  • Loading branch information
gruuya committed Jan 26, 2024
1 parent 8a4bad4 commit be142d5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion datafusion/physical-plan/src/joins/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,8 @@ pub(crate) fn estimate_join_statistics(
join_type: &JoinType,
schema: &Schema,
) -> Result<Statistics> {
let l = format!("{left:#?}");
let r = format!("{right:#?}");
let left_stats = left.statistics()?;
let right_stats = right.statistics()?;

Expand Down Expand Up @@ -955,7 +957,12 @@ fn max_distinct_count(
let result = match num_rows {
Precision::Absent => Precision::Absent,
Precision::Inexact(count) => {
Precision::Inexact(count - stats.null_count.get_value().unwrap_or(&0))
// To safeguard against inexact number of rows (e.g. 0) being smaller than
// an exact null count we need to do a checked subtraction.
match count.checked_sub(*stats.null_count.get_value().unwrap_or(&0)) {
None => Precision::Inexact(0),
Some(non_null_count) => Precision::Inexact(non_null_count),
}
}
Precision::Exact(count) => {
let count = count - stats.null_count.get_value().unwrap_or(&0);
Expand Down

0 comments on commit be142d5

Please sign in to comment.