Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,15 @@ object SQLConf {
.longConf
.createWithDefault(4 * 1024 * 1024)

val FILES_MIN_PARTITION_NUM = buildConf("spark.sql.files.minPartitionNum")
.doc("The suggested (not guaranteed) minimum number of splitting file partitions. " +

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

splitting? split?

"If not set, the default value is `spark.default.parallelism`. This configuration is " +
"effective only when using file-based sources such as Parquet, JSON and ORC.")
.version("3.1.0")
.intConf
Comment thread
cloud-fan marked this conversation as resolved.
.checkValue(v => v > 0, "The min partition number must be a positive integer.")
.createOptional

val IGNORE_CORRUPT_FILES = buildConf("spark.sql.files.ignoreCorruptFiles")
.doc("Whether to ignore corrupt files. If true, the Spark jobs will continue to run when " +
"encountering corrupted files and the contents that have been read will still be returned. " +
Expand Down Expand Up @@ -2782,6 +2791,8 @@ class SQLConf extends Serializable with Logging {

def filesOpenCostInBytes: Long = getConf(FILES_OPEN_COST_IN_BYTES)

def filesMinPartitionNum: Option[Int] = getConf(FILES_MIN_PARTITION_NUM)

def ignoreCorruptFiles: Boolean = getConf(IGNORE_CORRUPT_FILES)

def ignoreMissingFiles: Boolean = getConf(IGNORE_MISSING_FILES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ object FilePartition extends Logging {
selectedPartitions: Seq[PartitionDirectory]): Long = {
val defaultMaxSplitBytes = sparkSession.sessionState.conf.filesMaxPartitionBytes
val openCostInBytes = sparkSession.sessionState.conf.filesOpenCostInBytes
val defaultParallelism = sparkSession.sparkContext.defaultParallelism
val minPartitionNum = sparkSession.sessionState.conf.filesMinPartitionNum
.getOrElse(sparkSession.sparkContext.defaultParallelism)
val totalBytes = selectedPartitions.flatMap(_.files.map(_.getLen + openCostInBytes)).sum
val bytesPerCore = totalBytes / defaultParallelism
val bytesPerCore = totalBytes / minPartitionNum

Math.min(defaultMaxSplitBytes, Math.max(openCostInBytes, bytesPerCore))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,28 @@ class FileSourceStrategySuite extends QueryTest with SharedSparkSession with Pre
}
}

test("Add spark.sql.files.minPartitionNum config") {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we add SPARK-32019: prefix into this test case name?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's not a bug. So it's not need ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better to add it since it's a dedicated test case for this JIRA ticket.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add it.

withSQLConf(SQLConf.FILES_MIN_PARTITION_NUM.key -> "1") {
val table =
createTable(files = Seq(
"file1" -> 1,
"file2" -> 1,
"file3" -> 1
))
assert(table.rdd.partitions.length == 1)
Comment thread
dongjoon-hyun marked this conversation as resolved.
}

withSQLConf(SQLConf.FILES_MIN_PARTITION_NUM.key -> "10") {
val table =
createTable(files = Seq(
"file1" -> 1,
"file2" -> 1,
"file3" -> 1
))
assert(table.rdd.partitions.length == 3)
}

@cloud-fan cloud-fan Jun 19, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add more tests to make sure that this is really for min partition number?

e.g. we can create more partitions than the min number, as we make each partition 128mb.

}

// Helpers for checking the arguments passed to the FileFormat.

protected val checkPartitionSchema =
Expand Down