Gustavo de Morais created FLINK-41635:
-----------------------------------------

             Summary: Drop ChangelogNormalize for metadata columns consumed by 
stateless insert-only PTFs
                 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


{{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', 
'DELETE', 'DELETE'],
  produces_full_deletes => false);

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 WatermarkAssigner. 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)

Reply via email to