Repository navigation
fix(manifest): write spec-compliant partition-spec and schema-id headers - #1017
Merged
wgtmac merged 1 commit intoOct 15, 2026
Merged
Conversation
The manifest writers stored the full partition spec object, such as
{"fields":[],"spec-id":0}, in the `partition-spec` Avro metadata. The
spec requires only the partition fields array there. They also omitted
the separate `schema-id` metadata, which is required for v2 and later.
Add PartitionFieldsToJson to serialize only the partition fields and use
it for the manifest header in all format versions. ToJson(PartitionSpec)
keeps producing the full object for table metadata and REST requests.
Write the ID of the schema used to write the manifest as `schema-id`.
wgtmac
approved these changes
Oct 15, 2026
Member
|
Good catch. Thanks for your fix, @mavam! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1016
Root cause
ManifestEntryAdapterV{1,2,3}::Init()storedToJsonString(*partition_spec_)as thepartition-specAvro metadata. That is the general partition-spec serializer, which produces the full object ({"fields":[],"spec-id":0}). The manifest spec requires only the partition fields array ([]for an unpartitioned manifest). The spec ID already has its ownpartition-spec-identry.The adapters also never wrote the separate
schema-idmetadata. The spec makes it optional in v1 and required in v2 and later. Theschema-idinside the JSONschemavalue doesn't count as this entry.ClickHouse 26.7.1.1315 and 26.9.17.8 parse
partition-specas the array the spec describes. On these manifests, data scans fail withPoco::Bad cast exception. PyIceberg reads the old output without error, but that doesn't make the output conformant.Changes
PartitionFieldsToJson/PartitionFieldsToJsonStringtojson_serde_internal.h. They serialize only the fields array, like Java'sPartitionSpecParser.toJsonFields.ToJson(PartitionSpec)now builds itsfieldsmember with the same helper, so its output doesn't change. Table metadata, REST requests, and other callers that need the full object are unaffected.partition-specwith the new helper andschema-idfrom the schema used to write the manifest. v1 also getsschema-id: the spec allows it there, and it keeps all versions consistent.Note for reviewers: Java's
ManifestWriterdoesn't writeschema-idtoday either. This PR follows the spec table, which requires it for v2 and later.Tests
ManifestWriterHeaderTestis new and runs for format versions 1, 2, and 3. Each case writes a manifest and reads the key-value metadata back from the Avro file header withReader::Metadata(). It doesn't do a writer/reader round trip, which could accept the wrong encoding.partition-specmust be[],partition-spec-idmust be0, andschema-idmust be present and equal to0.partition-specmust be an array that keeps the order and thename,transform,source-id, andfield-idof all three fields.schema-idmust be7and match the ID in the embedded schema.JsonInternalTest.PartitionFieldsToJsonchecks the array serialization. It also checks thatToJson(PartitionSpec)still returns the full{"spec-id", "fields"}object. The existing REST test forCreateTableRequest("partition-spec":{"spec-id":0,"fields":[]}) still passes.Results (macOS arm64, Apple clang 21, Debug, vendored dependencies,
ICEBERG_BUILD_REST=ON):manifest_test --gtest_filter='*ManifestWriterHeader*'has 6 of 6 failing. Every version fails withpartition-specequal to{"fields":[],"spec-id":0}(or the full object for the partitioned case) and noschema-id.manifest_test: 216 passed, 18 skipped. The skips are existing version-dependentGTEST_SKIPs.json_serde_test: 164 passed.rest_catalog_test: 436 passed.ctest: all 19 tests passed.pre-commit runon the changed files is clean.AI disclosure
I used an AI coding assistant to draft the change and the tests. I reviewed the implementation, checked it against the spec and the Java reference writer, and ran the tests listed above myself.