[
https://issues.apache.org/jira/browse/FLINK-41443?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18149892#comment-18149892
]
Gustavo de Morais commented on FLINK-41443:
-------------------------------------------
Hi [~aborisov], you're right that TRY_RESOLVE targets lookup joins on an
evolving table! But it doesn't include upsert pipelines. ([NDU
docs|https://nightlies.apache.org/flink/flink-docs-master/docs/concepts/sql-table-concepts/determinism/#32-non-deterministic-update-in-streaming]).
So I'd see it as an improvement: extending TRY_RESOLVE to inner lookup joins in
upsert pipelines. I'd suggest doing that in a separate ticket and keeping
FLINK-41443 focused on UPDATE_BEFORE.
Are these issues you ran into with lookup joins or theoretical issues you
wanted to fix? I haven't worked on the lookup join so this usually requires a
bit more thinking time for me to reply
> 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)