viirya commented on a change in pull request #27690:
URL: https://github.com/apache/spark/pull/27690#discussion_r446666999



##########
File path: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/SaveAsHiveFile.scala
##########
@@ -124,11 +162,25 @@ private[hive] trait SaveAsHiveFile extends 
DataWritingCommand {
     val hiveVersion = 
externalCatalog.unwrapped.asInstanceOf[HiveExternalCatalog].client.version
     val stagingDir = hadoopConf.get("hive.exec.stagingdir", ".hive-staging")
     val scratchDir = hadoopConf.get("hive.exec.scratchdir", "/tmp/hive")
+    logDebug(s"path '${path.toString}', staging dir '$stagingDir', " +
+      s"scratch dir '$scratchDir' are used")
 
     if (hiveVersionsUsingOldExternalTempPath.contains(hiveVersion)) {
       oldVersionExternalTempPath(path, hadoopConf, scratchDir)
     } else if (hiveVersionsUsingNewExternalTempPath.contains(hiveVersion)) {
-      newVersionExternalTempPath(path, hadoopConf, stagingDir)
+      // HIVE-14270: Write temporary data to HDFS when doing inserts on tables 
located on S3

Review comment:
       We should use Spark jira instead of HIVE-14270.

##########
File path: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/SaveAsHiveFile.scala
##########
@@ -97,12 +99,46 @@ private[hive] trait SaveAsHiveFile extends 
DataWritingCommand {
       options = Map.empty)
   }
 
-  protected def getExternalTmpPath(
+  // Mostly copied from Context.java#getMRTmpPath of Hive 2.3.
+  // Visible for testing.
+  private[execution] def getNonBlobTmpPath(
+      hadoopConf: Configuration,
+      sessionScratchDir: String,
+      scratchDir: String): Path = {
+
+    // Hive's getMRTmpPath uses nonLocalScratchPath + '-mr-10000',
+    // which is ruled by 'hive.exec.scratchdir' including file system.
+    // This is the same as Spark's #oldVersionExternalTempPath.
+    // Only difference between #oldVersionExternalTempPath and Hive 2.3.0's is 
HIVE-7090.
+    // HIVE-7090 added user_name/session_id on top of 'hive.exec.scratchdir'
+    // Here it uses session_path unless it's emtpy, otherwise uses scratchDir.
+    val sessionPath = if (!sessionScratchDir.isEmpty) sessionScratchDir else 
scratchDir
+    val mrScratchDir = oldVersionExternalTempPath(new Path(sessionPath), 
hadoopConf, sessionPath)
+    logDebug(s"MR scratch dir '$mrScratchDir/-mr-10000' is used")
+    val path = new Path(mrScratchDir, "-mr-10000")
+    val scheme = Option(path.toUri.getScheme).getOrElse("")
+    if (schema == "file") {
+      logWarning(s"Temporary data will be written into a local disk " +

Review comment:
       If `file` doesn't work, why we just log warning instead of throwing 
exception?




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to