Incremental processing in Hudi: reading only what changed, and the timestamp that betrays you
Hudi's name contains "incrementals" and it is the capability the format was built around. Here is what an incremental read actually returns, why it is not a change log, how CDC mode differs, and the instant-versus-completion-time change in Hudi 1.x that makes the obvious checkpoint loop re-read its last commit.
- The timeline is the whole mechanism
- What an incremental read returns
- The timestamp to checkpoint
- CDC mode: the actual change log
- The
hudi_table_changesfunction - How far back can you read?
- Copy-on-write and merge-on-read
- Key takeaways
- References
- Trademarks
TL;DR
- An incremental read returns the current state of records that changed in a range. It is not a change log: a record updated three times appears once, and a deleted record does not appear at all.
- CDC mode is the change log. A table given an insert, an update with a further insert, and a delete produced 5 CDC rows (three inserts, one update with
beforeandafter, one delete). An incremental read of that table returned 2 rows.- CDC must be switched on when the table is created. Asking an ordinary table for CDC fails with
It isn't a CDC hudi table; there is no retrofit.- Checkpoint the completion time. Hudi 1.x orders its timeline by completion time, and
begin.instanttimeis now a completion time, but_hoodie_commit_timestill holds the instant time. Feeding the latter back in as your next checkpoint re-reads the last commit you already processed: starting from the first commit’s instant time returned 4 rows instead of 3.- The fix is a supported one.
CALL show_commitsexposesstate_transition_time, which is the completion time, and that is what a checkpoint should store.hoodie.datasource.read.start.commitis not the config. Hudi refuses it and namesbegin.instanttimein the error.
The name Hudi stands for Hadoop Upserts Deletes and Incrementals. The incrementals are what let a downstream job ask a table what changed since a point in time and process only those records, instead of rescanning everything.
The mechanism is simple. The semantics need more care, in particular what counts as a change and which timestamp to checkpoint.
The timeline is the whole mechanism
Every write to a Hudi table produces an instant on the timeline, under
.hoodie/. An incremental read is then a filter over that timeline: give me the
records touched by instants in this range.
In Hudi 1.x the timeline files carry two timestamps, and the filename says so:
.hoodie/timeline/
20260928041728131.commit.requested
20260928041728131.inflight
20260928041728131_20260928041743271.commit <- instant _ completion
20260928041743990_20260928041748181.commit
20260928041748709_20260928041752941.commit
The first number is when the write started and the second is when it completed. That pair is a 1.x change. It lets the timeline be ordered by completion, which non-blocking concurrency needs: a writer that started earlier but finished later must not appear earlier in the ordering.
The difference between the two numbers decides how you checkpoint an incremental read.
What an incremental read returns
Three commits against a table keyed on id:
# commit 1
[(1,"a",1), (2,"b",1), (3,"c",1)] # insert
# commit 2
[(1,"a2",2), (4,"d",2)] # update id=1, insert id=4
# commit 3
[(2,"b3",3)] # update id=2
Reading incrementally from the beginning:
(spark.read.format("hudi")
.option("hoodie.datasource.query.type", "incremental")
.option("hoodie.datasource.read.begin.instanttime", <instant>)
.load(PATH))
returns the latest state of every record touched in the range, one row per record:
| id | val | _hoodie_commit_time |
|---|---|---|
| 1 | a2 |
commit 2 |
| 2 | b3 |
commit 3 |
| 4 | d |
commit 2 |
Record 1 was written twice and appears once, with its final value. There is no row describing what it used to be. A record deleted in the range does not appear at all, because there is no latest state to return.
That is the right shape for the common job, which is “re-apply the changed rows downstream”. It is the wrong shape for anything needing an audit trail, a before image, or deletes.
A record that was inserted and then deleted inside the range is absent from the result, and indistinguishable from one that never existed. CDC mode shows both events. Normal predicates apply on top of the incremental relation, so partition pruning still works.
The timestamp to checkpoint
Here is the pattern every incremental pipeline is written with: process a batch, record the last commit time you saw, use it as the start of the next run.
last = df.agg(F.max("_hoodie_commit_time")).first()[0] # checkpoint
# next run
.option("hoodie.datasource.read.begin.instanttime", last)
On Hudi 1.x that returns the last commit again, and nothing warns you.
begin.instanttime is compared against the completion time. But
_hoodie_commit_time is the instant time, the first number in the filename. A commit that started at ...728131 and completed at ...743271
is not excluded by a filter of “completion time after ...728131”, because its
completion is later than that.
Measured on the table above:
begin = commit-1 INSTANT (from _hoodie_commit_time)
[(1,'a2'), (2,'b3'), (3,'c'), (4,'d')] <- 4 rows, commit 1 included
begin = commit-1 COMPLETION (from the timeline)
[(1,'a2'), (2,'b3'), (4,'d')] <- 3 rows, commit 1 excluded
Record 3 was only ever written by commit 1, so its presence in the first result shows that commit 1 came back. A pipeline that checkpoints this way re-reads its last commit on every run.
Whether that is harmless or catastrophic depends entirely on what the downstream job does. An idempotent upsert into another Hudi table absorbs it and merely wastes work. An append into a warehouse table, or anything that increments a counter, silently double-counts.
Getting the right value
You do not have to parse filenames. show_commits exposes both times, and the
second column is the one to checkpoint:
CALL show_commits(table => 'hudidemo.incr', limit => 10);
| commit_time | state_transition_time | action |
|---|---|---|
| 20260928041748709 | 20260928041752941 | commit |
| 20260928041743990 | 20260928041748181 | commit |
| 20260928041728131 | 20260928041743271 | commit |
state_transition_time is the completion time and matches the second half of the timeline filename exactly. Store that as your checkpoint, not
_hoodie_commit_time.
On this version hoodie.datasource.read.start.commit is not the option, whatever a tutorial written against another version says. Hudi 1.1.1
rejects it and tells you which to use:
org.apache.hudi.exception.HoodieException: Specify the start completion time
to pull from using option hoodie.datasource.read.begin.instanttime
CDC mode: the actual change log
When you need before images and deletes, incremental is the wrong query type. CDC mode has its own schema, and it has to be enabled at table creation:
"hoodie.table.cdc.enabled": "true",
"hoodie.table.cdc.supplemental.logging.mode": "data_before_after"
Asking an ordinary table for CDC does not degrade gracefully:
It isn't a CDC hudi table on s3a://warehouse/hudi_incr_demo
There is no retrofit. A table that might ever need CDC has to be created with it on, which is a decision worth making deliberately rather than discovering later.
With it enabled, three commits (insert two rows, update one and insert another, delete one) produce a change log:
SELECT op, ts_ms, before, after
FROM hudi_table_changes('hudidemo.cdc', 'cdc', 'earliest');
op=i before=None after=(1,'a')
op=i before=None after=(2,'b')
op=i before=null after=(3,'c')
op=u before=(1,'a') after=(1,'a2')
op=d before=(2,'b') after=null
There is one row per change, with op naming it and both images present where they exist. The images above are abbreviated: in rows from the table’s first commit, after also carries the _hoodie_* metadata columns. The same table read incrementally returns two rows, the current state of records 1 and 3, and says nothing about the deleted record 2.
Choosing between them
Incremental (latest_state) |
CDC | |
|---|---|---|
| Returns | current value of changed records | one row per change |
| Repeated updates | collapsed to the final value | one row each |
| Deletes | invisible | op=d with the before image |
| Before image | no | yes, with data_before_after |
| Enable when | always available | table creation only |
| Storage cost | none | supplemental logging on every write |
| Good for | re-applying changes downstream, idempotently | audit, replication, anything order-sensitive |
The rule of thumb: if the downstream operation is an idempotent upsert keyed the same way, incremental is cheaper and sufficient. If you need to know that something was deleted, or what it was before, you needed CDC enabled before you started.
supplemental.logging.mode also has cheaper settings than data_before_after, which store only the keys or only the before image and so tell you less. Choose it at creation too.
The hudi_table_changes function
Both modes have a SQL surface that avoids the DataFrame options entirely:
-- current state of what changed
SELECT * FROM hudi_table_changes('db.tbl', 'latest_state', 'earliest');
-- the change log
SELECT * FROM hudi_table_changes('db.tbl', 'cdc', 'earliest');
-- bounded
SELECT * FROM hudi_table_changes('db.tbl', 'latest_state', <begin>, <end>);
'earliest' is a useful literal for the first run of a pipeline, when there is no
checkpoint yet and you want everything the timeline still holds. Which brings up
the limit on all of this.
How far back can you read?
Only as far as the timeline goes, and the timeline is deliberately bounded by two services that exist to keep it that way:
- Cleaning removes old file versions. Once the versions an instant referred to are gone, that instant cannot be served incrementally.
- Archival moves old instants out of the active timeline entirely.
An incremental checkpoint therefore expires. A pipeline that stops for longer than your retention window cannot resume from where it left off, and the honest recovery is a full re-read rather than a silently short one. This is the same retention arithmetic covered in table maintenance, seen from the reader’s side: retention policy is not only about storage, it is the bound on how long a downstream consumer may be offline.
Set the retention deliberately and alert on it. A consumer whose checkpoint has fallen outside the window has lost data it can only recover with a full re-read.
Copy-on-write and merge-on-read
Both support incremental reads and the semantics above are identical. What differs is where the changed records are read from: on copy-on-write the reader picks up new base files, on merge-on-read it must also read log files for instants not yet compacted.
The practical consequence is that on a merge-on-read table, an incremental read competes with compaction for the same state, and a read spanning a compaction boundary does more work. That is the same read-side cost described in Hudi Merge-on-Read, and it is not a correctness difference.
Incremental reads are not free. They read the files the relevant instants touched, so a range spanning many commits, or a merge-on-read table with uncompacted logs, is not obviously cheaper than a filtered snapshot scan.
Key takeaways
An incremental read returns the current value of touched records, with deletes absent and history collapsed. When that is not enough, use CDC, which you must have enabled at table creation.
Checkpoint the completion time. Hudi 1.x orders the timeline by completion, so _hoodie_commit_time is not the value begin.instanttime expects. Using it re-reads the last commit on every run without an error, and show_commits gives you the right value.
References
- Hudi incremental processing for the query types and their options
- Hudi CDC for running a CDC query
- Hudi timeline for instants, actions and states
- SQL procedures for
show_commitsand the rest of the inspection surface - The Hudi index for how a record is located in the first place
- Apache Hudi architecture for what a commit writes underneath all of this
Trademarks
Apache Hudi, Apache Spark, Apache Iceberg, Apache Hadoop, Apache and the Apache feather logo are either registered trademarks or trademarks of The Apache Software Foundation in the United States and other countries.
Found this useful?
These posts and tools are free. If one saved you an afternoon, you can buy me a coffee.
Comments
Questions, corrections and reviews are welcome. Sign in with GitHub to post; comments are stored in this site's public GitHub Discussions.