如何更改Spark SQL中的分区大小 [英] How to change partition size in Spark SQL

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

问题描述

我需要使用spark-SQL HiveContext 加载Hive表中的数据并加载到HDFS中。默认情况下,SQL输出中的 DataFrame 具有2个分区。为了获得更多的并行性,我需要更多的SQL分区。 HiveContext中没有重载方法需要分区数量参数。
$ b 重新分区RDD会导致混洗并导致更多处理时间。

  val result = sqlContext.sql(select * from bt_st_ent)

具有以下日志输出:

 在阶段131.0中启动任务0.0(TID 297,aster1 .com,分区0,NODE_LOCAL,2203字节)
在阶段131.0(TID 298,aster1.com,分区1,NODE_LOCAL,2204字节)中启动任务1.0
pre>

我想知道有没有办法增加sql输出的分区大小。

解决方案

Spark< 2.0

您可以使用Hadoop配置选项:


  • mapred.min.split.size

  • mapred.max.split.size



以及HDFS块大小来控制基于文件系统格式的分区大小。

  val minSplit:Int = ??? 
val maxSplit:Int = ???

sc.hadoopConfiguration.setInt(mapred.min.split.size,minSplit)
sc.hadoopConfiguration.setInt(mapred.max.split.size,maxSplit)

Spark 2.0 +

您可以使用 spark.sql.files.maxPartitionBytes 配置:

  spark.conf.set(spark.sql.files.maxPartitionBytes,maxSplit)

在这两种情况下,这些值可能不会被特定的数据源API使用,因此您应该始终检查您使用的格式的文档/实现细节。


I have a requirement to load data from an Hive table using spark-SQL HiveContext and load into HDFS. By default, the DataFrame from SQL output is having 2 partitions. To get more parallelism i need more partitions out of the SQL. There is no overloaded method in HiveContext to take number of partitions parameter.

Repartitioning of the RDD causes shuffling and results in more processing time.

val result = sqlContext.sql("select * from bt_st_ent")

Has the log output of:

Starting task 0.0 in stage 131.0 (TID 297, aster1.com, partition 0,NODE_LOCAL, 2203 bytes)
Starting task 1.0 in stage 131.0 (TID 298, aster1.com, partition 1,NODE_LOCAL, 2204 bytes)

I would like to know is there any way to increase the partitions size of the sql output.

解决方案

Spark < 2.0:

You can use Hadoop configuration options:

  • mapred.min.split.size.
  • mapred.max.split.size

as well as HDFS block size to control partition size for filesystem based formats.

val minSplit: Int = ???
val maxSplit: Int = ???

sc.hadoopConfiguration.setInt("mapred.min.split.size", minSplit)
sc.hadoopConfiguration.setInt("mapred.max.split.size", maxSplit)

Spark 2.0+:

You can use spark.sql.files.maxPartitionBytes configuration:

spark.conf.set("spark.sql.files.maxPartitionBytes", maxSplit)

In both cases these values may not be in use by a specific data source API so you should always check documentation / implementation details of the format you use.

这篇关于如何更改Spark SQL中的分区大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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