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

 ##########
 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:
   You might delete the target file too early. If the path to be written is a 
directory, its files/sub-directories are untouched when `saveAsHiveFile` fails. 
But if it is a file, you delete it before actually saving the query output.  

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