如何在spark的多级分区中覆盖特定的顶级分区

v64noz0r  于 2021-06-28  发布在  Hive
关注(0)|答案(0)|浏览(319)

我的table有4个分区order:period_dt,年,月,日
i period\u dt是静态分区(值是一个参数),年、月、日是动态的。所以我知道period\u dt分区值,我想覆盖它。

newInputDF.write().mode("overwrite").partitionBy("period_dt","year","month","date").parquet("trg_file_path");

使用上面的命令spark覆盖所有分区。但是在我的例子中,如果分区存在,则覆盖它,否则追加它。我想在period\u dt级别覆盖分区。
一种方法是提供完整的路径:

inputDFTwo.write().mode("overwrite").parquet("trg_tbl/period_dt=2016-09-21/year=2016/month=09/date=21");

但是年、月、日是动态的

second to use hive query with HiveContext.

是否有其他方法覆盖特定分区?
我想到的解决方案是:

hiveContext.sql("INSERT OVERWRITE TABLE table_name PARTITION(period_dt='2016-06-08', year,month,date) , select x,y,z,year,month,date from DFTmpTable");

and

DeleteHDFSfile(/table/period_dt='2016-06-08')
DF.write().mode("append").partitionBy("period_dt","year","month","date").parquet("path")

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题