[ 
https://issues.apache.org/jira/browse/FLINK-41443?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18145584#comment-18145584
 ] 

Anton Borisov commented on FLINK-41443:
---------------------------------------

[~gustavodemorais],
One case it doesn't cover is when the old lookup row is gone by the time the 
update arrives:
* customers: (10, Alice), +I(1, 10) emits (1, Alice)
* customer 10 is deleted
* -U(1, 10) looks up 10 again, finds nothing and emits nothing, +U(1, 20) finds 
nothing either
* the sink keeps (1, Alice)

This also happens on master. TRY_RESOLVE fixes it when KeyedLookupJoinWrapper 
is added, e.g. for a sink without primary key, since it retracts from state. 
For an upsert sink keyed by order_id it isn't added, because only the primary 
key has to be deterministic. 
Should TRY_RESOLVE also materialize an inner lookup join in that case? Could be 
a separate ticket, but let's discuss this first.

> Inner lookup join keeps a stale row when an update moves the join key to a 
> row the lookup table doesn't have
> ------------------------------------------------------------------------------------------------------------
>
>                 Key: FLINK-41443
>                 URL: https://issues.apache.org/jira/browse/FLINK-41443
>             Project: Flink
>          Issue Type: Bug
>          Components: Table SQL / Planner, Table SQL / Runtime
>    Affects Versions: 2.3.0
>            Reporter: Anton Borisov
>            Priority: Major
>
> For an inner lookup join whose input sends updates without UPDATE_BEFORE (an 
> upsert source, or a CDC source whose UPDATE_BEFORE the planner drops because 
> the output keeps the input's upsert key), an UPDATE_AFTER that finds no match 
> emits nothing. Nothing retracts the joined row of the previous version, so it 
> stays in the sink. A later DELETE with the new join key finds no match 
> either, so the row is never removed.
> Reproducer:
> {code:sql}
> CREATE TABLE orders (order_id INT PRIMARY KEY NOT ENFORCED, customer_id INT, 
> pt AS PROCTIME())
>   WITH ('connector' = 'values', 'changelog-mode' = 'I,UB,UA,D');
> CREATE TABLE customers (id INT PRIMARY KEY NOT ENFORCED, name STRING) WITH 
> ('connector' = 'values');
> CREATE TABLE sink (order_id INT PRIMARY KEY NOT ENFORCED, name STRING)
>   WITH ('connector' = 'values', 'sink-insert-only' = 'false', 
> 'sink-changelog-mode-enforced' = 'I,UA,D');
> INSERT INTO sink SELECT o.order_id, c.name FROM orders AS o
> JOIN customers FOR SYSTEM_TIME AS OF o.pt AS c ON o.customer_id = c.id;
> {code}
> Customers: {{{}(10, Alice){}}}. Input: {{{}+I(1, 10){}}}, {{{}-U(1, 10){}}}, 
> {{{}+U(1, 20){}}}, {{{}-D(1, 20){}}}. Expected sink content: empty. Actual: 
> {{{}+I[1, Alice]{}}}. The same happens with an upsert source 
> ({{{}'changelog-mode' = 'I,UA,D'{}}}), with an async lookup, and with 
> {{{}table.optimizer.non-deterministic-update.strategy = TRY_RESOLVE{}}}. A 
> left lookup join is correct, since it emits a null padded row instead.
> This is the same class of bug that FLINK-40841, FLINK-40842 and FLINK-41066 
> fixed in the join operators, here in the lookup join, which keeps no state of 
> its input.
> An update can also stop matching when the new lookup row is dropped by a 
> filter on the lookup table, or rejected by a join condition on the looked up 
> row. FLINK-38579 only covers join conditions on non-key input columns.
> h3. Proposed fix
> Like a filter on a non-key column (FLINK-9528) and lookup join conditions on 
> non-key input columns (FLINK-38579): an inner lookup join whose join key 
> isn't contained in the input's upsert key requires UPDATE_BEFORE. This costs 
> a second lookup per update.
> Emitting a delete by key for an unmatched update was considered, but it would 
> emit deletes for rows that were never emitted, which joins don't handle 
> (FLINK-41258). See the comments.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to