Spark数据框的分区数 [英] Number of Partitions of Spark Dataframe
问题描述
谁能解释一下将为Spark Dataframe创建的分区数量.
Can anyone explain about the number of partitions that will be created for a Spark Dataframe.
我知道对于RDD,在创建它时,我们可以提及如下所示的分区数量.
I know that for a RDD, while creating it we can mention the number of partitions like below.
val RDD1 = sc.textFile("path" , 6)
但是对于Spark数据帧,在创建时看起来像我们没有选择指定RDD分区数的选项.
But for Spark dataframe while creating looks like we do not have option to specify number of partitions like for RDD.
我认为只有这种可能性,在创建数据框之后,我们可以使用重新分区API.
Only possibility i think is, after creating dataframe we can use repartition API.
df.repartition(4)
所以任何人都可以让我知道是否可以在创建数据帧时指定分区数.
So can anyone please let me know if we can specify the number of partitions while creating a dataframe.
推荐答案
您不能,或者至少在一般情况下不会,但是与RDD相比并没有什么不同.例如,您提供的textFile
示例代码仅对最小分区数设置了限制.
You cannot, or at least not in a general case but it is not that different compared to RDD. For example textFile
example code you've provides sets only a limit on the minimum number of partitions.
通常:
-
使用本地集合上的
-
Datasets
将使用spark.default.parallelism
.
从 -
Datasets
从其父级继承多个分区.
使用数据源API创建的 -
Datsets
:
range
或toDF
之类的方法在本地生成的RDD
创建的Datasets
generated locally using methods likerange
ortoDF
on local collection will usespark.default.parallelism
.Datasets
created fromRDD
inherit number of partitions from its parent.Datsets
created using data source API:
- 在Spark 1.x中,通常取决于Hadoop配置(最小/最大拆分大小).
- 在Spark 2.x中有一个正在使用的Spark SQL特定配置.
这篇关于Spark数据框的分区数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!