Skip to content

Commit 4431daa

Browse files
committed
Support both methods
1 parent 2be8cdf commit 4431daa

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

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

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

182-
val inRepoTests = if (System.getProperty("user.dir").endsWith("sql" + File.separator + "hive")) {
183-
new File("src" + File.separator + "test" + File.separator + "resources" + File.separator)
184-
} else {
185-
new File("sql" + File.separator + "hive" + File.separator + "src" + File.separator + "test" +
186-
File.separator + "resources")
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+
}
187189
}
188190

189191
def getHiveFile(path: String): File = {
190-
val stripped = path.replaceAll("""\.\.\/""", "").replace('/', File.separatorChar)
191-
hiveDevHome
192-
.map(new File(_, stripped))
193-
.filter(_.exists)
194-
.getOrElse(new File(inRepoTests, stripped))
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+
}
195201
}
196202

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

0 commit comments

Comments
 (0)