Repository navigation
Saturate an Iceberg decimal bound that cannot be widened inside its type - #119712
Conversation
Iceberg stores a decimal min/max bound rounded to the integral part, so the reader moves each bound one integral unit outwards before pruning on it. At scale 38 that unit is `10^38` and the bound lives in an `Int128`, which holds `1.7 * 10^38`, so the shift leaves the type for every bound of magnitude above roughly 0.70141. `Decimal(38, 38)` is the only width where that happens to a bound the column can hold: at the other three the largest value the precision allows plus `10^scale` still fits. Until #116604 the shift wrapped, which inverted the pair reaching `KeyCondition::mayBeTrueInRange`, pruned the data file holding the matching rows and lost them silently. That pull request rejects such a bound instead, which is correct but gives the column no min/max condition at all - and for a `Decimal(38, 38)` column that is every bound of magnitude above 0.7, so those tables lost min/max pruning altogether. A bound only has to stay on the outer side of every value in the file, and the largest magnitude the precision of the type allows is outside all of them, so it stands in for a widened bound that no longer fits. A bound that is itself outside that magnitude is one the column cannot hold: nothing vouches for the values in the file, so there is no stand-in for it and it stays unusable, which is the case `test_iceberg_inverted_decimal_manifest_bounds` pins for a `Decimal32` bound. The new test reads a `Decimal(38, 38)` column whose two data files hold `0.99` and `-0.99`: every filter on the column returns its rows, and a probe outside one of the two shifted bounds prunes that file and only it. A second table holds `0.1` and `-0.1`, where the shift stays inside `Int128` whatever the reader does with an overflow, so the two arms together say the pruning is lost to the overflow rather than to the shape of the test. Closes: #116999 Related: #116604 Related: #115832 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [6d6adc7] Summary: ✅
AI ReviewSummaryThis PR restores Iceberg min/max pruning for Findings❌ Blockers
Final VerdictChanges requested. LLVM Coverage ReportMeasured on commit 6d6adc7.
Changed lines: Changed C/C++ lines covered: 24/25 (96.00%) · Uncovered code |
Build profile diff (arm_release)Commit See the job log for details. |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
…ejecting it The overflow branch of `deserializeDecimalBound` still dropped the bound shape the compensation exists to recover. Spark and Amazon Athena round a decimal bound to the integral part, so a file whose extreme value is `0.99` carries `1.0` - `10^38` unscaled at scale 38, one unit outside what `Decimal(38, 38)` holds. `common::addOverflow` fired for it, the precision check then returned `std::nullopt`, and `ManifestFileIterator::processRow` skipped min/max pruning for the whole column again. Every value in the file fits the precision of the type it is read as, so the largest magnitude that precision allows is on the outer side of all of them: saturating to it is a valid bound and is the tightest one that does not leave the type. The widened bound is now saturated rather than rejected, which also covers a bound that is out of range before widening. Saturation is monotonic, so it cannot invert a pair that was not inverted as declared. The stateless test could not catch this, because it writes the table with ClickHouse, whose `dumpDecimalValue` serializes the exact unscaled value. It now patches the rounded form into the manifests - an uncompressed 16-byte big-endian `fixed` that both forms fill completely - and checks that the two data files still prune on the probes that sit outside them. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A lower bound above the largest value of its type (or an upper bound below the smallest) lies on the inner side of every value in the data file, so clamping it collapsed the range to a point that excludes the data and let `KeyCondition` prune a file that holds matching rows. Such a bound is not a usable range border, so `deserializeDecimalBound` rejects it again. This is the `Decimal32(9, 1)` case of `test_iceberg_inverted_decimal_manifest_bounds`. Also add the three `count` lines of section `B1` that were missing from the reference of `05210_iceberg_decimal38_bound_widening_116999`. Addresses #119712 (comment) (review thread by clickhouse-gh) Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
| /// bound is not a usable range border. | ||
| if (lower_bound) | ||
| { | ||
| if (widened_value > limit) |
There was a problem hiding this comment.
This outer-side guard is still too broad. It accepts any out-of-precision decimal bound whose widened value lands back inside [-limit, limit], not just the single writer-rounded shape this comment describes.
A concrete case is Decimal32(9, 1) with manifest bytes 1000000004 / 1000000005: deserializeDecimalBound turns them into [99999999.4, 99999999.9], ManifestFileIterator::processRow keeps that range because the declared pair is ordered, and KeyCondition can then prune a file that actually contains smaller values (for example e < toDecimal32(0.5, 1)), which brings back the silent-row-loss class on malformed manifests. The existing integration test around test_iceberg_inverted_manifest_bounds.py:441-449 is the same contract, just with a farther-out value that still takes the std::nullopt path.
I think the recoverable case has to be limited to the exact one-step-outside precision values (limit + 1 / -limit - 1), with everything else outside precision still returning std::nullopt.
|
@alexey-milovidov — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
Cherry pick #119712 to 26.8: Saturate an Iceberg decimal bound that cannot be widened inside its type
…ot be widened inside its type
Cherry pick #119712 to 26.9: Saturate an Iceberg decimal bound that cannot be widened inside its type
…ot be widened inside its type
Backport #119712 to 26.8: Saturate an Iceberg decimal bound that cannot be widened inside its type
Backport #119712 to 26.9: Saturate an Iceberg decimal bound that cannot be widened inside its type
Closes: #116999
Related: #116604
Related: #115832
Iceberg stores a decimal min/max bound rounded to the integral part, so the reader moves each bound one integral unit outwards before pruning on it. At scale 38 that unit is
10^38and the bound lives in anInt128, which holds1.7 * 10^38, so the shift leaves the type for every bound of magnitude above roughly 0.70141.Decimal(38, 38)is the only width where that happens to a bound the column can hold: at the other three the largest value the precision allows plus10^scalestill fits.Until #116604 the shift wrapped, which inverted the pair reaching
KeyCondition::mayBeTrueInRange, pruned the data file holding the matching rows and lost them silently (#116999). That pull request rejects such a bound instead, which is correct but gives the column no min/max condition at all - and for aDecimal(38, 38)column that is every bound of magnitude above 0.7, so those tables lost min/max pruning altogether.A bound only has to stay on the outer side of every value in the file, and the largest magnitude the precision of the type allows is outside all of them, so it stands in for a widened bound that no longer fits. A bound that is itself outside that magnitude is one the column cannot hold: nothing vouches for the values in the file, so there is no stand-in for it and it stays unusable, which is the case
test_iceberg_inverted_decimal_manifest_boundspins for aDecimal32bound.The new stateless test reads a
Decimal(38, 38)column whose two data files hold0.99and-0.99: every filter on the column returns its rows, and a probe outside one of the two shifted bounds prunes that file and only it. A second table holds0.1and-0.1, where the shift stays insideInt128whatever the reader does with an overflow, so the two arms together say the pruning is lost to the overflow rather than to the shape of the test. Onmasterthe test fails on the twoDecimal(38, 38)pruning arms only (0pruned files instead of1), and it passes with this change.Note on released versions: the silent row loss that #116999 reports is fixed on
masterby #116604, but that fix is not in any release branch, while the change that introduced the overflow (#115832) was backported to 26.8 by #116860 and shipped inv26.8.1.2041-ltsandv26.8.2.7-lts. Those releases still lose rows on a filter over aDecimal(38, 38)Iceberg column; that needs a backport of #116604 and is not addressed here.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Restore min/max pruning of Iceberg data files for a
Decimal(38, 38)column. A manifest bound of magnitude above roughly 0.7 cannot be widened insideInt128and was dropped, which left the column without a min/max condition; it is now saturated at the largest magnitude the precision allows, which is still outside every value the file can hold.Documentation entry for user-facing changes
Workflow [PR]
Sync PR [sync-upstream/pr/119712]
Version info
26.10.1.860-master(included in26.10and later)26.9.17.3,26.8.25.5