Spark程序中使用SQL语句查询Hive的表数据的方法是什么?
我们在使用spark-shell登录时,默认初始化了一个spark实例:
Spark session available as 'spark'.
我们可以使用spark访问Hive的表数据。
scala> val tableDF =spark.sql("select * from yahoo_stocks_orc limit 10")
tableDF: org.apache.spark.sql.DataFrame = [date: string,open: float ... 5 more fields]
查看10行数据:
scala> tableDF.take(10).foreach(println)
[2015-04-28,44.34,44.57,43.94,44.34,7188300,44.34]
[2015-04-27,44.65,45.1,44.25,44.36,10840900,44.36]
[2015-04-24,43.73,44.71,43.69,44.52,11267500,44.52]
[2015-04-23,43.92,44.06,43.58,43.7,14274900,43.7]
[2015-04-22,44.58,44.85,43.67,43.98,32241200,43.98]
[2015-04-21,45.15,45.18,44.45,44.49,16103700,44.49]
[2015-04-20,44.73,44.91,44.41,44.66,10052900,44.66]
[2015-04-17,45.3,45.44,44.25,44.45,13305700,44.45]
[2015-04-16,45.82,46.13,45.53,45.78,13800300,45.78]
[2015-04-15,45.46,45.83,45.23,45.73,15033500,45.73]
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。