[
https://issues.apache.org/jira/browse/FLINK-41635?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Gustavo de Morais updated FLINK-41635:
--------------------------------------
Description:
Part of removing unnecessary {{ChangelogNormalize}} below built-in PTFs that
skip 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.
was:
{{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.
Summary: Remove ChangelogNormalize below PTFs that skip retractions:
metadata columns (was: Drop ChangelogNormalize for metadata columns consumed
by stateless insert-only PTFs)
> Remove ChangelogNormalize below PTFs that skip 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
> skip 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)