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


##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/nodes/exec/stream/DeduplicateTestPrograms.java:
##########
@@ -248,6 +250,184 @@ public class DeduplicateTestPrograms {
                                     + "keep => 'last')")
                     .build();
 
+    public static final TableTestProgram UPDATING_INPUT =
+            TableTestProgram.of(
+                            "deduplicate-updating-input",
+                            "with one live row per key, every change is 
forwarded whatever "
+                                    + "keep and sequence_by say, a key-only -D 
is emitted with the "
+                                    + "full row, a -D without state emits 
nothing, and +U without "
+                                    + "state is a first record")
+                    .setupTableSource(
+                            SourceTestStep.newBuilder("customers_cdc")
+                                    .addSchema(
+                                            "customer_id STRING PRIMARY KEY 
NOT ENFORCED",
+                                            "city STRING",
+                                            "lsn BIGINT")
+                                    .addMode(ChangelogMode.upsert())
+                                    .producedValues(
+                                            Row.ofKind(RowKind.INSERT, "c1", 
"Berlin", 100L),
+                                            Row.ofKind(RowKind.UPDATE_AFTER, 
"c1", "Munich", 120L),
+                                            Row.ofKind(RowKind.UPDATE_AFTER, 
"c1", "Hamburg", 110L),
+                                            Row.ofKind(RowKind.DELETE, "c1", 
null, null),
+                                            Row.ofKind(RowKind.DELETE, "c1", 
null, null),
+                                            Row.ofKind(RowKind.UPDATE_AFTER, 
"c1", "Bremen", 115L))
+                                    .build())
+                    .setupTableSink(
+                            SinkTestStep.newBuilder("sink")
+                                    .addSchema(
+                                            "customer_id STRING PRIMARY KEY 
NOT ENFORCED",
+                                            "city STRING",
+                                            "lsn BIGINT")
+                                    .consumedValues(
+                                            "+I[c1, Berlin, 100]",
+                                            "+U[c1, Munich, 120]",
+                                            "+U[c1, Hamburg, 110]",
+                                            "-D[c1, Hamburg, 110]",
+                                            "+I[c1, Bremen, 115]")
+                                    .build())
+                    .setupTableSink(
+                            SinkTestStep.newBuilder("sink_first")
+                                    .addSchema(
+                                            "customer_id STRING PRIMARY KEY 
NOT ENFORCED",
+                                            "city STRING",
+                                            "lsn BIGINT")
+                                    .consumedValues(
+                                            "+I[c1, Berlin, 100]",
+                                            "+U[c1, Munich, 120]",
+                                            "+U[c1, Hamburg, 110]",
+                                            "-D[c1, Hamburg, 110]",
+                                            "+I[c1, Bremen, 115]")
+                                    .build())
+                    .runSql(
+                            "INSERT INTO sink SELECT * FROM DEDUPLICATE("
+                                    + "input => TABLE customers_cdc PARTITION 
BY customer_id, "
+                                    + "keep => 'last', "
+                                    + "sequence_by => DESCRIPTOR(lsn))")
+                    .runSql(
+                            "INSERT INTO sink_first SELECT * FROM DEDUPLICATE("
+                                    + "input => TABLE customers_cdc PARTITION 
BY customer_id, "
+                                    + "keep => 'first')")
+                    .build();
+
+    public static final TableTestProgram RETRACT_INPUT =
+            TableTestProgram.of(
+                            "deduplicate-retract-input",
+                            "on retract input partitioned by its upsert key, 
an update "
+                                    + "replaces the kept row")
+                    .setupTableSource(
+                            SourceTestStep.newBuilder("customers_cdc")
+                                    .addSchema(
+                                            "customer_id STRING PRIMARY KEY 
NOT ENFORCED",
+                                            "city STRING")
+                                    .addMode(ChangelogMode.all())
+                                    .producedValues(
+                                            Row.ofKind(RowKind.INSERT, "c1", 
"Berlin"),
+                                            Row.ofKind(RowKind.UPDATE_BEFORE, 
"c1", "Berlin"),
+                                            Row.ofKind(RowKind.UPDATE_AFTER, 
"c1", "Munich"),
+                                            Row.ofKind(RowKind.DELETE, "c1", 
"Munich"))
+                                    .build())
+                    .setupTableSink(
+                            SinkTestStep.newBuilder("sink")
+                                    .addSchema(
+                                            "customer_id STRING PRIMARY KEY 
NOT ENFORCED",
+                                            "city STRING")
+                                    .consumedValues(
+                                            "+I[c1, Berlin]", "+U[c1, 
Munich]", "-D[c1, Munich]")
+                                    .build())
+                    .runSql(
+                            "INSERT INTO sink SELECT * FROM DEDUPLICATE("
+                                    + "input => TABLE customers_cdc PARTITION 
BY customer_id, "
+                                    + "keep => 'last')")
+                    .build();
+
+    public static final TableTestProgram LIVE_ROWS =

Review Comment:
   Could we add one statement with `sequence_by`? No test reaches `wins()` with 
a comparator on updating input yet. E.g. keep last by `opened_at`: `+I(c1, a1, 
10:00)`, `+I(c1, a2, 11:00)`, `+I(c1, a3, 09:00)`, `-D(c1, a2, 11:00)` gives 
`+I a1`, `+U a2`, `+U a1`. When a2 is deleted, a1 takes its place over a3, 
which arrived later but has the smallest `opened_at`.



-- 
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