You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "xuyangzhong (via GitHub)" <gi...@apache.org> on 2025/01/03 11:47:28 UTC

[PR] [FLINK-36998][table-planner] Set +I to data when restoring in values KeyedUpsertingSinkFunction [flink]

xuyangzhong opened a new pull request, #25892:
URL: https://github.com/apache/flink/pull/25892

   ## What is the purpose of the change
   
   *Set +I to data when restoring in values KeyedUpsertingSinkFunction*
   
   
   ## Brief change log
   
     - *Set +I to data when restoring in values KeyedUpsertingSinkFunction*
     - *Add tests*
   
   ## Verifying this change
   
   This change has added tests.
   
   ## 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
     - If yes, how is the feature documented? 
   


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-36998][table-planner] Keep same behavior about the RowKind of data in globalUpsertResult for KeyedUpsertingSinkFunction while being inserted or being restored [flink]

Posted by "xuyangzhong (via GitHub)" <gi...@apache.org>.
xuyangzhong commented on code in PR #25892:
URL: https://github.com/apache/flink/pull/25892#discussion_r1922021917


##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/factories/TestValuesRuntimeFunctions.java:
##########
@@ -518,13 +518,17 @@ public void initializeState(FunctionInitializationContext context) throws Except
                         .flatMap(List::stream)
                         .forEach(
                                 row -> {
-                                    boolean isDelete = row.getKind() == RowKind.DELETE;
+                                    boolean isDelete =
+                                            row.getKind() == RowKind.DELETE
+                                                    || row.getKind() == RowKind.UPDATE_BEFORE;

Review Comment:
   Actually it may happen. Because although this upsert sink 'tells' the optimizer that it can receive upsert message, sometimes optimizer will ignore its expected upsert mode and send it retract message. You can see more in FlinkChangelogModeInferenceProgram#inferSinkRequiredTraits



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-36998][table-planner] Keep same behavior about the RowKind of data in globalUpsertResult for KeyedUpsertingSinkFunction while being inserted or being restored [flink]

Posted by "xuyangzhong (via GitHub)" <gi...@apache.org>.
xuyangzhong commented on code in PR #25892:
URL: https://github.com/apache/flink/pull/25892#discussion_r1922105929


##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/runtime/stream/sql/TableSinkITCase.scala:
##########
@@ -630,4 +635,66 @@ class TableSinkITCase(mode: StateBackendMode) extends StreamingWithStateTestBase
       "+I[3, clark, 1, null, null]")
     assertThat(result.sorted).isEqualTo(expected.sorted)
   }
+
+  @TestTemplate
+  def testUpsertSinkWithFailingSource(): Unit = {
+    // enable checkpoint, we are using failing source to force have a complete checkpoint
+    // and cover restore path
+    env.enableCheckpointing(100, CheckpointingMode.EXACTLY_ONCE)
+    val configuration = new Configuration()
+    configuration.set(RestartStrategyOptions.RESTART_STRATEGY, "fixeddelay")
+    configuration.set(RestartStrategyOptions.RESTART_STRATEGY_FIXED_DELAY_ATTEMPTS, Int.box(1))
+    configuration.set(
+      RestartStrategyOptions.RESTART_STRATEGY_FIXED_DELAY_DELAY,
+      Duration.ofMillis(0))
+    env.configure(configuration, Thread.currentThread.getContextClassLoader)
+    FailingCollectionSource.reset()
+
+    val data = List(
+      changelogRow("+I", Int.box(1), "Jim"),
+      changelogRow("-U", Int.box(1), "Jim"),
+      changelogRow("+U", Int.box(1), "Ketty"),
+      changelogRow("+I", Int.box(2), "Lilith"),
+      changelogRow("-U", Int.box(2), "Lilith"),
+      // failover
+      changelogRow("+I", Int.box(3), "Sam"),
+      changelogRow("-U", Int.box(3), "Sam"),
+      changelogRow("+U", Int.box(3), "Boob"),
+      changelogRow("-D", Int.box(3), "Boob"),
+      changelogRow("+I", Int.box(4), "Julia")
+    )
+    tEnv.executeSql(s"""
+                       |CREATE TABLE pk_src (
+                       |  id int primary key not enforced,
+                       |  name string
+                       |) with (
+                       |  'connector' = 'values',
+                       |  'changelog-mode' = 'I,UA,UB,D',
+                       |  'failing-source' = 'true',
+                       |  'data-id' = '${TestValuesTableFactory.registerData(data)}'
+                       |)
+                       |""".stripMargin)
+
+    tEnv.executeSql(s"""
+                       |CREATE TABLE pk_snk (
+                       |  id int primary key not enforced,
+                       |  name string
+                       |) with (
+                       |  'connector' = 'values',
+                       |  'sink-insert-only' = 'false',
+                       |  'sink-changelog-mode-enforced' = 'I,UA,D'
+                       |)
+                       |""".stripMargin)
+
+    tEnv
+      .executeSql("""
+                    |INSERT INTO pk_snk SELECT * FROM pk_src where name <> 'unknown';
+                    |""".stripMargin)
+      .await()
+
+    val expected = List("+I[1, Ketty]", "+I[4, Julia]")

Review Comment:
   @xishuaidelin Before this fix, the result is :
   ```
   Actual   :ArrayBuffer(+I[4, Julia], +U[1, Ketty], -U[2, Lilith])
   ```



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-36998][table-planner] Keep same behavior about the RowKind of data in globalUpsertResult for KeyedUpsertingSinkFunction while being inserted or being restored [flink]

