forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-22160][SQL] Make sample points per partition (in range partiti…
…oner) configurable and bump the default value up to 100 Spark's RangePartitioner hard codes the number of sampling points per partition to be 20. This is sometimes too low. This ticket makes it configurable, via spark.sql.execution.rangeExchange.sampleSizePerPartition, and raises the default in Spark SQL to be 100. Added a pretty sophisticated test based on chi square test ... Author: Reynold Xin <rxin@databricks.com> Closes apache#19387 from rxin/SPARK-22160. This commit contains the following squashed commits: 938326b NETFLIX-BUILD: Fixup backport of SPARK-22160.
- Loading branch information
Showing
4 changed files
with
96 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
sql/core/src/test/scala/org/apache/spark/sql/ConfigBehaviorSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.sql | ||
|
||
import org.apache.commons.math3.stat.inference.ChiSquareTest | ||
|
||
import org.apache.spark.sql.internal.SQLConf | ||
import org.apache.spark.sql.test.SharedSQLContext | ||
|
||
|
||
class ConfigBehaviorSuite extends QueryTest with SharedSQLContext { | ||
|
||
import testImplicits._ | ||
|
||
test("SPARK-22160 spark.sql.execution.rangeExchange.sampleSizePerPartition") { | ||
// In this test, we run a sort and compute the histogram for partition size post shuffle. | ||
// With a high sample count, the partition size should be more evenly distributed, and has a | ||
// low chi-sq test value. | ||
// Also the whole code path for range partitioning as implemented should be deterministic | ||
// (it uses the partition id as the seed), so this test shouldn't be flaky. | ||
|
||
val numPartitions = 4 | ||
|
||
def computeChiSquareTest(): Double = { | ||
val n = 10000 | ||
// Trigger a sort | ||
val data = spark.range(0, n, 1, 1).sort('id) | ||
.selectExpr("SPARK_PARTITION_ID() pid", "id").as[(Int, Long)].collect() | ||
|
||
// Compute histogram for the number of records per partition post sort | ||
val dist = data.groupBy(_._1).map(_._2.length.toLong).toArray | ||
assert(dist.length == 4) | ||
|
||
new ChiSquareTest().chiSquare( | ||
Array.fill(numPartitions) { n.toDouble / numPartitions }, | ||
dist) | ||
} | ||
|
||
withSQLConf(SQLConf.SHUFFLE_PARTITIONS.key -> numPartitions.toString) { | ||
// The default chi-sq value should be low | ||
assert(computeChiSquareTest() < 100) | ||
|
||
withSQLConf(SQLConf.RANGE_EXCHANGE_SAMPLE_SIZE_PER_PARTITION.key -> "1") { | ||
// If we only sample one point, the range boundaries will be pretty bad and the | ||
// chi-sq value would be very high. | ||
assert(computeChiSquareTest() > 1000) | ||
} | ||
} | ||
} | ||
|
||
} |