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_r329340658
 
 

 ##########
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/InsertIntoHadoopFsRelationCommand.scala
 ##########
 @@ -103,103 +111,131 @@ case class InsertIntoHadoopFsRelationCommand(
     val dynamicPartitionOverwrite = enableDynamicOverwrite && mode == 
SaveMode.Overwrite &&
       staticPartitions.size < partitionColumns.length
 
+    val appId = SparkEnv.get.conf.getAppId
+    val jobId = java.util.UUID.randomUUID().toString
+
+    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,
+      jobId = jobId,
       outputPath = outputPath.toString,
-      dynamicPartitionOverwrite = dynamicPartitionOverwrite)
+      dynamicPartitionOverwrite = dynamicPartitionOverwrite,
+      fileSourceWriteDesc = Some(FileSourceWriteDesc(true, 
escapedStaticPartitionKVs)))
 
-    val doInsertion = if (mode == SaveMode.Append) {
-      true
-    } else {
-      val pathExists = fs.exists(qualifiedOutputPath)
-      (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)
+    try {
+      val doInsertion = if (mode == SaveMode.Append) {
 
 Review comment:
   we need detectConflict before delete matching partitions.
   
   Maybe we can define a flag `doDeleteMatchingPartitions` and 
   then  `if (doDeleteMatchingPartitions) deleteMatchingPartitions; if 
(doInsertion) detectConflict`.

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