码迷,mamicode.com
首页 > 数据库 > 详细

[Spark][Hive][Python][SQL]Spark 读取Hive表的小例子

时间:2017-10-07 14:36:35      阅读:290      评论:0      收藏:0      [点我收藏+]

标签:string   spark   limited   rdf   sts   int   local   lte   orm   

[Spark][Hive][Python][SQL]Spark 读取Hive表的小例子
$ cat customers.txt
1 Ali us
2 Bsb ca
3 Carls mx

$ hive

hive>
> CREATE TABLE IF NOT EXISTS customers(
> cust_id string,
> name string,
> country string
> )
> ROW FORMAT DELIMITED FIELDS TERMINATED BY ‘\t‘;

hive> load data local inpath ‘/home/training/customers.txt‘ into table customers;

hive>exit

$pyspark

sqlContext =HiveContext(sc)
filterDF=sqlContext.sql(""" SELECT * FROM customers WHERE name LIKE "A%" """)

filterDF.limit(3).show()

+-------+----+-------+
|cust_id|name|country|
+-------+----+-------+
| 001| Ani| us|
+-------+----+-------+

[Spark][Hive][Python][SQL]Spark 读取Hive表的小例子

标签:string   spark   limited   rdf   sts   int   local   lte   orm   

原文地址:http://www.cnblogs.com/gaojian/p/7634234.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!