fix(datafusion): show an unreported partition statistic as NULL, not as -1 - #697
Merged
JingsongLi merged 1 commit intoAug 9, 2026
Conversation
…as -1 The three count columns and total_buckets of the $partitions system table were declared non-nullable, so a statistic the catalog never had reported to it came out as -1 and read like a measurement: the partition holds -1 rows, -1 files, -1 buckets. Reporting 0 instead would be worse, because 0 is a real measurement meaning the partition is empty. This is the same failure mode as the file-level row count fixed in apache#624 — a placeholder presented as an exact statistic — arriving through a second entrance, the catalog. So it gets the same treatment the crate already uses there: Partition gains UNKNOWN and is_known(), documenting that on the observation plane any negative value means never measured while zero is an exact zero, and saying nothing about the delta plane where a negative value is a decrement. The four columns become nullable and unknown renders as NULL. A test asserts real statistics still arrive as values before flipping the catalog to unknown, so a NULL in the second half means unknown rather than the column having stopped being populated at all.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The three count columns and
total_bucketsof the$partitionssystem table were declarednon-nullable, so a statistic the catalog never had reported to it came out as
-1and read like ameasurement: the partition holds -1 rows, -1 files, -1 buckets. Reporting
0instead would be worse,because
0is a real measurement meaning the partition is empty.This is the same failure mode as the file-level row count fixed in #624 — a placeholder presented as
an exact statistic — arriving through a second entrance, the catalog. A catalog-managed format table
registers partitions without necessarily measuring them, so an unreported statistic is the normal
case there, not an edge case.
Fix
PartitiongainsUNKNOWN,UNKNOWN_TOTAL_BUCKETSandis_known(), documenting that on theobservation plane any negative value means never measured while zero is an exact zero — and saying
nothing about the delta plane, where a negative value is a decrement to apply. That mirrors what the
crate already does for file-level counts with
DataFileMeta::ROW_COUNT_UNKNOWNandrow_count_known().The four columns become nullable and unknown renders as NULL.
Tests
spec::partition::tests::test_unknown_is_negative_and_zero_is_a_measurementpins the contract:any negative is unknown, zero and positives are measurements.
sql_context_tests::test_partitions_system_table_shows_unreported_statistics_as_nullasserts realstatistics still arrive as values before flipping the stub catalog to unknown, so a NULL in the
second half means unknown rather than the column having stopped being populated at all. It also
checks the partition is still listed — only its statistics are unknown.
Reverting the
record_countfield to non-nullable makes that test fail withColumn 'record_count' is declared as non-nullable but contains null values, so the assertion isload-bearing.
spec::partition32 passed,sql_context_tests55 passed,system_tables15 passed.