1、在CDH中已经添加了hive
2、配置hive中的hive-site.xml参数 /opt/cloudera/parcels/CDH/lib/hive/conf/hive-site.xml
3、配置spark中的hive-site.xml 目录/opt/cloudera/parcels/CDH/lib/spark3/conf/hive-site.xml
<property> <name>hive.metastore.warehouse.dir</name> <value>/user/hive/warehouse</value> </property> <property> <name>hive.metastore.local</name> <value>false</value> </property> <property> <name>hive.metastore.uris</name> <value>thrift://hadoop103:9083</value> </property>
4、修改spark-env.sh,目录/opt/cloudera/parcels/CDH/lib/spark3/conf/
export PYSPARK_PYTHON=/opt/cloudera/anaconda3/bin/python export SPARK_HOME=/opt/cloudera/parcels/CDH/lib/spark3
5、如果自己在代码中实现这
spark = SparkSession.builder.appName('feat-eng')\ .config("hive.metastore.warehouse.dir",'hdfs://hadoop103:8020/user/hive/warehouse')\ .config("hive.metastore.uris","thrift://hadoop103:9083") \ .enableHiveSupport().getOrCreate()
6、下面就是spark on hive 对接数据
import findspark findspark.init(spark_home='/opt/cloudera/parcels/CDH/lib/spark3',python_path='/opt/cloudera/anaconda3/bin/python') import pyspark from pyspark.context import SparkContext from pyspark.sql import SparkSession from pyspark.sql.functions import * spark = SparkSession.builder.appName('feat-eng')\ .config("hive.metastore.warehouse.dir",'hdfs://hadoop103:8020/user/hive/warehouse')\ .config("hive.metastore.uris","thrift://hadoop103:9083") \ .enableHiveSupport().getOrCreate() '''读取csv的原始数据''' anime_df = spark.read.csv('hdfs://hadoop101:8020/recommandvideo/anime.csv',header=True,inferSchema=True) anime_df.createOrReplaceTempView("temp_anime") '''将数据入库hive''' spark.sql('insert into sparktest.anime select "1",anime_id,name,genre,type,episodes,rating,members from temp_anime') '''读取hive中表的数据''' spark.sql("select * from sparktest.anime").show()
热门文章
- 南京领养宠物的平台电话是多少(南京宠物猫领养中心)
- 宠物领养协议书范本免费版图片大全集(宠物领养协议文案)
- 2月18日 | Free Trojan Node节点订阅每天更新20.8M/S免费节点订阅链接
- 动物医院需要几个兽医资格证书呢英语 动物医院需要几个兽医资格证书呢英语怎么说
- Spark SQL底层执行流程详解
- 宠物粮行业分析报告怎么写的(宠物粮行业分析报告怎么写的啊)
- 2月7日 | Free Trojan Node节点订阅每天更新19M/S免费节点订阅链接
- 动物防疫疫苗管理工作方案怎么写好(动物疫苗管理制度)
- 1月12日 | Free Trojan Node节点订阅每天更新22.1M/S免费节点订阅链接
- 上海宠物领养平台可靠吗安全吗知乎推荐(上海宠物领养中心免费领养狗狗)