您的位置:首页 > 其它

spark链接hive并查询数据

2017-09-26 09:48 246 查看
首先启动 hadoop,mysql,hive 服务

{hadoop}/sbin/start-all.sh

service mysqld start

hive --service metastore&

hive --service hiveserver2 &

最后启动spark 我是以python方式启动的spark

{spark_home}/bin/pyspark

如果没有报错就是没有什么问题。接下来我们运行一段代码进行测试一下:

>>>from pyspark.sql import HiveContext

>>>from pyspark import SparkConf,SparkContext

>>>conf = SparkConf().setMaster("local").setAppName("My App")

>>>sc= SparkContext(conf=conf)

>>> hiveCtx=HiveContext(sc)
>>>hh=hiveCtx.sql("select * from test")
>>>hh.show()
>>> print hh.first()

Row(id=1)


一切ok,首先要注意下,spark链接hive的时候一定要把 hive/conf下面的hive-site.xml 拷贝到spark/conf 下面

在hive-site.xml 中要配置:主要指明hive的存储位置

<property>
<name>hive.metastore.uris</name>
<value>thrift://vm000:9083</value>
<description>Thrift URI for the remote metastore. Used by metastore client to connect to remote metastore.</description>
</property>


我在配置完成之后还是报错就重启了系统,就好了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