Skip to content

fix(HUDI-9666): record the single-field ComplexKeyGenerator key encoding as a table property - #20200

Open
ad1happy2go wants to merge 5 commits into
apache:branch-0.xfrom
ad1happy2go:complex-keygen-encoding-branch-0x
Open

ad1happy2go wants to merge 5 commits into
apache:branch-0.xfrom
ad1happy2go:complex-keygen-encoding-branch-0x

Conversation

@ad1happy2go

@ad1happy2go ad1happy2go commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Describe the issue this Pull Request addresses

closes #20199

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.x. On branch-0.x a validation guard refuses every write to such a table by default, and with the guard disabled the writer keys records with hoodie.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 as hoodie.table.complex.keygenerator.encoding (FIELD_PREFIXED or VALUE_ONLY), deduced on the next write or upgrade from a record the most recent commit wrote (the record with the greatest _hoodie_commit_time in 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:

  • The table builder records only a declared encoding, because CREATE TABLE ... LOCATION re-initializes an existing table through it on this branch.
  • Only writing clients record the encoding (DataSourceUtils.createHoodieClient(..., true) from HoodieSparkSqlWriter, 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.encoding and hoodie.write.complex.keygen.validation.enable are updated; the new table property is documented in its config definition.

Contributor's checklist

  • Read through contributor's guide
  • Enough context is provided in the sections above
  • Adequate tests were added if applicable

…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.
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.
@hudi-bot

hudi-bot commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

CI report:

Bot commands @hudi-bot supports the following commands:
  • @hudi-bot run azure re-run the last Azure build

@ad1happy2go
ad1happy2go marked this pull request as ready for review October 29, 2026 13:36
@voonhous

voonhous commented Nov 7, 2026

Copy link
Copy Markdown
Member

Temporarily closing this PR while we debug a GitHub settings error on master (#20471); it will be reopened shortly, no action needed.

@voonhous voonhous closed this Nov 7, 2026
@voonhous voonhous reopened this Nov 7, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL PR with lines of changes > 1000

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants