Skip to content

Commit 330c499

Browse files
committed
Fix TestHiveContext interaction with PySpark issue
1 parent ef43b4e commit 330c499

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

sql/hive/src/main/scala/org/apache/spark/sql/hive/test/TestHive.scala

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,25 @@ private[hive] class TestHiveSparkSession(
179179
hiveFilesTemp.mkdir()
180180
ShutdownHookManager.registerShutdownDeleteDir(hiveFilesTemp)
181181

182+
lazy val inRepoTests = {
183+
if (System.getProperty("user.dir").endsWith("sql" + File.separator + "hive")) {
184+
new File("src" + File.separator + "test" + File.separator + "resources" + File.separator)
185+
} else {
186+
new File("sql" + File.separator + "hive" + File.separator + "src" + File.separator + "test" +
187+
File.separator + "resources")
188+
}
189+
}
190+
182191
def getHiveFile(path: String): File = {
183-
new File(Thread.currentThread().getContextClassLoader.getResource(path).getFile)
192+
// Attempt to load from class loader, fall back to old system property based.
193+
val resourcePath = Option(Thread.currentThread().getContextClassLoader.getResource(path))
194+
resourcePath.map(rp => new File(rp.getFile)).getOrElse{
195+
val stripped = path.replaceAll("""\.\.\/""", "").replace('/', File.separatorChar)
196+
hiveDevHome
197+
.map(new File(_, stripped))
198+
.filter(_.exists)
199+
.getOrElse(new File(inRepoTests, stripped))
200+
}
184201
}
185202

186203
val describedTable = "DESCRIBE (\\w+)".r

0 commit comments

Comments
 (0)