[
https://issues.apache.org/jira/browse/FLINK-41635?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18152776#comment-18152776
]
Gustavo de Morais commented on FLINK-41635:
-------------------------------------------
Fixed in apache/flink:master 83220c59eac956860f60c597b18901fc07a3d39b
> Remove ChangelogNormalize below PTFs that ignore retractions: metadata columns
> ------------------------------------------------------------------------------
>
> Key: FLINK-41635
> URL: https://issues.apache.org/jira/browse/FLINK-41635
> Project: Flink
> Issue Type: Improvement
> Components: Table SQL / Planner
> Reporter: Gustavo de Morais
> Assignee: Gustavo de Morais
> Priority: Major
>
> Part of removing unnecessary {{ChangelogNormalize}} below built-in PTFs that
> ignore retractions (e.g. {{TO_APPEND}}), see
> [apache/flink#30123|https://github.com/apache/flink/pull/30123].
> {{ChangelogNormalize}} is kept whenever a metadata column of an upsert source
> is read ({{ChangelogNormalizeRequirementResolver}}). Metadata describes the
> record, not the row, so without normalization a retraction would carry
> different metadata than the row it retracts, and operators that match
> retractions against earlier rows would break.
> A PTF with row semantics, no state and insert-only output never matches a
> retraction against an earlier row, and nothing downstream receives
> retractions. Still, the planner keeps a {{ChangelogNormalize}} (one row per
> key in state) below it:
> {code:sql}
> CREATE TABLE orders (
> id INT PRIMARY KEY NOT ENFORCED,
> status STRING,
> headers MAP<STRING, BYTES> METADATA
> ) WITH ('connector' = 'upsert-kafka', ...);
> SELECT * FROM TO_CHANGELOG(
> input => TABLE orders,
> op_mapping => MAP['INSERT', 'INSERT', 'UPDATE_AFTER', 'UPDATE_AFTER']);
> SELECT * FROM TO_APPEND(input => TABLE orders);
> {code}
> Without the metadata column, both queries run without {{ChangelogNormalize}}.
> We should skip the metadata check in {{FlinkChangelogModeInferenceProgram}}
> when the {{ChangelogNormalize}} feeds such a PTF, only through Calc, Exchange
> or Union. All other reasons to keep it (pushed filter, UPDATE_BEFORE,
> cdc-events-duplicate, required full deletes) stay.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)