覆盖火花数据帧写入方法中的特定分区 [英] Overwrite specific partitions in spark dataframe write method

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

问题描述

我想覆盖特定的分区而不是全部在 spark 中.我正在尝试以下命令:

I want to overwrite specific partitions instead of all in spark. I am trying the following command:

df.write.orc('maprfs:///hdfs-base-path','overwrite',partitionBy='col4')

其中 df 是具有要覆盖的增量数据的数据帧.

where df is dataframe having the incremental data to be overwritten.

hdfs-base-path 包含主数据.

hdfs-base-path contains the master data.

当我尝试上述命令时,它会删除所有分区,并将 df 中存在的分区插入到 hdfs 路径中.

When I try the above command, it deletes all the partitions, and inserts those present in df at the hdfs path.

我的要求是仅覆盖 df 中指定 hdfs 路径中存在的那些分区.有人可以帮我吗?

What my requirement is to overwrite only those partitions present in df at the specified hdfs path. Can someone please help me in this?

推荐答案

这是一个常见问题.Spark 到 2.0 的唯一解决方案是直接写入分区目录,例如,

This is a common problem. The only solution with Spark up to 2.0 is to write directly into the partition directory, e.g.,

df.write.mode(SaveMode.Overwrite).save("/root/path/to/data/partition_col=value")

如果您在 2.0 之前使用 Spark,则需要使用以下方法阻止 Spark 发出元数据文件(因为它们会破坏自动分区发现):

If you are using Spark prior to 2.0, you'll need to stop Spark from emitting metadata files (because they will break automatic partition discovery) using:

sc.hadoopConfiguration.set("parquet.enable.summary-metadata", "false")

如果您使用的是 1.6.2 之前的 Spark,您还需要删除 /root/path/to/data/partition_col=value 中的 _SUCCESS 文件否则它的存在会破坏自动分区发现.(我强烈建议使用 1.6.2 或更高版本.)

If you are using Spark prior to 1.6.2, you will also need to delete the _SUCCESS file in /root/path/to/data/partition_col=value or its presence will break automatic partition discovery. (I strongly recommend using 1.6.2 or later.)

您可以从我关于 防弹作业.

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

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