Spark 读 Hive(不在一个 yarn 集群)

方法一

1. 找到目标 Hive 的 hive-site.xml 文件,拷贝到 spark 的 conf 下面。

    在我的情况下 /etc/hive/conf/hive-site.xml -> /usr/lib/spark/conf/hive-site.xml

2. 运行期间,遇到一个问题:

java.lang.NoClassDefFoundError: org/apache/tez/dag/api/SessionNotRunning

   相关解答:https://issues.apache.org/jira/browse/SPARK-15779

   简单来说,把 "hive.execution.engine" 的 value,从 tez 改成 mr

方法二

   创建 SparkSession 的时候,在 config 中配置参数 "hive.metastore.uris",并 enableHiveSupport 即可

  val spark = SparkSession.builder()
    .appName(appName)
    .config("hive.metastore.uris", "thrift://ip-10-10-242-40.ec2.internal:9083")
    .enableHiveSupport()
    .getOrCreate()

  一开始,我在 spark-shell 中尝试没有成功。。原因是shell启动时,预先生成了 SparkSession,之后的 getOrCreate 都是直接用了老的实例。

原文地址:https://www.cnblogs.com/keepthinking/p/10318606.html