在spark中保存固定大小的镶木地板输出文件 [英] Save the parquet output file with fixed size in spark

查看:37
本文介绍了在spark中保存固定大小的镶木地板输出文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 160GB 的数据,在 DATE 列上分区并以在 spark 1.6.0 上运行的镶木地板文件格式存储.我需要在每个分区中存储具有相同大小文件的输出镶木地板文件,每个分区都有固定大小,比如每个 100MB.

I have 160GB of data,partition on DATE Column and storing in parquet file format running on spark 1.6.0. I need to store the output parquet files with equal sized files in each partition with fixed size say like 100MB each.

我尝试使用以下代码:

val blockSize= 1024*1024*100
sc.hadoopConfiguration.setInt("dfs.blocksize", blockSize)
sc.hadoopConfiguration.setInt("parquet.block.size",blockSize)

df1.write.partitionBy("DATE").parquet("output_file_path")

上面的配置不起作用,它正在创建具有默认分区数的多个文件,而不是 100 MB 的文件.

The above configuration is not working, it is creating multiple files with default number of partitions,not the 100 MB file.

推荐答案

不可能为每个文件获得完全相同的大小,但您可以向 Spark 提供足够的提示,使它们在"特定大小范围内.一般目标是使每个文件等于 HDFS 块大小,并且每个文件包含一个(或多个)行组.您希望行组适合一个 HDFS 块.如果一个行组不适合一个块,您可能需要进行额外的网络调用来读取另一个 HDFS 块以完全读取该行组.

Its not possible to get the exact same size for every file, but you can give enough hints to Spark to make them "within" a certain size. The general goal is to make each file equal to the HDFS block size and each file holds one (or more) row group. You want the row group to fit in one HDFS block. If a row group does not fit in one block, you have a situation where additional network calls needs to be made to read another HDFS block to completely read the row group.

要实现这一点,请执行以下操作:

To achieve this, do the following:

  • 将 spark conf 中的 spark.sql.files.maxPartitionBytes 设置为 256 MB(等于您的 HDFS 块尺寸)
  • 将 Spark 中的 parquet writer 选项上的 parquet.block.size 设置为 256 MB.

tradesDF.write.option("parquet.block.size", 256 * 1024 * 1024)

这篇关于在spark中保存固定大小的镶木地板输出文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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