Spark数据框的分区数 [英] Number of Partitions of Spark Dataframe

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

问题描述

谁能解释一下将为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.

通常:

    使用本地集合上的rangetoDF之类的方法在本地生成的
  • Datasets将使用spark.default.parallelism.
  • RDD创建的
  • Datasets从其父级继承多个分区.
  • 使用数据源API创建的
  • Datsets:

  • Datasets generated locally using methods like range or toDF on local collection will use spark.default.parallelism.
  • Datasets created from RDD inherit number of partitions from its parent.
  • Datsets created using data source API:

这篇关于Spark数据框的分区数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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