大数据IMF传奇行动绝密课程第57课:Spark SQL on Hive配置及实战

Spark SQL on Hive配置及实战

因为底层hive最为存储引擎,所以需要配置hive-site.xml

//配置以下参数
hive.metastore.uris
thrift://Master:9083
在linux下运行如下命令
hive --service metastore >metastore.log 2>& 1&

启动spark-shell

val hiveContext = org.apache.spark.sql.hive.HiveContext(sc)
hiveContext.sql("use hive") //使用之前已经建好的hive库
hiveContext.sql("show tables").collect.foreach(println)
hiveContext.sql("select count(*) from sougouq1").collect.foreach(println)
hiveContext.sql("select count(*) from sougouq3 where website like "%baidu%").collect.foreach(println)
hiveContext.sql("select count(*) from sougouq3 where website like "%baidu%" and c_seq=1 and s_seq=1).collect.foreach(println)

Spark SQL在计算后第一次10多秒,第二次以后7秒左右,使用Hive速度在40多秒左右

val df = sqlContext.read.json("/library/examples/src/main/resources/people.json")
df.show()
df.printschema()
df.select("name").show()
df.select(df("name"),df("age") +1).show()
df.filter(df("age")>21).show()
df.groupBy("age").count().show()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值