@@ -19,12 +19,14 @@ package org.apache.spark.sql.hive
1919
2020import java .io .File
2121
22- import org .scalatest .BeforeAndAfter
22+ import org .apache .hadoop .fs .Path
23+ import org .scalatest .{BeforeAndAfter , PrivateMethodTester }
2324
2425import org .apache .spark .SparkException
2526import org .apache .spark .sql .{QueryTest , _ }
2627import org .apache .spark .sql .catalyst .parser .ParseException
2728import org .apache .spark .sql .catalyst .plans .logical .InsertIntoTable
29+ import org .apache .spark .sql .hive .execution .InsertIntoHiveTable
2830import org .apache .spark .sql .hive .test .TestHiveSingleton
2931import org .apache .spark .sql .internal .SQLConf
3032import org .apache .spark .sql .test .SQLTestUtils
@@ -36,7 +38,7 @@ case class TestData(key: Int, value: String)
3638case class ThreeCloumntable (key : Int , value : String , key1 : String )
3739
3840class InsertSuite extends QueryTest with TestHiveSingleton with BeforeAndAfter
39- with SQLTestUtils {
41+ with SQLTestUtils with PrivateMethodTester {
4042 import spark .implicits ._
4143
4244 override lazy val testData = spark.sparkContext.parallelize(
@@ -550,6 +552,32 @@ class InsertSuite extends QueryTest with TestHiveSingleton with BeforeAndAfter
550552 }
551553 }
552554
555+ test(" SPARK-27552: hive.exec.stagingdir is invalid on Windows OS" ) {
556+ val conf = spark.sessionState.newHadoopConf()
557+ val inputPath = new Path (" /tmp/b/c" )
558+ var stagingDir = " tmp/b"
559+ val saveHiveFile = InsertIntoHiveTable (null , Map .empty, null , false , false , null )
560+ val getStagingDir = PrivateMethod [Path ](' getStagingDir )
561+ var path = saveHiveFile invokePrivate getStagingDir(inputPath, conf, stagingDir)
562+ assert(path.toString.indexOf(" /tmp/b_hive_" ) != - 1 )
563+
564+ stagingDir = " tmp/b/c"
565+ path = saveHiveFile invokePrivate getStagingDir(inputPath, conf, stagingDir)
566+ assert(path.toString.indexOf(" /tmp/b/c/.hive-staging_hive_" ) != - 1 )
567+
568+ stagingDir = " d/e"
569+ path = saveHiveFile invokePrivate getStagingDir(inputPath, conf, stagingDir)
570+ assert(path.toString.indexOf(" /tmp/b/c/.hive-staging_hive_" ) != - 1 )
571+
572+ stagingDir = " .d/e"
573+ path = saveHiveFile invokePrivate getStagingDir(inputPath, conf, stagingDir)
574+ assert(path.toString.indexOf(" /tmp/b/c/.d/e_hive_" ) != - 1 )
575+
576+ stagingDir = " /tmp/c/"
577+ path = saveHiveFile invokePrivate getStagingDir(inputPath, conf, stagingDir)
578+ assert(path.toString.indexOf(" /tmp/c_hive_" ) != - 1 )
579+ }
580+
553581 test(" insert overwrite to dir from hive metastore table" ) {
554582 withTempDir { dir =>
555583 val path = dir.toURI.getPath
0 commit comments