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


[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|
+-------+----+-------+


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM