Skip to content

Cherry pick #119712 to 26.8: Saturate an Iceberg decimal bound that cannot be widened inside its type - #125240

Merged
robot-ch-test-poll merged 9 commits into
backport/26.8/119712from
cherrypick/26.8/119712
Oct 11, 2026
Merged

robot-ch-test-poll merged 9 commits into
backport/26.8/119712from
cherrypick/26.8/119712

Conversation

@robot-clickhouse-ci-1

Copy link
Copy Markdown
Contributor

Original pull-request #119712

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

alexey-milovidov and others added 8 commits September 13, 2026 00:37
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]>
…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]>
…rate

Saturate an Iceberg decimal bound that cannot be widened inside its type
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request labels Oct 11, 2026
On 26.8 `deserializeDecimalBound` lives in `ManifestFileIterator.cpp`, not in
`IcebergFieldParseHelpers.cpp`, so apply the saturation of a widened decimal
bound there. The comment over the undecodable-bound branch does not mention
bounds of promoted columns, which the release branch does not handle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robot-ch-test-poll
robot-ch-test-poll merged commit 75c7312 into backport/26.8/119712 Oct 11, 2026
1 check passed
@robot-ch-test-poll
robot-ch-test-poll deleted the cherrypick/26.8/119712 branch October 11, 2026 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants