Skip to content

[flink] Add opt-in changelog-to-append event materialization - #10341

Open
nleigh wants to merge 5 commits into
apache:masterfrom
nleigh:u/nleigh/changelog-as-append
Open

nleigh wants to merge 5 commits into
apache:masterfrom
nleigh:u/nleigh/changelog-as-append

Conversation

@nleigh

@nleigh nleigh commented Oct 2, 2026 •

Copy link
Copy Markdown

Purpose

Some Flink SQL pipelines consume emitted changelog payloads as independent events. An aggregate update emits an old and a new payload, and downstream consumers retain and count both positively. For example, +I(value=0), -U(value=0), +U(value=1000) must become three stored append events, including two copies of value 0.

Paimon's ordinary append writer rejects retract records, filtering retracts loses required payloads, and a keyed table maintains relational state. Migrating a message-based pipeline with this event-retention requirement currently needs a custom conversion operator.

This PR adds sink.changelog-as-append, a default-off Flink SQL sink mode that stores each received INSERT, UPDATE_BEFORE, UPDATE_AFTER, and DELETE payload as an independent INSERT event.

The feature request describes the event-retention contract and the proposed SQL interface. Support opt-in changelog-to-append materialization in Flink SQL

Feedback is welcome on the SQL sink approach, physical fields versus writable metadata, and whether existing audit-log or changelog options can provide equivalent retention and conversion-time semantics.

Changes

  • Request the full changelog, including before-images and full deletes where available.
  • Deep-copy each payload before the existing append writer, preserving duplicates and protecting against object reuse. Populate configured nullable physical STRING/BIGINT fields with the original row kind and conversion-time epoch milliseconds before evaluating omitted physical generated columns. A partition expression such as LOWER(original_kind) therefore uses the stored row kind. Review discussion
  • Preserve upstream parallelism and its configured flag through materialization and generated-column evaluation, avoiding extra converters, writers and a rebalance after single-parallelism operators such as global aggregates.
  • Validate the mode for non-keyed file-store tables. Reject format tables and writes delegated to a lake-stream store at sink creation. Reject payload defaults because the append writer would replace received NULLs, and reject ignore-update-before because the mode retains before-images. Overwrite, ignore-delete, rowkind.field, key-only deletes, and direct partitioning by the metadata fields are also unsupported. Follow-up review
  • Document the SQL example, restrictions and timestamp/replay contract in the append streaming guide and generated connector option reference.

Scope and tradeoffs

The mode covers the Flink SQL table sink. DELETE and UPDATE_BEFORE become recorded data and do not remove earlier events; readers see INSERT records and can inspect the original kind field. The option is disabled by default, and the existing core append-writer guards remain in place.

Conversion time is neither source event time nor checkpoint commit time. Replay can assign new timestamps and move records to different downstream windows; timestamps are not globally ordered across subtasks. The sink preserves records delivered to it and cannot reconstruct history omitted upstream. Retaining all changes increases stored record volume compared with keyed state.

Tests

Rebased onto Apache Paimon master at f1b735b7f1. Focused Maven verify passed on Java 11 with Flink 1.20.1 and Flink 2.2.0, with 94 test cases per profile. Spotless and git diff --check passed, and the generated option reference matches the connector description.

The checkpoint recovery test commits an initial row, injects a failure after emitting uncheckpointed changes, and verifies the exact committed payloads after replay, including all four original row kinds and both identical INSERTs. It allows conversion timestamps to be reassigned. The generated-column tests cover partitioning by stored kind, deriving a column from conversion time, and filling an omitted generated metadata field. GitHub CI checks

Validation before the rebase

Local verification at f8054a0e6, based on upstream master at df43423, using Java 11:

Flink version / profile Result
1.20.1 / flink1 26 passed; zero failures, errors or skips
2.2.0 / flink2 26 passed; zero failures, errors or skips, after clean recompilation

