From ac8e29d590d9a4530540247393c1f36fb918924f Mon Sep 17 00:00:00 2001 From: Lucas Yang Date: Tue, 21 Jun 2016 16:03:57 +0800 Subject: [PATCH] fix getHiveFile retun file url in jar that cannot be load in SQL --- .../org/apache/spark/sql/hive/test/TestHive.scala | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sql/hive/src/main/scala/org/apache/spark/sql/hive/test/TestHive.scala b/sql/hive/src/main/scala/org/apache/spark/sql/hive/test/TestHive.scala index b45be0251d953..4c330f61b5059 100644 --- a/sql/hive/src/main/scala/org/apache/spark/sql/hive/test/TestHive.scala +++ b/sql/hive/src/main/scala/org/apache/spark/sql/hive/test/TestHive.scala @@ -17,13 +17,14 @@ package org.apache.spark.sql.hive.test -import java.io.File +import java.io.{File, FileOutputStream} import java.util.{Set => JavaSet} import scala.collection.JavaConverters._ import scala.collection.mutable import scala.language.implicitConversions +import org.apache.commons.io.IOUtils import org.apache.hadoop.conf.Configuration import org.apache.hadoop.hive.conf.HiveConf.ConfVars import org.apache.hadoop.hive.ql.exec.FunctionRegistry @@ -180,7 +181,12 @@ private[hive] class TestHiveSparkSession( ShutdownHookManager.registerShutdownDeleteDir(hiveFilesTemp) def getHiveFile(path: String): File = { - new File(Thread.currentThread().getContextClassLoader.getResource(path).getFile) + val tempFile = File.createTempFile(path, "tmp") + tempFile.deleteOnExit() + val in = Thread.currentThread().getContextClassLoader.getResourceAsStream(path) + val out = new FileOutputStream(tempFile) + IOUtils.copy(in, out) + tempFile } val describedTable = "DESCRIBE (\\w+)".r