advancedxy commented on a change in pull request #25863: 
[SPARK-28945][SPARK-29037][CORE][SQL] Fix the issue that spark gives duplicate 
result and support concurrent file source write operations write to different 
partitions in the same table.
URL: https://github.com/apache/spark/pull/25863#discussion_r329335222
 
 

 ##########
 File path: 
core/src/main/scala/org/apache/spark/internal/io/FileCommitProtocol.scala
 ##########
 @@ -169,4 +171,84 @@ object FileCommitProtocol extends Logging {
         ctor.newInstance(jobId, outputPath)
     }
   }
+
+  /**
+   * Instantiates a FileCommitProtocol with file source write description.
+   */
+  def instantiate(
+      className: String,
+      jobId: String,
+      outputPath: String,
+      dynamicPartitionOverwrite: Boolean,
+      fileSourceWriteDesc: Option[FileSourceWriteDesc]): FileCommitProtocol = {
+
+    logDebug(s"Creating committer $className; job $jobId; output=$outputPath;" 
+
+      s" dynamic=$dynamicPartitionOverwrite; fileSourceWriteDesc= 
$fileSourceWriteDesc")
+    val clazz = Utils.classForName[FileCommitProtocol](className)
+    // First try the constructor with arguments (jobId: String, outputPath: 
String,
+    // dynamicPartitionOverwrite: Boolean, fileSourceWriteDesc: 
Option[FileSourceWriteDesc]).
+    // If that doesn't exist, try to invoke 
`FileCommitProtocol.instance(className,
+    // JobId, outputPath, dynamicPartitionOverwrite)`.
+    try {
+      val ctor = clazz.getDeclaredConstructor(classOf[String], 
classOf[String], classOf[Boolean],
+        classOf[Option[FileSourceWriteDesc]])
+      logDebug("Using (String, String, Boolean, FileSourceWriteDesc) 
constructor")
+      ctor.newInstance(jobId, outputPath, 
dynamicPartitionOverwrite.asInstanceOf[java.lang.Boolean],
+        fileSourceWriteDesc)
+    } catch {
+      case _: NoSuchMethodException =>
+        logDebug("Falling back to invoke instance(className, JobId, 
outputPath," +
+          " dynamicPartitionOverwrite)")
+        instantiate(className, jobId, outputPath, dynamicPartitionOverwrite)
+    }
+  }
 
 Review comment:
   Kind of, but I think we can also add `dynamicPartitionOverwrite` to 
`fileSourceWriteDesc`.
   
   For user defined `FileCommitProtocol` class, We can extract 
`fileSourceWriteDesc` and pass it to the old instantiate method.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

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

Reply via email to