Each run covered ChangelogAsAppendTest (5), ChangelogAsAppendSinkTest (8), ChangelogAsAppendITCase (3), ChangelogModeTest (6), the existing append-writer DELETE/UPDATE_BEFORE rejection cases (2), and FormatTableITCase#testRejectChangelogAsAppend+testDiffFormat (2). There were 52 test executions total.

Coverage includes:

  • Converter: all four kinds, equal duplicates, null payloads, nested object reuse, generated-field validation, timestamp bounds and input immutability.
  • Sink: full changelog negotiation, unchanged defaults, incompatible tables/options, generated partition fields, overwrite validation after abilities are applied, and preservation of input parallelism with either configured-flag value.
  • SQL integration: explicit four-kind input and a real aggregate generating before-images, after-images and a final delete. Tests read committed storage and assert exact payload counts, duplicate retention, original kinds, INSERT read semantics and conversion-time bounds.
  • Regressions: REST-catalog batch SQL rejects the unsupported format-table option during sink creation; normal parquet/CSV/JSON writes still succeed. A global aggregate with job parallelism four retains one converter and one writer with FORWARD edges. Default changelog negotiation and append-writer retract rejection remain covered.

The format-table rejection and parallelism tests were first run against 514da05, where they reproduced both issues fixed by f8054a0. The focused Maven runs kept Checkstyle, Spotless and Enforcer enabled; git diff --check passed.

Earlier verification at 514da05: the connector/documentation module dependency closure built successfully with -Pflink2,spark3 -pl paimon-flink/paimon-flink-common,paimon-docs -am install -DskipTests. Checkstyle, Spotless, Enforcer and license checks were enabled in local Maven build/test invocations. Generated connector documentation succeeded with -Pflink2,spark3,generate-docs -pl paimon-docs package -DskipTests; git diff --check passed.

Upstream CI passed every job at f8054a0 except Python, which was skipped. This included JDK 8 and 11, Flink 1 and Flink 2 (with the 1.16–1.20 and 2.0–2.2 modules), end-to-end tests, documentation and licensing. The Flink 1 common job (JDK 8) and the Flink 2 job (JDK 11) each ran ChangelogAsAppendTest (5), ChangelogAsAppendSinkTest (8), ChangelogAsAppendITCase (3), ChangelogModeTest (6) and FormatTableITCase (8) with no failures.

df428bf replaces the deprecated fromCollection call in ChangelogAsAppendSinkTest with StreamExecutionEnvironmentUtils.fromData, removing the only compiler warning in the changed files. The class passed locally under flink1 and flink2 (8 tests each, Java 11) with Checkstyle and Spotless enabled.

Remaining validation includes the following.

  • Streaming reads and compaction retention coverage for the agreed contract.
  • Application-specific end-to-end parity and adoption checks.

@nleigh

nleigh commented Oct 5, 2026

Copy link
Copy Markdown
Author

Hey @JingsongLi

I have this draft PR and issue 'Add opt-in changelog-to-append event materialization'
#10343

Would be great if you can review when you have a moment

Thanks!

@junmuz

junmuz commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@nleigh This looks an interesting feature. Can you rebase the branch with master and open the pull request. Thanks.

nleigh and others added 3 commits December 2, 2026 02:47
Replace the deprecated StreamExecutionEnvironment#fromCollection call with
the version-compatible StreamExecutionEnvironmentUtils.fromData helper.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@nleigh
nleigh force-pushed the u/nleigh/changelog-as-append branch from df428bf to 0c1be25 Compare December 2, 2026 10:52
@nleigh
nleigh marked this pull request as ready for review December 2, 2026 10:53
Copilot AI balanced review requested due to automatic review settings December 2, 2026 10:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Metadata is populated after generated-column evaluation, causing dependent columns to retain placeholder values and potentially route events to incorrect partitions.

1 open issue
What changed in this PR

Adds opt-in Flink SQL changelog event retention to non-keyed Paimon file-store tables, preserving updates and deletes as independent append records.

Changes:

  • Deep-copies every received payload into an INSERT with original-kind and conversion-time fields.
  • Validates incompatible settings and preserves converter parallelism.
  • Adds unit/integration coverage and documents retention and replay semantics.
