[
https://issues.apache.org/jira/browse/FLINK-41472?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18150937#comment-18150937
]
Gustavo de Morais commented on FLINK-41472:
-------------------------------------------
Hi Vas, I gave some thought to this and here's my suggestion on how to
implement updating input thinking about the issue above.
The rule: for each PARTITION BY key, return the first or last of the key's live
rows, the same as running the query in batch on the current input table.
`sequence_by` orders different rows, never versions of the same row, since the
changelog already defines the versions.
Pick one of three implementations in `specialize()`, based on the input's
upsert keys:
1. Insert-only input: as today.
2. PARTITION BY contains an upsert key: each key has at most one live row, so
`keep` and `sequence_by` have no effect. Forward every change, with no state.
- PARTITION BY = upsert key: the input has no -U. Only if the output needs
-U, keep the current row to produce it.
- PARTITION BY = upsert key + more columns: the framework gives us -U. If
the output has no -U, emit -U as -D, since the row may have moved to another
key.
3. Any other updating input: a key can have several live rows, and the
framework gives us -U with the full old row.
- State: a `MapState` of the live rows (row -> count) plus the current row
in a `ValueState`.
- +I/+U: add the row to the map, and replace the current row if the new one
wins.
- -U/-D: remove the row from the map. Only if it was the current row, scan
the key's rows for the next one, or emit -D if none is left.
- Without `sequence_by`, a per-key arrival counter stored with each row is
the sequence, so an update counts as a new arrival.
For the docs: with one row per key, `keep` and `sequence_by` have no effect.
> Support updating input in DEDUPLICATE
> -------------------------------------
>
> Key: FLINK-41472
> URL: https://issues.apache.org/jira/browse/FLINK-41472
> Project: Flink
> Issue Type: Sub-task
> Components: Table SQL / Planner, Table SQL / Runtime
> Reporter: Gustavo de Morais
> Assignee: Vas Shabu
> Priority: Major
>
> Accept updating input when the PARTITION BY columns contain an upsert key of
> the input, and reject it at planning time otherwise. Handle upsert and
> retract messages: -D clears the key and is emitted, and -U/-D for a key
> without state are ignored.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)