SparkSQL整合 HIVE
-
安装hive(配置好)
-
将配置好的hive-site.xml放入$SPARK-HOME/conf目录下
-
将mysql-xxx-connector-xx.jar放到spark集群中节点的lib目录下
-
启动spark-shell时指定mysql连接驱动位置
先启动spark:sbin/start-all.sh
bin/spark-shell \
--master spark://master:7077 \
--executor-memory 1g \
--total-executor-cores 2 \
--driver-class-path /apps/spark/lib/mysql-connector-java-5.1.35-bin.jar
5.使用sqlContext.sql调用HQL
sqlContext.sql(“select * from TABLS limit 2”)
或使用org.apache.spark.sql.hive.HiveContext
import org.apache.spark.sql.hive.HiveContext
val hiveContext = new HiveContext(sc)
hiveContext.sql(“select * from spark.person”).show()
或者.write.mode(“append”).jdbc()