gustavodemorais commented on code in PR #30182:
URL: https://github.com/apache/flink/pull/30182#discussion_r4772007717
##########
docs/content.zh/docs/sql/reference/queries/deduplication.md:
##########
@@ -234,6 +241,61 @@ GROUP BY window_start, window_end;
The repeated `e1` is not counted. The first copy of a row is kept even if it
arrives late, so a later window can drop it.
+#### Updating input with one row per key
+
+A CDC table with primary key `customer_id`, partitioned by its primary key:
+
+| `customers_cdc` |
+|:-------------------------|
+| `+I(c1, Berlin, 100)` |
+| `+U(c1, Munich, 120)` |
+| `+U(c1, Hamburg, 110)` |
+| `-D(c1)` |
+| `+U(c1, Bremen, 115)` |
+
+```sql
+SELECT * FROM DEDUPLICATE(
+ input => TABLE customers_cdc PARTITION BY customer_id,
+ keep => 'last',
+ sequence_by => DESCRIPTOR(lsn))
+```
+
+| Changes of the result | |
+|:-------------------------|:---------------------------|
+| `+I(c1, Berlin, 100)` | |
+| `+U(c1, Munich, 120)` | |
+| `+U(c1, Hamburg, 110)` | `sequence_by` → no effect |
+| `-D(c1, Hamburg, 110)` | full row, not only the key |
+| `+I(c1, Bremen, 115)` | no state → first record |
+
+To discard versions of a row that arrive out of order, deduplicate the change
events as an append-only table, as in [Order by a column](#order-by-a-column).
+
+#### Updating input with several rows per key
+
+Accounts with primary key `account_id`, partitioned by `customer_id`, so a
customer can have several live accounts:
+
+| `accounts` (`customer_id`, `account_id`, `balance`) |
+|:----------------------------------------------------|
+| `+I(c1, a1, 10)` |
+| `+I(c1, a2, 20)` |
+| `-D(c1, a2, 20)` |
+| `-U(c1, a1, 10)` |
+| `+U(c1, a1, 15)` |
+
+```sql
+SELECT * FROM DEDUPLICATE(
+ input => TABLE accounts PARTITION BY customer_id,
+ keep => 'last')
+```
+
+| Changes of the result | |
+|:----------------------|:-------------------------------------|
+| `+I(c1, a1, 10)` | |
+| `+U(c1, a2, 20)` | |
+| `+U(c1, a1, 10)` | `a2` deleted → falls back to `a1` |
+| `-D(c1, a1, 10)` | update of the only row → `-D`, `+I` |
+| `+I(c1, a1, 15)` | |
Review Comment:
Could we base this example on a customers CDC table partitioned by `city`? A
customer moving to another city shows the fallback through an update, and the
result reads as a table instead of change flags (same in the English copy):
````suggestion
#### Updating input with several rows per key
A CDC table `customers_cdc` with primary key `customer_id`, partitioned by
`city`, so a city can have several customers. The query returns the customer of
each city that changed last:
| `customers_cdc` (`customer_id`, `city`) |
|:----------------------------------------|
| `+I(c1, Berlin)` |
| `+I(c2, Berlin)` |
| `+U(c2, Munich)` |
| `-D(c1)` |
```sql
SELECT * FROM DEDUPLICATE(
input => TABLE customers_cdc PARTITION BY city,
keep => 'last')
```
| After | Result |
|:-----------------|:-------------------------------|
| `+I(c1, Berlin)` | `(Berlin, c1)` |
| `+I(c2, Berlin)` | `(Berlin, c2)` |
| `+U(c2, Munich)` | `(Berlin, c1)`, `(Munich, c2)` |
| `-D(c1)` | `(Munich, c2)` |
When `c2` moves to Munich, Berlin falls back to `c1`, its remaining
customer. When `c1` is deleted, Berlin has no customer left and leaves the
result.
````
--
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]