spark on hive

4 篇文章 0 订阅
1 篇文章 0 订阅

很多时候用spark处理数据,处理完后需要写回hive 数据仓库。 这时候用spark on hive 效率会高很多。

rdd 处理完后,
先创建一个schema

schema = StructType([
StructField(“item_id”,StringType(), True),
StructField(“feed_id”,StringType(), True),
………
StructField(“ds”,StringType(), True)]
)

然后rdd转换为hive df。注意是hive df 。不是sql df
df=hiveContext.createDataFrame(rdd,schema)
hiveContext.sql(‘use database’)
hiveContext.sql(‘SET hive.exec.dynamic.partition=true ‘)
hiveContext.sql(‘SET hive.exec.dynamic.partition.mode=nonstrict ‘)
hiveContext.sql(‘SET hive.exec.max.dynamic.partitions.pernode = 1000 ‘)
hiveContext.sql(‘SET hive.exec.max.dynamic.partitions=1000 ‘)
hiveContext.sql(‘set hive.exec.reducers.bytes.per.reducer=500000000 ‘)

dfw=DataFrameWriter(df)
dfw.partitionBy().insertInto(‘table’)
partitionBy 是分区表,如果没有,则直接insert。如果没有表,那就dfw.saveAsTable()直接写入

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值