@@ -20,12 +20,13 @@ package org.apache.spark.sql.hive.execution
2020import java .io .{File , PrintWriter }
2121import java .nio .charset .StandardCharsets
2222import java .sql .{Date , Timestamp }
23+ import java .util .Set
2324
2425import scala .sys .process .{Process , ProcessLogger }
2526import scala .util .Try
2627
2728import com .google .common .io .Files
28- import org .apache .hadoop .fs .Path
29+ import org .apache .hadoop .fs .{ FileSystem , Path }
2930
3031import org .apache .spark .sql ._
3132import org .apache .spark .sql .catalyst .TableIdentifier
@@ -2031,4 +2032,22 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton {
20312032 checkAnswer(table.filter($" p" === " p1\" and q=\" q1" ).select($" a" ), Row (4 ))
20322033 }
20332034 }
2035+
2036+ test(" SPARK-21721: Clear FileSystem deleterOnExit cache if path is successfully removed" ) {
2037+ withTable(" test21721" ) {
2038+ val deleteOnExitField = classOf [FileSystem ].getDeclaredField(" deleteOnExit" )
2039+ deleteOnExitField.setAccessible(true )
2040+
2041+ val fs = FileSystem .get(spark.sparkContext.hadoopConfiguration)
2042+ val setOfPath = deleteOnExitField.get(fs).asInstanceOf [Set [Path ]]
2043+
2044+ val testData = sparkContext.parallelize(1 to 10 ).map(i => TestData (i, i.toString)).toDF()
2045+ sql(" CREATE TABLE test21721 (key INT, value STRING)" )
2046+ val pathSizeToDeleteOnExit = setOfPath.size()
2047+
2048+ (0 to 10 ).foreach(_ => testData.write.mode(SaveMode .Append ).insertInto(" test1" ))
2049+
2050+ assert(setOfPath.size() == pathSizeToDeleteOnExit)
2051+ }
2052+ }
20342053}
0 commit comments