Posted by "xishuaidelin (via GitHub)" <gi...@apache.org>.
xishuaidelin commented on code in PR #25892:
URL: https://github.com/apache/flink/pull/25892#discussion_r1922008106


##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/factories/TestValuesRuntimeFunctions.java:
##########
@@ -518,13 +518,17 @@ public void initializeState(FunctionInitializationContext context) throws Except
                         .flatMap(List::stream)
                         .forEach(
                                 row -> {
-                                    boolean isDelete = row.getKind() == RowKind.DELETE;
+                                    boolean isDelete =
+                                            row.getKind() == RowKind.DELETE
+                                                    || row.getKind() == RowKind.UPDATE_BEFORE;

Review Comment:
   Nit: Do we need add UB here? IIUC, UB message will not appear here.



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-36998][table-planner] Keep same behavior about the RowKind of data in globalUpsertResult for KeyedUpsertingSinkFunction while being inserted or being restored [flink]

Posted by "xuyangzhong (via GitHub)" <gi...@apache.org>.
xuyangzhong commented on PR #25892:
URL: https://github.com/apache/flink/pull/25892#issuecomment-2642494401

   Hi, @xishuaidelin can you take a look at this pr again if you have time?


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-36998][table-planner] Keep same behavior about the RowKind of data in globalUpsertResult for KeyedUpsertingSinkFunction while being inserted or being restored [flink]

Posted by "xuyangzhong (via GitHub)" <gi...@apache.org>.
xuyangzhong commented on code in PR #25892:
URL: https://github.com/apache/flink/pull/25892#discussion_r1922104973


##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/factories/TestValuesRuntimeFunctions.java:
##########
@@ -518,13 +518,17 @@ public void initializeState(FunctionInitializationContext context) throws Except
                         .flatMap(List::stream)
                         .forEach(
                                 row -> {
-                                    boolean isDelete = row.getKind() == RowKind.DELETE;
+                                    boolean isDelete =
+                                            row.getKind() == RowKind.DELETE
+                                                    || row.getKind() == RowKind.UPDATE_BEFORE;

Review Comment:
   Added!



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-36998][table-planner] Keep same behavior about the RowKind of data in globalUpsertResult for KeyedUpsertingSinkFunction while being inserted or being restored [flink]

Posted by "MartijnVisser (via GitHub)" <gi...@apache.org>.
MartijnVisser commented on PR #25892:
URL: https://github.com/apache/flink/pull/25892#issuecomment-2642404225

   @xuyangzhong Are you still working on this PR? Because CI has failed. 
   I think @xishuaidelin had the right analysis of the problem in https://github.com/apache/flink/pull/26015#issuecomment-2601256414 - Would be good to get this test stability resolved.


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-36998][table-planner] Keep same behavior about the RowKind of data in globalUpsertResult for KeyedUpsertingSinkFunction while being inserted or being restored [flink]

Posted by "xishuaidelin (via GitHub)" <gi...@apache.org>.
xishuaidelin commented on code in PR #25892:
URL: https://github.com/apache/flink/pull/25892#discussion_r1922036544


