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

查看:54
本文介绍了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.

一般来说:

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

  • 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 Dataframe 的分区数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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