Spark 在加载 Hive 表时创建了多少个分区 [英] How many partitions Spark creates when loading a Hive table

查看:31
本文介绍了Spark 在加载 Hive 表时创建了多少个分区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使是 Hive 表或 HDFS 文件,当 Spark 读取数据并创建数据帧时,我认为 RDD/数据帧中的分区数将等于 HDFS 中的部分文件数.但是当我对 Hive 外部表进行测试时,我可以看到该数字与部分文件的数量不同.数据帧中的分区数为 119.该表是一个 Hive 分区表,其中包含 150 个部分文件, 文件的最小大小为 30 MB,最大大小为 118 MB.那么是什么决定了分区的数量?

Even if it is a Hive table or an HDFS file, when Spark reads the data and creates a dataframe, I was thinking that the number of partitions in the RDD/dataframe will be equal to the number of partfiles in HDFS. But when I did a test with Hive external table, I could see that the number was coming different than the number of part-files .The number of partitions in a dataframe was 119. The table was a Hive partitioned table with 150 partfiles in it, with a minimum size of a file 30 MB and max size is 118 MB. So then what decides the number of partitions?

推荐答案

您可以通过设置 spark.sql.files.maxPartitionBytes 来控制 Spark 打包到单个分区中的字节数.默认值为 128 MB,请参阅 Spark Tuning.

You can control how many bytes Spark packs into a single partition by setting spark.sql.files.maxPartitionBytes. The default value is 128 MB, see Spark Tuning.

这篇关于Spark 在加载 Hive 表时创建了多少个分区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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