Skip to content

Cherry pick #115832 to 26.6: Support decimal types for writing in data lakes - #116858

Merged
robot-clickhouse-ci-2 merged 12 commits into
backport/26.6/115832from
cherrypick/26.6/115832
Aug 30, 2026
Merged

robot-clickhouse-ci-2 merged 12 commits into
backport/26.6/115832from
cherrypick/26.6/115832

Conversation

@robot-clickhouse-ci-2

Copy link
Copy Markdown
Contributor

Original pull-request #115832

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.

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

scanhex12 and others added 10 commits August 21, 2026 17:20
Two defects in the manifest writer, both reported by CI:

1. Every partition field was serialized against `leafAt(0)` of the partition
   record, so only the first partition column got its own Avro node. With a
   multi-column spec, a later `Nullable` column built its `GenericUnion` from
   the first field's schema and a later decimal column used the first field's
   `fixed` size. Restore the lookup of the field index by name.

2. Decimal partition values were dispatched on the `Field` type, but
   `DateTime64` is also kept in a `DecimalField`, so a `DateTime64` partition
   was written as a `fixed` decimal instead of a `long`. That tripped
   `Logical error: 'schema->type() == avro::AVRO_FIXED' (STID: 1288-3bd5)` in
   `04501_iceberg_datetime64_partition_pruning` and failed
   `test_writes_field_partitioning`, which partitions by nine columns
   including a `DateTime64`. Dispatch on the partition column type instead.

The `chassert` on the Avro node kind becomes a regular exception: in a release
build it was a no-op and the writer would have produced a malformed manifest.

Also, `icebergDecimalRequiredBytes` computed the width from a signed `Int256`
whose intermediate `(1 << 255) - 1` overflows, and the new decimal decoder in
`ManifestFilesPruning` silently left the value as a `String` when the byte
count did not fit the type. Both are now computed on the unsigned type and
report a malformed manifest as an error.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115832&sha=latest&name_0=PR
Related: #115832
`fixed` is a named Avro type, and the name was derived only from `(precision, scale)`,
so `PARTITION BY (price_a, price_b)` with two `Decimal(18, 4)` columns emitted two
definitions of the same name `decimal_18_4` into one manifest schema and failed
schema compilation on insert. Include the partition field id in the name.

Co-Authored-By: Claude Fable 5 <[email protected]>
The bound deserializer hard-capped decimal bounds at 8 bytes and reconstructed only
`Decimal32` and `Decimal64`, so the `lower_bounds`/`upper_bounds` the writer now
emits for wider decimals could never be turned into a `Range` and
`IcebergMinMaxIndexPrunedFiles` never fired for them. Decode through the native
type of the expected decimal, like the partition value decoding already does.

Co-Authored-By: Claude Fable 5 <[email protected]>
Address review: `OPTIMIZE TABLE ... MANIFEST` reads partition tuples back
from the source manifests, where a decimal partition value is parsed from
the Avro `fixed` as its raw bytes (a `String` field), and both rewrite
paths feed that row straight back into `generateManifestFile` (and into
the `entry_partition_summaries` of the manifest list). `makeDecimalFixedDatum`
and `dumpDecimalValue` accepted only a typed `DecimalField` there, so
compaction of any decimal-partitioned table threw on `safeGet`.

Both serializers now also accept the read-back representation: the bytes
already hold the unscaled value in two's-complement big-endian form, so
they are re-padded to the target `fixed` width (partition values) or
re-trimmed to the minimum length (partition summary bounds) instead of
being decoded and re-encoded.

Covered by `test_optimize_manifest_files_decimal_partition`, which fails
with `Bad get: has String, requested Decimal` without the fix.

Co-Authored-By: Claude Fable 5 <[email protected]>
Support decimal types for writing in data lakes
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 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 Aug 28, 2026
…ypick/26.6/115832

# Conflicts:
#	src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp
#	src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFilesPruning.cpp
#	tests/integration/test_storage_iceberg_with_spark/test_manifest_compaction.py
The 26.6 branch misses several master-only refactorings around Iceberg
writes, so the mechanical merge needed adaptation:
- `extendSchemaForPartitions` on 26.6 always assigns partition field ids
  as `1000 + i` (no `spec_has_all_ids` logic), so define `field_id`
  locally for the new `getAvroType` signature.
- Add the `DataTypes/DataTypesDecimal.h` include to `Utils.cpp` and
  `ManifestFilesPruning.cpp` (`getDecimalPrecision`, `checkDecimal`).
- Keep 26.6's pruning loop without the master-only `DateTime64` branch,
  but make it index-based to decode decimal partition values by type.
- Drop `test_manifest_compaction.py`: `OPTIMIZE TABLE ... MANIFEST` does
  not exist on 26.6, so the compaction test cannot run there.

Original PR: #115832
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