11.7 spark和hive整合

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011418530/article/details/81556692

1、在Spark的安装包下的conf下创建一个文件 hive-site.xml

<configuration>

<property>

<name>hive.metastore.uris</name>

<value>thrift://node2:9083</value>

</property>

</configuration>

不需要更新到其他的节点,只需要在客户端有一份hive-site.xml就可以

2、开启Hive的metaStore服务 hive --service metastore 以metastore启动hive

假如启动不了,可以cd ~到家目录下 创建一个vim startHiveMetastoreService.sh

source ~/.bashrc

hive --service metastore > /data/metastore.log 2>&1 &

记得创建:/data/metastore.log

./startHiveMetastoreService.sh启动

3、在spark的bin目录下启动spark sql: ./spark-shell --master spark://node1:7077 --total-executor-cores 3

4、import org.apache.spark.sql.hive.HiveContext

val hc = new HiveContext(sc) //new hive链接对象

hc.sql("show databases").show

hc.sql("use result").show

设置日志级别:sc.setLogLevel("INFO")

猜你喜欢

转载自blog.csdn.net/u011418530/article/details/81556692