Reo-LEI commented on a change in pull request #2898:
URL: https://github.com/apache/iceberg/pull/2898#discussion_r681128531



##########
File path: flink/src/main/java/org/apache/iceberg/flink/IcebergTableSink.java
##########
@@ -59,12 +60,22 @@ public SinkRuntimeProvider getSinkRuntimeProvider(Context 
context) {
         .map(UniqueConstraint::getColumns)
         .orElseGet(ImmutableList::of);
 
-    return (DataStreamSinkProvider) dataStream -> 
FlinkSink.forRowData(dataStream)
-        .tableLoader(tableLoader)
-        .tableSchema(tableSchema)
-        .equalityFieldColumns(equalityColumns)
-        .overwrite(overwrite)
-        .build();
+    return (DataStreamSinkProvider) dataStream ->  {
+      // For CDC case in FlinkSQL, change log will be rebalanced(default 
partition strategy) distributed to Filter opr
+      // when set job default parallelism greater than 1. That will make 
change log data disorder and produce a wrong
+      // result for iceberg(e.g. +U comes before -U). Here try to specific the 
Filter opr parallelism same as it's
+      // input to keep Filter chaining it's input and avoid rebalance.
+      Transformation<?> forwardOpr = dataStream.getTransformation();
+      if (forwardOpr.getName().equals("Filter") && 
forwardOpr.getInputs().size() == 1) {
+        
forwardOpr.setParallelism(forwardOpr.getInputs().get(0).getParallelism());

Review comment:
       `Filter` parallelism different than `IcebergStreamingWriter` is possible 
and common. Here setting `Filter` parallelism as it's input is want to let 
`Filter` chain to it's Input, and keep input stream data original order. 
`writeParallelism` will setting the `IcebergStreaming` parallelism, that will 
only effect on write performance. 
   
   If `equalityFieldColumns` has been setting, that is mean data stream will be 
`keyBy` by `equalityFieldColumns` between `Filter` and 
`IcebergStreamingWriter`. If `equalityFieldColumns` is null, that will be 
`rebalance` between `Filter` and `IcebergStreamingWriter`.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to