如何在没有 hive-site.xml 的情况下将 Spark SQL 连接到远程 Hive 元存储(通过节俭协议)? [英] How to connect Spark SQL to remote Hive metastore (via thrift protocol) with no hive-site.xml?
问题描述
我正在将 HiveContext 与 SparkSQL 一起使用,并且我正在尝试连接到远程 Hive 元存储,设置 Hive 元存储的唯一方法是通过在类路径中包含 hive-site.xml(或将其复制到/etc/spark/conf/).
I'm using HiveContext with SparkSQL and I'm trying to connect to a remote Hive metastore, the only way to set the hive metastore is through including the hive-site.xml on the classpath (or copying it to /etc/spark/conf/).
有没有办法在不包含 hive-site.xml 的情况下在 java 代码中以编程方式设置此参数?如果是这样,要使用的 Spark 配置是什么?
Is there a way to set this parameter programmatically in a java code without including the hive-site.xml ? If so what is the Spark configuration to use ?
推荐答案
对于 Spark 1.x,可以设置:
For Spark 1.x, you can set with :
System.setProperty("hive.metastore.uris", "thrift://METASTORE:9083");
final SparkConf conf = new SparkConf();
SparkContext sc = new SparkContext(conf);
HiveContext hiveContext = new HiveContext(sc);
或者
final SparkConf conf = new SparkConf();
SparkContext sc = new SparkContext(conf);
HiveContext hiveContext = new HiveContext(sc);
hiveContext.setConf("hive.metastore.uris", "thrift://METASTORE:9083");
如果您的 Hive 被 Kerberized 更新:
在创建 HiveContext 之前尝试设置这些:
Try setting these before creating the HiveContext :
System.setProperty("hive.metastore.sasl.enabled", "true");
System.setProperty("hive.security.authorization.enabled", "false");
System.setProperty("hive.metastore.kerberos.principal", hivePrincipal);
System.setProperty("hive.metastore.execute.setugi", "true");
这篇关于如何在没有 hive-site.xml 的情况下将 Spark SQL 连接到远程 Hive 元存储(通过节俭协议)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!