JingsongLi commented on a change in pull request #13789:
URL: https://github.com/apache/flink/pull/13789#discussion_r514019228



##########
File path: 
flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/plan/nodes/common/CommonPhysicalSink.scala
##########
@@ -99,11 +111,63 @@ class CommonPhysicalSink (
 
         val operator = new SinkOperator(env.clean(sinkFunction), 
rowtimeFieldIndex, enforcer)
 
+        assert(runtimeProvider.isInstanceOf[ParallelismProvider],
+              "runtimeProvider with `ParallelismProvider` implementation is 
required")
+
+        val inputParallelism = inputTransformation.getParallelism
+        val parallelism =  {
+          val parallelismOptional = runtimeProvider
+            .asInstanceOf[ParallelismProvider].getParallelism
+          if(parallelismOptional.isPresent) {
+            val parallelismPassedIn = parallelismOptional.get().intValue()
+            if(parallelismPassedIn <= 0) {
+              throw new TableException(
+                s"Table: $tableIdentifier configured sink parallelism: 
$parallelismPassedIn " +
+                  "should not be less than zero or equal to zero")
+            }
+            parallelismPassedIn
+          } else inputParallelism
+        }
+
+        val primaryKeys = 
TableSchemaUtils.getPrimaryKeyIndices(catalogTable.getSchema)
+        val theFinalInputTransformation =
+          (inputParallelism == parallelism,changelogMode, primaryKeys.toList) 
match {
+           // if the inputParallelism equals parallelism, do nothing.
+          case (true, _, _) => inputTransformation
+          case (_, _, _) if (changelogMode.containsOnly(RowKind.INSERT)) => 
inputTransformation
+          case (_, _, Nil) =>
+            throw new TableException(
+            s"Table: $tableIdentifier configured sink parallelism is: 
$parallelism, " +
+            s"while the input parallelism is: $inputParallelism. " +
+            s"Since the changelog mode " +
+            s"contains 
[${changelogMode.getContainedKinds.toList.mkString(",")}], " +
+            s"which is not INSERT_ONLY mode, " +
+            s"primary key is required but no primary key is found"
+          )
+          case (_, _, pks) =>
+            //key by before sink
+            //according to [[StreamExecExchange]]
+            val selector = KeySelectorUtil.getRowDataSelector(
+              pks.toArray, inputTypeInfo)
+            // in case of maxParallelism is negative
+            val keyGroupNum = env.getMaxParallelism match {

Review comment:
       Yes




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

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


Reply via email to