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

 ##########
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/InsertIntoHadoopFsRelationCommand.scala
 ##########
 @@ -105,26 +109,39 @@ case class InsertIntoHadoopFsRelationCommand(
     val dynamicPartitionOverwrite = enableDynamicOverwrite && mode == 
SaveMode.Overwrite &&
       staticPartitions.size < partitionColumns.length
 
+    val escapedStaticPartitionKVs = partitionColumns
+      .filter(c => staticPartitions.contains(c.name))
+      .map { attr =>
+        val escapedKey = ExternalCatalogUtils.escapePathName(attr.name)
+        val escapedValue = 
ExternalCatalogUtils.escapePathName(staticPartitions.get(attr.name).get)
+        (escapedKey, escapedValue)
+      }
+
     val committer = FileCommitProtocol.instantiate(
       sparkSession.sessionState.conf.fileCommitProtocolClass,
       jobId = java.util.UUID.randomUUID().toString,
       outputPath = outputPath.toString,
-      dynamicPartitionOverwrite = dynamicPartitionOverwrite)
+      dynamicPartitionOverwrite = dynamicPartitionOverwrite,
+      fileSourceWriteDesc = Some(FileSourceWriteDesc(true, 
escapedStaticPartitionKVs)))
 
     val doInsertion = (mode, pathExists) match {
       case (SaveMode.ErrorIfExists, true) =>
         throw new AnalysisException(s"path $qualifiedOutputPath already 
exists.")
       case (SaveMode.Overwrite, true) =>
         if (ifPartitionNotExists && matchingPartitions.nonEmpty) {
           false
-        } else if (dynamicPartitionOverwrite) {
-          // For dynamic partition overwrite, do not delete partition 
directories ahead.
-          true
         } else {
-          deleteMatchingPartitions(fs, qualifiedOutputPath, 
customPartitionLocations, committer)
-          true
+          detectConflict(fs, outputPath, escapedStaticPartitionKVs)
+          if (dynamicPartitionOverwrite) {
 
 Review comment:
   detect conflict before deleteMatchingPartitions.

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