File Description
paimon-flink/​paimon-flink-common/​src/​test/​java/​org/​apache/​paimon/​flink/​source/​FormatTableITCase.java Tests format-table rejection.
paimon-flink/​paimon-flink-common/​src/​test/​java/​org/​apache/​paimon/​flink/​sink/​ChangelogAsAppendTest.java Tests conversion, copying and field validation.
paimon-flink/​paimon-flink-common/​src/​test/​java/​org/​apache/​paimon/​flink/​sink/​ChangelogAsAppendSinkTest.java Tests negotiation, restrictions and parallelism.
paimon-flink/​paimon-flink-common/​src/​test/​java/​org/​apache/​paimon/​flink/​ChangelogAsAppendITCase.java Tests SQL event retention and execution topology.
paimon-flink/​paimon-flink-common/​src/​main/​java/​org/​apache/​paimon/​flink/​sink/​FlinkTableSinkBase.java Integrates conversion and validation.
paimon-flink/​paimon-flink-common/​src/​main/​java/​org/​apache/​paimon/​flink/​sink/​FlinkFormatTableSinkBase.java Rejects the mode for format tables.
paimon-flink/​paimon-flink-common/​src/​main/​java/​org/​apache/​paimon/​flink/​sink/​ChangelogAsAppend.java Implements payload copying and event metadata.
paimon-flink/​paimon-flink-common/​src/​main/​java/​org/​apache/​paimon/​flink/​FlinkConnectorOptions.java Defines three opt-in configuration options.
docs/​generated/​flink_connector_configuration.html Adds generated option reference entries.
docs/​docs/​append-table/​streaming.mdx Documents usage, restrictions and replay behavior.

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical correctness gaps let delegated sinks bypass changelog materialization and payload defaults overwrite explicit NULLs, violating event semantics and payload retention.

3 open issues
2 previously missed issues

In code that hasn't changed since last review

Medium severity Test event retention across checkpoint recovery

paimon-flink/​paimon-flink-common/​src/​main/​java/​org/​apache/​paimon/​flink/​sink/​ChangelogAsAppend.java:81

The new SQL tests use bounded inputs and never restart, so they do not exercise event retention across checkpoint recovery. Add a streaming failover test that replays all four kinds and equal payloads, then asserts committed event counts without losses or extra events while allowing replayed rows to receive new conversion timestamps.

Medium severity Reject ignore-update-before when changelog materialization is enabled

paimon-flink/​paimon-flink-common/​src/​main/​java/​org/​apache/​paimon/​flink/​sink/​FlinkTableSinkBase.java:289

With ignore-update-before=true, materialization changes before-images to INSERT before the writer's row-kind filter runs, so the configured filter silently stops working. Reject this combination alongside ignore-delete=true and add a rejection test. Update the restriction lists in FlinkConnectorOptions, the generated reference and streaming.mdx as well.

1 resolved since last review

Review effort: Max

Comment on lines +95 to +99
if (changelogAsAppend()) {
validateChangelogAsAppend();
// Event materialization needs before-images and full deletes, even if the source
// advertises an upsert changelog. Do not enable the key-only deletes capability.
return ChangelogMode.all();
if (table.partitionKeys().contains(kind) || table.partitionKeys().contains(time)) {
throw new IllegalArgumentException("Changelog metadata cannot be partition fields.");
}
new ChangelogAsAppend((RowType) toLogicalType(table.rowType()), kind, time);
createTable(
"event_log",
schema.column("emitted_ms", DataTypes.BIGINT())
.generatedColumn("kind_lower", DataTypes.STRING(), "LOWER(original_kind)")
Reject delegated lake-stream writes, payload defaults, and ignore-update-before when changelog materialization is enabled. Cover recovery with a checkpointed source that replays all row kinds and duplicate payloads. Use separate valid schemas for the generated-column regressions.
@nleigh
nleigh requested a max review from Copilot December 2, 2026 12:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants