[Spark][Hive][Python][SQL]Spark 读取Hive表的小例子
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[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|
+-------+----+-------+
以上是关于[Spark][Hive][Python][SQL]Spark 读取Hive表的小例子的主要内容,如果未能解决你的问题,请参考以下文章
Spark(Hive) SQL中UDF的使用(Python)
源码级解读如何解决Spark-sql读取hive分区表执行效率低问题