gustavodemorais commented on code in PR #30182:
URL: https://github.com/apache/flink/pull/30182#discussion_r4772098902


##########
docs/content.zh/docs/sql/reference/queries/deduplication.md:
##########
@@ -106,12 +106,19 @@ The output columns are the `PARTITION BY` columns, in the 
order listed, followed
 
 The result has one row per key. When a later row replaces the kept one, the 
row of that key is updated, so the result must be written to a table that 
accepts updates, for example one with a primary key on the `PARTITION BY` 
columns.
 
-With `keep => 'first'` and no `sequence_by`, the kept row of a key never 
changes, so the result only contains inserts and can be written to an 
append-only table.
+On append-only input with `keep => 'first'` and no `sequence_by`, the kept row 
of a key never changes, so the result only contains inserts and can be written 
to an append-only table.
 
 {{< hint info >}}
 The first record of a key is emitted as `+I`. A record that replaces the kept 
one is emitted as `+U`, preceded by `-U` if the consumer needs retractions. A 
record that equals the kept one, or does not replace it, emits nothing. See 
[Updates and Changelogs]({{< ref "docs/dev/table/functions/ptfs" 
>}}#updates-and-changelogs).
 {{< /hint >}}
 
+### Updating input
+
+On updating input, `DEDUPLICATE` returns the first or the last of the live 
rows of each key, that is, of the rows in the input table at that moment, as a 
batch query on the current table would. `sequence_by` orders different rows of 
a key, never versions of the same row, since the changelog of the input defines 
the versions.
+
+- If the `PARTITION BY` columns are an upsert key of the input, a key has at 
most one live row, so `keep` and `sequence_by` have no effect and every change 
is forwarded. A deleted row is emitted as `-D` with the full row, also if the 
input only carries its key.
+- Otherwise, a key can have several live rows, and all of them are kept in 
state. When the kept row is retracted, the best remaining row replaces it, or 
`-D` is emitted if none is left. An update of the only row of a key is emitted 
as `-D` followed by `+I`.

Review Comment:
   ```suggestion
   On updating input, such as a CDC table, `DEDUPLICATE` keeps the first or the 
last of the rows each key has right now, as a batch query on the table would.
   
   - **One row per key.** If each key has at most one row, for example when a 
CDC table is partitioned by its primary key, the result is that row. An update 
always replaces it, so `keep` and `sequence_by` don't change the result.
   - **Several rows per key.** If a key can have several rows, all of them are 
kept in state. When the kept row is deleted, the next best row takes its place. 
Without `sequence_by`, an updated row counts as a new arrival. With 
`state_ttl`, a row that hasn't changed for the TTL is forgotten and can no 
longer take the kept row's place.
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to