只覆盖分区火花数据集中的一些分区 [英] Overwrite only some partitions in a partitioned spark Dataset

查看:772
本文介绍了只覆盖分区火花数据集中的一些分区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何覆盖分区数据集,但只有我们要更改的分区?例如,重新计算上周每天的工作,并且只重写上周的数据。

How can we overwrite a partitioned dataset, but only the partitions we are going to change? For example, recomputing last week daily job, and only overwriting last week of data.

默认的Spark行为是覆盖整个表,即使只有一些分区将要写出来。

Default Spark behaviour is to overwrite the whole table, even if only some partitions are going to be written.

推荐答案

自从Spark 2.3.0覆盖表格时,这是一个选项。要覆盖它,您需要将新的 spark.sql.sources.partitionOverwriteMode 设置设置为 dynamic ,数据集需要被分区,写模式覆盖
示例:

Since Spark 2.3.0 this is an option when overwriting a table. To overwrite it, you need to set the new spark.sql.sources.partitionOverwriteMode setting to dynamic, the dataset needs to be partitioned, and the write mode overwrite. Example:

spark.conf.set("spark.sql.sources.partitionOverwriteMode","dynamic")
data.write.mode("overwrite").insertInto("partitioned_table")

我建议在编写之前根据你的分区列重新分区,所以你最终不会得到每个文件夹400个文件。

I recommend doing a repartition based on your partition column before writing, so you won't end up with 400 files per folder.

在Spark 2.3.0之前,最好的解决方案将启动SQL语句以删除这些分区,然后使用附加模式将其写入。

Before Spark 2.3.0, the best solution would be to launch SQL statements to delete those partitions and then write them with mode append.

这篇关于只覆盖分区火花数据集中的一些分区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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