出现这个问题可能是没有找到hive库地址,使用spark-sql时,spark-sql脚本会知道要在Spark安装目录中,去找conf/hive-site.xml; 但是IDEA运行时,就不知道如何去找哪里找hive-site.xml了.
知道spark如何使用hive-site.xml文件,才能知道应该如何将这个文件"送"给IEDA;
在 HiveContext.scala源码中:
[mw_shl_code=scala,true]def newTemporaryConfiguration(): Map[String, String] = {
val tempDir = Utils.createTempDir()
val localMetastore = new File(tempDir, "metastore").getAbsolutePath
val propMap: HashMap[String, String] = HashMap()
// We have to mask all properties in hive-site.xml that relates to metastore data source
// as we used a local metastore here.
HiveConf.ConfVars.values().foreach { confvar =>
if (confvar.varname.contains("datanucleus") || confvar.varname.contains("jdo")) {
propMap.put(confvar.varname, confvar.defaultVal)
}
} [/mw_shl_code]
Spark SQL是复用了Hive的HiveConf类来读取hive-site.xml中!: HiveConf是通过在Classpath中依次寻找hive-site.xml的。于是在IDEA中显式制定classpath:
File->Project Structure->Modules->Dependencies->Add->Jars or Directories, 选中spark安装目录下的conf目录:
选择Classes,然后将Scope修改为"Runtime";
参考:美伊小公主的奶爸
|