dongjoon-hyun commented on a change in pull request #28232: 
[SPARK-31459][SQL]fix insert overwrite directory target path is an existing file
URL: https://github.com/apache/spark/pull/28232#discussion_r410597334
 
 

 ##########
 File path: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/InsertIntoHiveDirCommand.scala
 ##########
 @@ -90,6 +90,18 @@ case class InsertIntoHiveDirCommand(
         val dfs = qualifiedPath.getFileSystem(hadoopConf)
         (qualifiedPath, dfs)
       }
+
+    // SPARK-31459: If the target path already exists as a file,
+    // the last rename operation will cause only one result file to be moved,
+    // resulting in incorrect results.
+    if (fs.isFile(writeToPath)) {
+      if (overwrite) {
+        fs.delete(writeToPath, true)
 
 Review comment:
   `fs.delete` can fail if Apache Spark don't have enough privileges.

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