Skip to content

[FLINK-41712][table] Expose PTF trait to drop retractions and enforce with FilterChangelog - #30173

Open
gustavodemorais wants to merge 2 commits into
apache:masterfrom
confluentinc:FLINK-41712
Open

gustavodemorais wants to merge 2 commits into
apache:masterfrom
confluentinc:FLINK-41712

Conversation

@gustavodemorais

Copy link
Copy Markdown
Contributor

What is the purpose of the change

Follow-up to #30123 (only the last two commits are new). PTFs that declare IGNORE_RETRACTIONS never read UPDATE_BEFORE or DELETE rows, but these rows still reach them. This PR adds a generic ChangelogFilter node that keeps only a given set of row kinds, and places it below such functions as low as possible: below Calcs and Unions, on top of sources and stateful operators. Since the planner now enforces the trait, it is exposed to user PTFs as ArgumentTrait.IGNORE_RETRACTIONS.

Brief change log

  • New ChangelogFilter node (physical, exec stream-exec-changelog-filter, runtime filter), reusable for other row-kind filtering.
  • The planner places it below IGNORE_RETRACTIONS arguments, so keyless Calcs no longer forward all-NULL tombstones and non-key filters over sources with key-only deletes (e.g. upsert-kafka) no longer need a ChangelogNormalize.
  • ArgumentTrait.IGNORE_RETRACTIONS for user PTFs (requires SUPPORT_UPDATES, cannot be combined with REQUIRE_UPDATE_BEFORE / REQUIRE_FULL_DELETE), documented in the PTF docs.

Verifying this change

Plan tests in ToAppendTest, ToChangelogTest and ProcessTableFunctionTest, semantic tests in ToAppendSemanticTests and ProcessTableFunctionSemanticTests (a user PTF that fails on any retraction), extraction tests in TypeInferenceExtractorTest, metadata tests, and a compiled-plan round trip for the new exec node.

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): no
  • The public API, i.e., is any changed class annotated with @Public(Evolving): yes, new ArgumentTrait.IGNORE_RETRACTIONS
  • The serializers: no
  • The runtime per-record code paths (performance sensitive): no
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
  • The S3 file system connector: no

Documentation

  • Does this pull request introduce a new feature? yes
  • If yes, how is the feature documented? docs (PTF docs) and JavaDocs

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Claude Code 2.1.304 (Opus 5.5)

@flinkbot

flinkbot commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

CI report:

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

@twalthr twalthr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great stuff @gustavodemorais. I left some comments but overall I'm surpottive of this addition.

ProcessTableFunction(invocation=[TO_APPEND(TABLE(#0), DEFAULT(), DEFAULT())], uid=[null], select=[name], rowType=[RecordType(VARCHAR(2147483647) name)], changelogMode=[I])
+- Calc(select=[name], changelogMode=[I,UA,PD])
+- TableSourceScan(table=[[default_catalog, default_database, upsert_source]], fields=[id, name], changelogMode=[I,UA,PD])
+- Calc(select=[name], changelogMode=[I,UA])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

check if the calc has still a partialDeleteKey set

@gustavodemorais gustavodemorais Dec 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The Calc above the ChangelogFilter receives no deletes, so it has no partial delete keys.
partialDeleteKeys is null there, which is expected, since its delete kind is NONE.

@twalthr twalthr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

for the second commit

@gustavodemorais gustavodemorais changed the title [FLINK-41712][table] Drop retractions early below PTFs that ignore retractions [FLINK-41712][table] Expose PTF trait to drop retractions and enforce with FilterChangelog Dec 2, 2026

@MartijnVisser MartijnVisser left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, I have two comments.

None
}

case normalize: StreamPhysicalChangelogNormalize if !deduplicatesChanges(normalize) =>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Without the ChangelogNormalize, an upsert repeating the last row of its key now reaches the function, so TO_CHANGELOG with only inserts and updates in op_mapping emits more rows than on master. Is that intended?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, the user wants a simples stateless conversion and we give them that 🙂 If there are duplicates, that is what he will see in his output append table.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Makes sense. Then I think a semantic test with a repeated upsert below a non-key filter should pin it; the new TO_APPEND programs also pass on master. The IGNORE_RETRACTIONS docs could mention it too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a repeated upsert to the non-key filter program with key-only deletes; it fails on master. Also mentioned it in the IGNORE_RETRACTIONS docs.

…tractions

Generated-by: Claude Code 2.1.304 (Opus 5.5)
…s are key-only

Generated-by: Claude Code 2.1.304 (Opus 5.5)
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.

4 participants