Skip to content
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

fix null_count on compute_record_batch_statistics to report null counts across partitions #10468

Merged
merged 4 commits into from
May 17, 2024

Conversation

samuelcolvin
Copy link
Contributor

Rationale for this change

Maybe I'm missing something or being dumb, but while reading datafusion::physical_plan::common::compute_record_batch_statistics I noticed that the null_count took the value from the last partition, not the sum of all partition.

What changes are included in this PR?

  • fix compute_record_batch_statistics
  • add a test

Are these changes tested?

yes

Are there any user-facing changes?

I don't think so, perhaps some queries are now correct that were previously incorrect.


for partition in batches.iter() {
for batch in partition {
for (stat_index, col_index) in projection.iter().enumerate() {
column_statistics[stat_index].null_count =
Precision::Exact(batch.column(*col_index).null_count());
null_counts[stat_index] += batch.column(*col_index).null_count();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There would be fewer bounds checks i think if we used zip here, rather than .enumerate() and lookup each column

@alamb alamb changed the title fix null_count on compute_record_batch_statistics fix null_count on compute_record_batch_statistics to report null counts across partitions May 13, 2024
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution @samuelcolvin

Looks like a very good improvement to me

],
};

assert_eq!(actual, expected);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I verified test coverage by running this test without the code in this PR and the test fails like this


assertion `left == right` failed
  left: Statistics { num_rows: Exact(6), total_byte_size: Exact(368), column_statistics: [ColumnStatistics { null_count: Exact(1), max_value: Absent, min_value: Absent, distinct_count: Absent }] }
 right: Statistics { num_rows: Exact(6), total_byte_size: Exact(368), column_statistics: [ColumnStatistics { null_count: Exact(3), max_value: Absent, min_value: Absent, distinct_count: Absent }] }

@alamb
Copy link
Contributor

alamb commented May 14, 2024

I took the liberty of merging up from main and runnning cargo fmt to fix the CI test

@alamb alamb merged commit cfa7154 into apache:main May 17, 2024
23 checks passed
@alamb
Copy link
Contributor

alamb commented May 17, 2024

Thanks again @samuelcolvin -- sorry for the delay in merging

@samuelcolvin samuelcolvin deleted the fix-compute_record_batch_statistics branch May 19, 2024 21:00
findepi pushed a commit to findepi/datafusion that referenced this pull request Jul 16, 2024
…counts across partitions (apache#10468)

* fix null_count on compute_record_batch_statistics

* fmt

---------

Co-authored-by: Andrew Lamb <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants