Repository navigation
fix(HUDI-9666): record the single-field ComplexKeyGenerator key encoding as a table property - #20200
Open
ad1happy2go wants to merge 5 commits into
Open
ad1happy2go wants to merge 5 commits into
ad1happy2go wants to merge 5 commits into
Conversation
…ing as a table property For a ComplexKeyGenerator with one record key field, _hoodie_record_key is `field:value` when written by 0.14.0 and older and the bare `value` when written by 0.14.1, 0.15.0 and 1.0.0 to 1.0.2. On this branch a validation guard refuses every such write by default, and with the guard disabled the writer keys records with hoodie.write.complex.keygen.new.encoding (default `field:value`), so every upsert into a table written by 0.14.1 inserts duplicates. Port of apache#19304 to branch-0.x: - New table property hoodie.table.complex.keygenerator.encoding (FIELD_PREFIXED | VALUE_ONLY). A table without it records it on its next write or upgrade, deduced from the record key stored in its most recent data file; a table without data records the encoding the writer keys with. Once recorded it decides how every key generator keys records. - The blanket validation guard is replaced by a check that a write keying records runs against a recorded encoding and keys with it; a writer configured otherwise is refused instead of writing duplicates. - The Spark datasource and Spark SQL record the encoding when they create a writing client and put it on its config; the streamer does so before it keys records; the Java and Flink clients record it from the table's data. Table service and DDL clients do not record it. - The table builder records only a declared encoding, since CREATE TABLE on an existing location re-initializes an existing table through it. - Flink jobs take the table's recorded encoding into the job configuration. apache#20063 does not apply here: this branch has table versions up to 6 and timeline layout 1 only.
A commit that packs inserts into an existing small file rewrites the file with its older records first, keyed the way their writer keyed them, so the first record of the newest commit's file can carry another writer's encoding. Read the record with the greatest _hoodie_commit_time in a base file, stopping at one the inspected commit wrote, and in a log file the data block that commit appended.
Open
3 tasks done
Clustering and compaction rewrite records that other commits keyed, so a record they wrote does not show how the table's last writer keys records; without preserved commit metadata every clustered record even carries the clustering instant. Inspect only commits that ingested data, and read the projected meta columns by position so readers that return a plain IndexedRecord work too.
Collaborator
ad1happy2go
marked this pull request as ready for review
October 29, 2026 13:36
Member
|
Temporarily closing this PR while we debug a GitHub settings error on master (#20471); it will be reopened shortly, no action needed. |
This branch has not been deployed
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.
Describe the issue this Pull Request addresses
closes #20199
For a
ComplexKeyGeneratorwith one record key field,_hoodie_record_keyisfield:valuewhen written by 0.14.0 and older and the barevaluewhen written by 0.14.1, 0.15.0 and 1.0.x. Onbranch-0.xa validation guard refuses every write to such a table by default, and with the guard disabled the writer keys records withhoodie.write.complex.keygen.new.encoding, so every upsert into a table written by 0.14.1 inserts duplicates.Summary and Changelog
Port of #19304 to
branch-0.x. The table records its encoding ashoodie.table.complex.keygenerator.encoding(FIELD_PREFIXEDorVALUE_ONLY), deduced on the next write or upgrade from a record the most recent commit wrote (the record with the greatest_hoodie_commit_timein that commit's file, since a commit packing inserts into a small file carries older records with their own keys), skipping clustering and compaction commits, which only rewrite records other commits keyed, or taken from the writer's config for a table without data. Every key generator then keys with it, and a write whose config would key differently is refused instead of writing duplicates.Differences from master worth a look:
CREATE TABLE ... LOCATIONre-initializes an existing table through it on this branch.DataSourceUtils.createHoodieClient(..., true)fromHoodieSparkSqlWriter, the streamer, and the Java and Flink clients on table initialization); table service and DDL clients leave it alone, so a rollback cannot record the encoding of the batch it removes.#20063 does not apply: this branch has table versions up to 6 and timeline layout 1 only.
Impact
Single-field complex key generator tables written by any 0.14.x to 1.0.x release can be written again with default settings, keep their key format, and keep it across a later upgrade to a 1.x release carrying #19304. New table property
hoodie.table.complex.keygenerator.encoding; no new write config.Risk Level
medium. The change touches key generation on every write path. Tested with tables written by the actual 0.14.0 and 0.14.1 releases (Spark datasource upsert, insert, bulk insert with the row writer, delete, insert overwrite, Spark SQL
MERGE INTO), plus the Java client, Flink key generation and a cross-version upgrade of these tables to version 9 by a 1.x build.Documentation Update
Docs of
hoodie.write.complex.keygen.new.encodingandhoodie.write.complex.keygen.validation.enableare updated; the new table property is documented in its config definition.Contributor's checklist