turboFei commented on a change in pull request #25863: 
[WIP][SPARK-29037][CORE][SQL] For static partition overwrite, spark may give 
duplicate result.
URL: https://github.com/apache/spark/pull/25863#discussion_r327997706
 
 

 ##########
 File path: 
core/src/main/scala/org/apache/spark/internal/io/FileCommitProtocol.scala
 ##########
 @@ -169,4 +183,55 @@ object FileCommitProtocol extends Logging {
         ctor.newInstance(jobId, outputPath)
     }
   }
+
+  /**
+   * Invoke a method from the Class of instance or from its superclasses.
+   */
+  private def invokeMethod(
+      instance: Any,
+      methodName: String,
+      argTypes: Seq[Class[_]],
+      params: Seq[AnyRef]): Any = {
+    var clazz: Class[_ <: Any] = instance.getClass
+    while (clazz != null) {
+      try {
+        val method = clazz.getDeclaredMethod(methodName, argTypes: _*)
+        method.setAccessible(true)
+        val r = method.invoke(instance, params: _*)
+        method.setAccessible(false)
+        return r
+      } catch {
+        case _: NoSuchMethodException =>
+          logDebug(s"Can not get $methodName method from $clazz, try to get 
from its superclass:" +
+            s" ${clazz.getSuperclass}")
+          clazz = clazz.getSuperclass
+      }
+    }
+    throw new NoSuchMethodException(s"Can not get $methodName method from 
${instance.getClass}" +
+      s" and its superclasses")
+  }
+
+  /**
+   * Invoke the `mergePaths` method of a FileOutputCommitter instance.
+   */
+  @throws[IOException]
+  def mergePaths(
+      committer: FileOutputCommitter,
+      fs: FileSystem,
+      from: FileStatus,
+      to: Path,
+      context: JobContext): Unit = {
+    try {
+      invokeMethod(committer, "mergePaths", Seq(classOf[FileSystem], 
classOf[FileStatus],
+        classOf[Path]),
+        Seq(fs, from, to))
 
 Review comment:
   thanks

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