在 Hive 中将 Spark 数据帧另存为动态分区表 [英] Save Spark dataframe as dynamic partitioned table in Hive

查看:32
本文介绍了在 Hive 中将 Spark 数据帧另存为动态分区表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个示例应用程序可以将 csv 文件读取到数据帧中.可以使用该方法将数据帧以镶木地板格式存储到 Hive 表中df.saveAsTable(tablename,mode).

I have a sample application working to read from csv files into a dataframe. The dataframe can be stored to a Hive table in parquet format using the method df.saveAsTable(tablename,mode).

上面的代码工作正常,但是我每天都有很多数据,我想根据创建日期(表中的列)动态分区 hive 表.

The above code works fine, but I have so much data for each day that i want to dynamic partition the hive table based on the creationdate(column in the table).

有没有办法动态分区数据帧并将其存储到配置单元仓库.想要避免使用 hivesqlcontext.sql(insert into table partittioin by(date)....) 对插入语句进行硬编码.

is there any way to dynamic partition the dataframe and store it to hive warehouse. Want to refrain from Hard-coding the insert statement using hivesqlcontext.sql(insert into table partittioin by(date)....).

问题可以看作是对以下内容的扩展:How to将 DataFrame 直接保存到 Hive?

Question can be considered as an extension to :How to save DataFrame directly to Hive?

非常感谢任何帮助.

推荐答案

我相信它是这样的:

df 是一个包含年、月和其他列的数据框

df is a dataframe with year, month and other columns

df.write.partitionBy('year', 'month').saveAsTable(...)

df.write.partitionBy('year', 'month').insertInto(...)

这篇关于在 Hive 中将 Spark 数据帧另存为动态分区表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