lincoln-lil opened a new pull request, #20791:
URL: https://github.com/apache/flink/pull/20791

   ## What is the purpose of the change
   Currently SinkUpsertMaterializer only update row by comparing the complete 
row in anycase, but this may cause wrong result if input has upsertKey and also 
non-deterministic column values, see such a case:
   
   ```java
   @Test
   public void testCdcWithNonDeterministicFuncSinkWithDifferentPk() {
   tEnv.createTemporaryFunction(
   "ndFunc", new JavaUserDefinedScalarFunctions.NonDeterministicUdf());
   
   String cdcDdl =
   "CREATE TABLE users (\n"
   + " user_id STRING,\n"
   + " user_name STRING,\n"
   + " email STRING,\n"
   + " balance DECIMAL(18,2),\n"
   + " primary key (user_id) not enforced\n"
   + ") WITH (\n"
   + " 'connector' = 'values',\n"
   + " 'changelog-mode' = 'I,UA,UB,D'\n"
   + ")";
   
   String sinkTableDdl =
   "CREATE TABLE sink (\n"
   + " user_id STRING,\n"
   + " user_name STRING,\n"
   + " email STRING,\n"
   + " balance DECIMAL(18,2),\n"
   + " PRIMARY KEY(email) NOT ENFORCED\n"
   + ") WITH(\n"
   + " 'connector' = 'values',\n"
   + " 'sink-insert-only' = 'false'\n"
   + ")";
   tEnv.executeSql(cdcDdl);
   tEnv.executeSql(sinkTableDdl);
   
   util.verifyJsonPlan(
   "insert into sink select user_id, ndFunc(user_name), email, balance from 
users");
   }
   ```
   
   for original cdc source records:
   
   ```gittext
   +I[user1, Tom, [email protected], 10.02],
   -D[user1, Tom, [email protected], 10.02],
   ```
   
   the above query cannot correctly delete the former insertion row because of 
the non-deterministic column value 'ndFunc(user_name)'
   
   this canbe solved by letting the SinkUpsertMaterializer be aware of input 
upsertKey and update by it. This pr aims to address it.
   
   ## Brief change log
   * Add projectRowType to RowTypeUtils and deprecate 
AggCodeGenHelper#projectRowType
   * Move non-deterministic test functions to userDefinedScalarFunctions
   * Add upsertKey info for SinkUpsertMaterializer and do update via upsertKey 
if has one (if no upsertKey,  code path keeps unchanged)
   
   ## Verifying this change
   add more related ut & it
   
   ## Does this pull request potentially affect one of the following parts:
     - Dependencies (does it add or upgrade a dependency): (no)
     - The public API, i.e., is any changed class annotated with 
@Public(Evolving): (no)
     - The serializers: (no )
     - The runtime per-record code paths (performance sensitive): (no)
     - Anything that affects deployment or recovery: JobManager (and its 
components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (no)
     - The S3 file system connector: (no)
   
   ## Documentation
     - Does this pull request introduce a new feature? (no)
   
   


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