Skip to content

Commit de938ed

Browse files
author
zuotingbing
committed
add a test case for SPARK-20594
1 parent c154f3a commit de938ed

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

sql/hive/src/test/scala/org/apache/spark/sql/hive/InsertIntoHiveTableSuite.scala

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,4 +494,50 @@ class InsertIntoHiveTableSuite extends QueryTest with TestHiveSingleton with Bef
494494
spark.table("t").write.insertInto(tableName)
495495
}
496496
}
497+
498+
/**
499+
* Drop named tables if they exist
500+
*
501+
* @param tableNames tables to drop
502+
*/
503+
def dropTables(tableNames: String*): Unit = {
504+
tableNames.foreach { name =>
505+
sql(s"DROP TABLE IF EXISTS $name")
506+
}
507+
}
508+
509+
test(
510+
"""SPARK-20594: The staging directory should be appended with ".hive-staging"
511+
|to avoid being deleted if we set hive.exec.stagingdir under the table directory
512+
|without start with "."""".stripMargin) {
513+
514+
dropTables("test_table", "test_table1")
515+
516+
sql("CREATE TABLE test_table (key int, value string)")
517+
518+
// Add some data.
519+
testData.write.mode(SaveMode.Append).insertInto("test_table")
520+
521+
// Make sure the table has also been updated.
522+
checkAnswer(
523+
sql("SELECT * FROM test_table"),
524+
testData.collect().toSeq
525+
)
526+
527+
sql("CREATE TABLE test_table1 (key int, value string)")
528+
529+
// Set hive.exec.stagingdir under the table directory without start with ".".
530+
sql("set hive.exec.stagingdir=./test")
531+
532+
// Now overwrite.
533+
sql("INSERT OVERWRITE TABLE test_table1 SELECT * FROM test_table")
534+
535+
// Make sure the table has also been updated.
536+
checkAnswer(
537+
sql("SELECT * FROM test_table1"),
538+
testData.collect().toSeq
539+
)
540+
541+
dropTables("test_table", "test_table1")
542+
}
497543
}

0 commit comments

Comments
 (0)