-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-12662][SQL] Fix DataFrame.randomSplit to avoid creating overlapping splits #10626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
27288a3
6336832
8c3293c
be9630f
56d9bd7
3af6a2d
1b30119
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -129,6 +129,19 @@ class HiveSparkSubmitSuite | |
| runSparkSubmit(args) | ||
| } | ||
|
|
||
| test("SPARK-12662 fix DataFrame.randomSplit to avoid creating overlapping splits") { | ||
|
||
| val unusedJar = TestUtils.createJarWithClasses(Seq.empty) | ||
| val args = Seq( | ||
| "--class", SPARK_12662.getClass.getName.stripSuffix("$"), | ||
| "--name", "SparkSQLConfTest", | ||
| "--master", "local-cluster[2,1,1024]", | ||
| "--conf", "spark.ui.enabled=false", | ||
| "--conf", "spark.master.rest.enabled=false", | ||
| "--driver-java-options", "-Dderby.system.durability=test", | ||
| unusedJar.toString) | ||
| runSparkSubmit(args) | ||
| } | ||
|
|
||
| // NOTE: This is an expensive operation in terms of time (10 seconds+). Use sparingly. | ||
| // This is copied from org.apache.spark.deploy.SparkSubmitSuite | ||
| private def runSparkSubmit(args: Seq[String]): Unit = { | ||
|
|
@@ -372,3 +385,48 @@ object SPARK_11009 extends QueryTest { | |
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * This object is used to test SPARK-12662: https://issues.apache.org/jira/browse/SPARK-12662. | ||
| * This test ensures that [[org.apache.spark.sql.DataFrame.randomSplit]] does not create overlapping | ||
| * splits even when the underlying dataframe doesn't guarantee a deterministic ordering of rows in | ||
| * each partition. | ||
| */ | ||
| object SPARK_12662 extends QueryTest { | ||
| import org.apache.spark.sql.functions._ | ||
|
|
||
| protected var sqlContext: SQLContext = _ | ||
|
|
||
| def main(args: Array[String]): Unit = { | ||
| Utils.configTestLog4j("INFO") | ||
|
|
||
| val sparkContext = new SparkContext( | ||
| new SparkConf() | ||
| .set("spark.sql.shuffle.partitions", "100")) | ||
|
|
||
| val hiveContext = new TestHiveContext(sparkContext) | ||
| sqlContext = hiveContext | ||
|
|
||
| try { | ||
| val n = 600 | ||
| val data = sqlContext.range(n).toDF("id").repartition(200, col("id")) | ||
| val splits = data.randomSplit(Array[Double](1, 2, 3), seed = 1) | ||
| assert(splits.length == 3, "wrong number of splits") | ||
|
|
||
| assert(splits.reduce((a, b) => a.unionAll(b)).sort("id").collect().toList == | ||
| data.sort(col("id")).collect().toList, "incomplete or wrong split") | ||
|
|
||
| for (id <- splits.indices) { | ||
| assert(splits(id).intersect(splits((id + 1) % splits.length)).collect().isEmpty, | ||
| s"split $id overlaps with split ${(id + 1) % splits.length}") | ||
| } | ||
|
|
||
| val s = splits.map(_.count()) | ||
| assert(math.abs(s(0) - 100) < 50) // std = 9.13 | ||
| assert(math.abs(s(1) - 200) < 50) // std = 11.55 | ||
| assert(math.abs(s(2) - 300) < 50) // std = 12.25 | ||
| } finally { | ||
| sparkContext.stop() | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to make it more concise, just call this "sorted" and then everything fits in one line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done