##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/factories/TestValuesRuntimeFunctions.java:
##########
@@ -518,13 +518,17 @@ public void initializeState(FunctionInitializationContext context) throws Except
                         .flatMap(List::stream)
                         .forEach(
                                 row -> {
-                                    boolean isDelete = row.getKind() == RowKind.DELETE;
+                                    boolean isDelete =
+                                            row.getKind() == RowKind.DELETE
+                                                    || row.getKind() == RowKind.UPDATE_BEFORE;

Review Comment:
   Thanks for the explanation!Could we add a test to cover this situation? :)



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-36998][table-planner] Keep same behavior about the RowKind of data in globalUpsertResult for KeyedUpsertingSinkFunction while being inserted or being restored [flink]

Posted by "lincoln-lil (via GitHub)" <gi...@apache.org>.
lincoln-lil merged PR #25892:
URL: https://github.com/apache/flink/pull/25892


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-36998][table-planner] Set +I to data when restoring in values KeyedUpsertingSinkFunction [flink]

Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #25892:
URL: https://github.com/apache/flink/pull/25892#issuecomment-2569108750

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "094a094b63c33420696ebf9c3bbdb3d1e9957922",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "094a094b63c33420696ebf9c3bbdb3d1e9957922",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 094a094b63c33420696ebf9c3bbdb3d1e9957922 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run azure` re-run the last Azure build
   </details>


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-36998][table-planner] Keep same behavior about the RowKind of data in globalUpsertResult for KeyedUpsertingSinkFunction while being inserted or being restored [flink]

Posted by "xuyangzhong (via GitHub)" <gi...@apache.org>.
xuyangzhong commented on code in PR #25892:
URL: https://github.com/apache/flink/pull/25892#discussion_r1946286251


##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/runtime/stream/sql/TableSinkITCase.scala:
##########
@@ -630,4 +635,66 @@ class TableSinkITCase(mode: StateBackendMode) extends StreamingWithStateTestBase
       "+I[3, clark, 1, null, null]")
     assertThat(result.sorted).isEqualTo(expected.sorted)
   }
+
+  @TestTemplate
+  def testUpsertSinkWithFailingSource(): Unit = {
+    // enable checkpoint, we are using failing source to force have a complete checkpoint
+    // and cover restore path
+    env.enableCheckpointing(100, CheckpointingMode.EXACTLY_ONCE)
+    val configuration = new Configuration()
+    configuration.set(RestartStrategyOptions.RESTART_STRATEGY, "fixeddelay")
+    configuration.set(RestartStrategyOptions.RESTART_STRATEGY_FIXED_DELAY_ATTEMPTS, Int.box(1))
+    configuration.set(
+      RestartStrategyOptions.RESTART_STRATEGY_FIXED_DELAY_DELAY,
+      Duration.ofMillis(0))
+    env.configure(configuration, Thread.currentThread.getContextClassLoader)
+    FailingCollectionSource.reset()

Review Comment:
   I still recommend retaining FailingCollectionSource.reset(). Just like in other tests that utilize `FailingCollectionSource`, where it is reset in the `@BeforeEach` method to prevent interference from other tests, it should be treated the same way here.



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-36998][table-planner] Keep same behavior about the RowKind of data in globalUpsertResult for KeyedUpsertingSinkFunction while being inserted or being restored [flink]

Posted by "xishuaidelin (via GitHub)" <gi...@apache.org>.
xishuaidelin commented on code in PR #25892:
URL: https://github.com/apache/flink/pull/25892#discussion_r1922158356


##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/runtime/stream/sql/TableSinkITCase.scala:
##########
@@ -630,4 +635,66 @@ class TableSinkITCase(mode: StateBackendMode) extends StreamingWithStateTestBase
       "+I[3, clark, 1, null, null]")
     assertThat(result.sorted).isEqualTo(expected.sorted)
   }
+
+  @TestTemplate
+  def testUpsertSinkWithFailingSource(): Unit = {
+    // enable checkpoint, we are using failing source to force have a complete checkpoint
+    // and cover restore path
+    env.enableCheckpointing(100, CheckpointingMode.EXACTLY_ONCE)
+    val configuration = new Configuration()
+    configuration.set(RestartStrategyOptions.RESTART_STRATEGY, "fixeddelay")
+    configuration.set(RestartStrategyOptions.RESTART_STRATEGY_FIXED_DELAY_ATTEMPTS, Int.box(1))
+    configuration.set(
+      RestartStrategyOptions.RESTART_STRATEGY_FIXED_DELAY_DELAY,
+      Duration.ofMillis(0))
+    env.configure(configuration, Thread.currentThread.getContextClassLoader)
+    FailingCollectionSource.reset()

Review Comment:
   Nit: I commented out this part and found that it has no impact. Could you explain the specific reason for this configuration? Could we remove this? 



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org