voonhous opened a new pull request, #21091:
URL: https://github.com/apache/hudi/pull/21091
### Describe the issue this Pull Request addresses
Closes #18754. Closes #18755.
Supersedes #18792: it predates the rewritten data skipping read path and no
longer applies, and its encoding (null min / max with a null count of 0) drops
files for `IS NULL` and needs a new read-side rule in every engine.
`ParquetUtils#readColumnStatsFromMetadata` turns two cases where Parquet
gives no usable statistics for a column chunk into statistics that data
skipping trusts:
- A FLOAT / DOUBLE chunk holding NaN. Parquet writes NaN as the max, and its
reader drops the min / max, leaving them at their stubbed 0.0. Hudi recorded
min = max = 0.0, so `d > 250` dropped a file whose rows are 300.0 and NaN.
- A chunk whose min and max reach 4 KB together, for example one string over
4 KB. Parquet writes no statistics at all, null count included. Hudi took the
missing null count as "every value is null" (null count = value count), so `s =
'Y'` dropped the file.
Partition stats aggregate these file ranges, so they prune the whole
partition as well.
### Summary and Changelog
- `HoodieColumnRangeMetadata#createWithoutStats` / `#hasStats`: the range of
a column a file holds no statistics for has no min / max and an unknown null
count. Its column stats and partition stats records store a null null count.
The Spark (`SparkBaseIndexSupport#buildCandidateFilter`, `Verdict` for `IS
NULL` / `IS NOT NULL`) and Flink (`ColumnStatsProbe#test`) readers already take
a null null count as missing statistics, so they keep the file for every
predicate, `IS NULL` included. No read-side change is needed there.
- `ParquetUtils`: a chunk with no null count, or with no min / max while
holding a non-null value, yields a range without statistics. Min / max are only
read when the chunk holds a non-null value, so an all-null numeric chunk
records null bounds instead of 0 / 0.
- Merging (`HoodieColumnRangeMetadata#merge` for row groups and partitions,
`HoodieTableMetadataUtil#mergeColumnStatsRecords` in the metadata table) keeps
a range without statistics on either side unknown, rather than letting the
other side's bounds stand for both. `convertMetadataToPartitionStatsRecords`
already leaves out negative counts, so a partition holding such a file gets no
partition stats for the column. `fromColumnStats` reads a null null count back
as unknown.
- Stats built from records (MOR log blocks below table version 10) and from
in-memory writer footers (native and Flink Parquet log blocks) keep NaN as the
max, which matches Spark ordering NaN above every double. They are unchanged.
- Trino: `HudiColumnStatsIndexSupport#getDomainFromColumnStats` and
`TableMetadataReader` treat a null null count as missing statistics instead of
failing with a NullPointerException.
- Spark `show_metadata_table_column_stats` procedure: returns a null
`null_number` for a file without statistics for the column instead of failing
with a NullPointerException.
- Column stats records without min / max but with a null count below the
value count, as writers stored for chunks Parquet gives no min / max for (for
example INT96 with its undefined sort order, or legacy binary statistics
Parquet drops as corrupt), are read as missing statistics:
`HoodieColumnRangeMetadata#fromColumnStats` / `#hasUnknownValues`,
`HoodieTableMetadataUtil#mergeColumnStatsRecords`, Spark
`ColumnStatsIndexSupport#transpose`, Flink
`FileStatsIndex#transposeColumnStatsIndex` and Trino
`HudiColumnStatsIndexSupport#getDomainFromColumnStats`. Such a record
identifies itself, so this needs no table config and also covers records
written before this change.
- Column stats and partition stats that writers below table version 10
stored for such files look valid, so readers trust the indexes of a table only
from version 10 on:
- `NineToTenUpgradeHandler`: when the column stats index covers a FLOAT,
DOUBLE, string or binary column (the columns of its index definition, or the
ones the write config selects; meta columns do not count), the upgrade drops
the column_stats and partition_stats partitions, their table config state and
index definitions. The next write with the indexes enabled builds them again
from all latest files (Flink: when the coordinator starts). An index covering
only other columns is kept.
- `TenToNineDowngradeHandler`: drops both indexes, since version 9 writers
cannot read a null null count. A writer that still enables them rebuilds them.
- Readers of a table below version 10 (Spark
`ColumnStatsIndexSupport#computeCandidateFileNames` /
`PartitionStatsIndexSupport#prunePartitions`, Flink
`FileStatsIndex#transposeColumnStatsIndex`, Trino `HudiColumnStatsIndexSupport`
/ `HudiPartitionStatsIndexSupport`) leave out the column stats and partition
stats of FLOAT, DOUBLE, string and binary columns, so files and partitions are
kept for predicates on them; other columns still prune. Spark takes these
columns as not indexed, so `loadTransposed` still returns the stored records.
- Logs: the upgrade and downgrade log which indexes they drop or keep and
why; readers log one WARN per index and query naming the table and the ignored
columns.
- Tests:
- Unit tests for `ParquetUtils` (NaN in DOUBLE and FLOAT, all-NaN, strings
at and over the 4 KB limit, INT96 with its undefined sort order, null-only
chunks), `HoodieColumnRangeMetadata`, `mergeColumnStatsRecords`, partition
stats, and NaN in record-based stats.
- `TestDataSkippingWithUnreliableColStats` (functional, strict data
skipping failure mode): NaN in base files for COW and MOR, NaN in MOR log files
at table versions 9 and 10, and a 4 KB string with `=`, `IN`, range, `LIKE`,
`IS NULL` and `IS NOT NULL`. Each query is compared with and without data
skipping, in memory and on the engine, the files with statistics are checked to
still be pruned, and the partition stats records are checked.
- A Flink `FileStatsIndex` test (the file without statistics is kept, a
bounded one is pruned), Trino tests for `getDomainFromColumnStats` (no
statistics, all null, bounded with and without nulls) and
`TableMetadataReader`, and a `show_metadata_table_column_stats` test.
- Every new end-to-end case fails on master: for example `d > 250` returns
no rows with data skipping instead of 8, and `s = 'Y'` returns none instead of
2.
- Table versions:
`TestDataSkippingWithUnreliableColStats#testStatsOfOlderWritersBelowTableVersion10`
stores the stats older writers stored for a NaN file and a long string file in
a version 9 table: queries return the same rows with data skipping (strict
mode) as without while an INT column still prunes; the next write upgrades the
table, rebuilds both indexes, and DOUBLE and string predicates prune again.
`#testNoStatsAtTableVersion9` checks a write at version 9 stores the same
no-stats records as one at version 10. `TestNineToTenUpgradeHandler` (indexes
dropped for a DOUBLE or STRING column, kept for INT / LONG and meta columns),
`TestTenToNineDowngradeHandler`, Flink
`TestColumnStatsIndex#testCandidateFilesByTableVersion`, Trino
`testUnreliableStatsColumnsByTableVersion` and Spark
`TestColumnStatsIndexSupport#testTypesWithUnreliableStats`.
- Null bounds for non-null values:
`TestHoodieColumnRangeMetadata#testColumnStatsRecordWithNullBoundsForNonNullValues`,
`TestHoodieTableMetadataUtil#testMergeColumnStatsRecordsWithNullBoundsForNonNullValues`,
`TestDataSkippingWithUnreliableColStats#testNullBoundsForNonNullValues`
(stores such a record for a DOUBLE column of one file: queries return the same
rows as without data skipping, the file is kept and the others are still
pruned), Flink
`TestColumnStatsIndex#testCandidateFilesWithNullBoundsForNonNullValues`, and
Trino `getDomainFromColumnStats` cases. Each fails without the read-side rule.
### Impact
Queries on tables with NaN in a FLOAT / DOUBLE column, or with a string
column holding values over about 4 KB, return the rows that data skipping used
to drop. Such files lose data skipping on that column only; other columns still
prune them. The fix applies to every table version written by this release.
Existing tables: column stats and partition stats that older writers stored
for the affected files (min = max = 0.0 for a file holding NaN, every value
null for a file holding an oversized string) look valid. Three cases:
- New tables (version 10) are fixed.
- Tables upgraded from version 9 to 10: if the column stats index covers a
FLOAT, DOUBLE, string or binary column, the upgrade drops column_stats and
partition_stats and the first write after it rebuilds them, at the cost of
reading the footers of every latest file. Otherwise they are left alone. With
async indexing (`hoodie.metadata.index.async=true`), the indexes have to be
built again with the indexer.
- Tables kept at version 9 or below by a 1.3.0 writer stay correct without a
rebuild: readers ignore the column stats and partition stats of FLOAT, DOUBLE,
string and binary columns, with a warning, until the table is upgraded. Data
skipping on other columns is unchanged. A 1.2.x or older writer on such a table
that 1.3.0 also wrote fails partition stats updates with a
NullPointerException, from unboxing a null null count in
`HoodieColumnRangeMetadata#fromColumnStats`.
Downgrading from 10 to 9 drops both indexes, so a version 9 writer never
reads a null null count; it rebuilds them with its own writer if they are still
enabled.
Records with null min / max but fewer nulls than values are recognized and
ignored automatically, on every table version.
Release note: Column stats and partition stats no longer drop rows for FLOAT
/ DOUBLE columns holding NaN or string / binary columns holding values of about
4 KB (#18754, #18755). Upgrading a table to version 10 rebuilds these indexes
on the first write when they cover such columns. Tables that stay at version 9
or below keep returning correct results but do not use these indexes for FLOAT,
DOUBLE, string and binary columns until they are upgraded.
### Risk Level
medium
The write side changes for every Parquet column chunk without usable
statistics; such chunks were wrong before, and all-null numeric chunks now
record null bounds instead of 0 / 0, which only lets data skipping prune them
for value predicates as it already does for other all-null columns.
### Documentation Update
none
### Contributor's checklist
- [x] Read through [contributor's
guide](https://hudi.apache.org/contribute/how-to-contribute)
- [x] Enough context is provided in the sections above
- [x] Adequate tests were added if applicable
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]