Repository navigation
Support decimal types for writing in data lakes - #115832
Conversation
|
Workflow [PR], commit [54aef01] Summary: ✅
AI ReviewSummaryThis PR adds write-side support for Iceberg Findings❌ Blockers
Final Verdict❌ Request changes. LLVM Coverage ReportMeasured on commit 54aef01.
Changed lines: Changed C/C++ lines covered: 154/212 (72.64%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Object file sizes8 object files changed (+70.11 KiB total), 0 added.
737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units38 translation units recompiled, 378 s compile time in total, 38 of them have a recent master baseline. |
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]>
…pruning Co-Authored-By: Claude Fable 5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115832&sha=d6fc50fc82e88d04827d523dac76d796acdf892a&name_0=PR&name_1=Stateless%20tests%20%28amd_msan%2C%20WasmEdge%2C%20parallel%2C%202%2F3%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. |
|
#112229 is the fix in progress, open since 2026-07-28 and awaiting review rather than awaiting work. It covers the failure in your report, which is the One correction on the corroborating pull requests, because it changes what #112229 closes. The three statements of
So #114263 and #110459, two of the three you cite, are the synchronous statement. That path has no epoll timer, so the latch cannot reach it, and it is also the only one of the three carriers that has failed on master: I have no fix in progress for that synchronous half and no root cause for it yet. I can investigate it in a separate pull request if you want it tracked. |
The build failed with `readability-redundant-casting` on `deserializeDecimalBound`: `unscaled_value` already has type `NativeType`. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115832&sha=d0e193232635a4d06105487972ba49ecc2550194&name_0=PR&name_1=Build%20%28arm_tidy%29 PR: #115832 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]>
| else if (field.getType() == Field::Types::Int64 && WhichDataType(type).isDateTime64()) /// clickhouse used to write timestamp as simple long in avro | ||
| field = DecimalField<Decimal64>(field.safeGet<Int64>(), getDecimalScale(*type)); | ||
| else if (field.getType() == Field::Types::String && WhichDataType(type).isDecimal()) | ||
| field = decodePartitionDecimalByType(field.safeGet<String>(), *type); |
There was a problem hiding this comment.
This only normalizes decimal partition values in the index_value scratch copy that partition pruning uses. The underlying parsed_entry->partition_key_value still stays as the raw Avro fixed bytes, and getIdentityPartitionColumnValues later feeds that String through convertFieldToTypeOrThrow (Utils.cpp:1639). Its String -> Decimal path (convertFieldToType.cpp:132-136) parses decimal text, not Iceberg's two's-complement bytes.
A concrete trace is 1.50: the manifest stores the unscaled value 150 as 0x00 0x96, parseFromString stops at the leading NUL, and the reconstructed partition constant becomes 0.00. StorageObjectStorageSource then uses those identity-partition values to materialize projected partition columns and substitute them into PREWHERE / row-level filters, so a decimal identity partition can still return wrong values even though pruning is fixed here.
Please normalize decimal partition fields once on manifest read, or reuse decodePartitionDecimalByType in getIdentityPartitionColumnValues, and add a focused regression that projects and filters on an identity Decimal partition column.
There was a problem hiding this comment.
🕵 Checked this against master (this PR is merged now). The 1.50 -> 0.00 trace does not reproduce: for a decimal identity partition column the manifest value reaching getIdentityPartitionColumnValues is already a Decimal field, not the raw fixed bytes.
Verified under a debugger on a table written by ClickHouse and partitioned by Decimal(7, 2): at Utils.cpp:1639 the field is DB::Field::Types::Decimal32, and SELECT returns 1.50 / 2.50 / -3.25 correctly (same for Decimal(38, 10) and Decimal(50, 5), with partition pruning enabled and disabled) — the Avro reader decodes the annotated fixed for us.
That said, the two encodings the pruner does handle (String decimal bytes, and a legacy DateTime64 written as a plain long) would indeed be reconstructed incorrectly on the identity-projection path, so I factored the decoding out into Iceberg::normalizePartitionValue and used it in both places, with an integration test that reads a decimal identity-partitioned table whose data files no longer store the partition columns: #117090
|
@scanhex12 the 26.7 backport #116859 does not build. On its current head
The second error, Two ways forward. #111786 is mine and carries no backport label, and #116858, the 26.6 cherry-pick, will hit the same error, and on 26.6 #111786's source half conflicts I do not apply labels and I do not hand-resolve release-branch ports, so the choice is yours. |
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
Cherry pick #115832 to 26.6: Support decimal types for writing in data lakes
|
@scanhex12 from my research, ClickHouse Bool should map boolean in iceberg and FixedString(N) should map fixed[N] in iceberg. Are you aware of this? They are not supported I think |
Backport #115832 to 26.7: Support decimal types for writing in data lakes
The backport of ClickHouse#115832 re-imported the upstream type mapping in `getIcebergType` and, in doing so, replaced the guarded branch with the unguarded upstream one. A `Decimal` wider than the Iceberg spec limit was then silently serialized into metadata that other engines reject, instead of being refused. The guard was added to this branch in 998bb35. The Iceberg spec caps `decimal(P, S)` at precision 38, while ClickHouse `Decimal256` goes up to 76. Fixes `IcebergTypeMapping.DecimalPrecisionAboveSpecLimitIsRejected` and `IcebergTypeMapping.NullableDecimalPrecisionAboveSpecLimitIsRejected`, and the two `rejected: Decimal(39, 2)` scenarios under `export partition id` and `export part` in the Iceberg regression suite. CI report: https://altinity-build-artifacts.s3.amazonaws.com/json.html?PR=2320&sha=9091be4a6720c4cc319b24caf95601c7ed0371c2&name_0=PR&name_1=Unit%20tests%20%28asan_ubsan%29 Related: #2320
Antalya 26.6 Backport of ClickHouse#115832: Support decimal types for writing in data lakes
… in data lakes
…support Support decimal types for writing in data lakes
The test came from the backport of ClickHouse#115832 and creates a `Decimal(76, 20)` column, which this branch refuses -- the Iceberg spec caps `decimal` at precision 38. It fails on its first CREATE TABLE in every build. `Decimal256` is unreachable on the write path here, so the column goes. The refusal itself stays covered by the type-mapping gtest and by the `rejected: Decimal(39, 2)` scenarios in the regression suite. Related: ClickHouse#2320 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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 ClickHouse#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: ClickHouse#116999 Related: ClickHouse#116604 Related: ClickHouse#115832 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
An Iceberg schema was converted to ClickHouse types without checking the schema-level rules, so metadata that the Java implementation rejects was read (apache/iceberg-verification cases, issue ClickHouse#130002): - `identifier-field-ids` naming a field that does not exist, is optional, is `float`/`double`, is not primitive, or is nested in a list, a map or an optional struct (Java `Schema.validateIdentifierField`); - a list without `element-id`, a map without `key-id` or `value-id` (Java `SchemaParser.listFromJson`/`mapFromJson`); - a geo type with an empty CRS or an unknown edge interpolation algorithm: `getSimpleType` mapped every string starting with `geometry`/`geography` to `Geometry` (Java `Types.fromTypeName`, `EdgeAlgorithm.fromName`); - a table schema that is not `"type": "struct"`. `IcebergSchemaProcessor::findSchemaViolation` returns the first violation; `checkSchema` throws ICEBERG_SPECIFICATION_VIOLATION naming the field. Where it runs: - every metadata.json copy registered by `addIcebergTableSchema`, before the identical-copy fast paths: they compare only `fields`, and with the geo parser every geo type compares as `binary`, so an invalid copy of an already registered schema-id would return early unchecked; - manifest header copies get the structural rules only, at registration of a new copy: AWS S3 Tables writes header copies with only the partition source columns, whose copied `identifier-field-ids` may name absent fields, and Java takes the schema from metadata.json (`ManifestReader`); - `parseTableSchema` checks every entry of `schemas`: a table without a current snapshot registers only the current one, while Java parses all of them (`TableMetadataParser`). Writers: `ALTER` deep-copies `identifier-field-ids`, so dropping an identifier column (or the struct containing one) or making it Nullable wrote a schema that ClickHouse and Java then refuse to read; it is now refused with BAD_ARGUMENTS, like Java's `SchemaUpdate`. The REST catalog server's create-table validates the client's identifier fields the same way. `decimal(P, S)` with `P > 38` is not rejected: ClickHouse writes it on purpose (ClickHouse#115832); asked on the issue. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…anifest lists, keep wide decimals - `05616` and `05617`: change into the generated table directory and pass relative table names, because `icebergLocal` in `clickhouse local` refuses paths outside the working directory (the tests failed with `PATH_ACCESS_DENIED` with `clickhouse-test --tmp` outside the checkout). - `05617`: remap the manifest lists `s3://a/b/*.avro` of `TableMetadataV2Valid` and `TableMetadata*StatisticsFiles` into `metadata/` of the table and supply empty manifest lists, because describing a table reads the manifest list of the current snapshot. - `05616`: expect `Nullable(Decimal(39, 0))` for `decimal-precision-over-38`, because ClickHouse deliberately supports wide decimals in Iceberg (#115832). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Decimalcolumns could not be written to Iceberg tables at all:getIcebergTypeandgetAvroTypehad no case for them, soCREATE TABLEwith a decimal column failed withUnsupported type for iceberg.This adds the write side for
Decimal32,Decimal64,Decimal128andDecimal256:decimal(P, S);fixedof the minimum width that holds every value of the precision, and partition values are serialized as the unscaled value in two's-complement big-endian form, per Appendix D of the spec;lower_bounds/upper_boundsstatistics are written for decimal columns in the same encoding, and decimal partition values are decoded back on the read path so that partition pruning works on them.Decimal256is written asdecimal(P, S)with a precision above the38the Iceberg spec allows. That is deliberate: ClickHouse reads such metadata back with the same type (createDecimal<DataTypeDecimal>accepts precision up to76), and it is left to users to avoid types that other engines do not support.Two bugs found by CI on the first revision are fixed in the follow-up commits: every partition field was serialized against the Avro node of the first partition field, and decimal partition values were dispatched on the
Fieldtype, which also matchedDateTime64and turned it into afixeddecimal instead of along.Review follow-ups: the Avro
fixedname of a decimal partition field now includes the partition field id, so two partition columns of the same decimal shape no longer collide in one manifest schema; and the min/max bound deserialization handlesDecimal128andDecimal256, so the statistics written for wide decimals are actually consumable by partition pruning. Both are covered by new integration tests. A further review round found that a manifest rewrite (OPTIMIZE TABLE ... MANIFEST) feeds partition tuples read back from Avro — where a decimal is the rawfixedbytes in aStringfield — straight back into the manifest writer; both decimal serializers now accept that representation as well, covered by an integration test compacting a decimal-partitioned table.CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115832&sha=latest&name_0=PR
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Support
Decimaltypes when writing into Iceberg tables, including decimal partition columns and decimal min/max statistics.Workflow [PR]
Sync PR [sync-upstream/pr/115832]
Version info
26.9.1.240(included in26.9and later)26.8.1.2023,26.7.7.46