Github user MLnick commented on a diff in the pull request:
https://github.com/apache/spark/pull/14321#discussion_r74426713
--- Diff:
core/src/test/scala/org/apache/spark/rdd/PairRDDFunctionsSuite.scala ---
@@ -168,6 +168,126 @@ class PairRDDFunctionsSuite extends SparkFunSuite
with SharedSparkContext {
}
}
+ test("randomSplitByKey exact") {
+ val defaultSeed = 1L
+
+ // vary RDD size
+ for (n <- List(100, 1000, 10000)) {
+ val data = sc.parallelize(1 to n, 2)
+ val fractionPositive = 0.3
+ val stratifiedData =
data.keyBy(StratifiedAuxiliary.stratifier(fractionPositive))
+ val keys = Array("0", "1")
+ val splitWeights = Array(0.3, 0.2, 0.5)
+ val weights: Array[scala.collection.Map[String, Double]] =
+ splitWeights.map(w => keys.map(k => (k, w)).toMap)
+ StratifiedAuxiliary.testSplits(stratifiedData, weights, defaultSeed,
n, true)
+ }
+
+ // vary fractionPositive
+ for (fractionPositive <- List(0.1, 0.3, 0.5, 0.7, 0.9)) {
+ val n = 100
+ val data = sc.parallelize(1 to n, 2)
+ val stratifiedData =
data.keyBy(StratifiedAuxiliary.stratifier(fractionPositive))
+ val keys = Array("0", "1")
+ val splitWeights = Array(0.3, 0.2, 0.5)
+ val weights: Array[scala.collection.Map[String, Double]] =
+ splitWeights.map(w => keys.map(k => (k, w)).toMap)
+ StratifiedAuxiliary.testSplits(stratifiedData, weights, defaultSeed,
n, true)
+ }
+
+ // use same data for remaining tests
+ val n = 100
+ val fractionPositive = 0.3
+ val data = sc.parallelize(1 to n, 2)
+ val stratifiedData =
data.keyBy(StratifiedAuxiliary.stratifier(fractionPositive))
+ val keys = Array("0", "1")
+
+ // use different weights for each key in the split
+ val unevenWeights: Array[scala.collection.Map[String, Double]] =
+ Array(Map("0" -> 0.2, "1" -> 0.3), Map("0" -> 0.1, "1" -> 0.4),
Map("0" -> 0.7, "1" -> 0.3))
+ StratifiedAuxiliary.testSplits(stratifiedData, unevenWeights,
defaultSeed, n, true)
+
+ // vary the seed
+ val splitWeights = Array(0.3, 0.2, 0.5)
+ val weights: Array[scala.collection.Map[String, Double]] =
+ splitWeights.map(w => keys.map(k => (k, w)).toMap)
+ for (seed <- defaultSeed to defaultSeed + 3L) {
+ StratifiedAuxiliary.testSplits(stratifiedData, weights, seed, n,
true)
+ }
+
+ // vary the number of splits
+ for (numSplits <- 1 to 3) {
+ val splitWeights = Array.fill(numSplits)(1.0) // check normalization
too
+ val weights: Array[scala.collection.Map[String, Double]] =
+ splitWeights.map(w => keys.map(k => (k, w)).toMap)
+ StratifiedAuxiliary.testSplits(stratifiedData, weights, defaultSeed,
n, true)
+ }
+ val thrown = intercept[IllegalArgumentException] {
+
stratifiedData.randomSplitByKey(Array.empty[scala.collection.Map[String,
Double]], true, 42L)
+ }
+ assert(thrown.getMessage.contains("weights cannot be empty"))
+ }
+
+ test("randomSplitByKey") {
+ val defaultSeed = 1L
+
+ // vary RDD size
+ for (n <- List(500, 1000, 10000)) {
+ val data = sc.parallelize(1 to n, 2)
+ val fractionPositive = 0.3
+ val stratifiedData =
data.keyBy(StratifiedAuxiliary.stratifier(fractionPositive))
+ val keys = Array("0", "1")
+ val splitWeights = Array(0.3, 0.2, 0.5)
+ val weights: Array[scala.collection.Map[String, Double]] =
+ splitWeights.map(w => keys.map(k => (k, w)).toMap)
+ StratifiedAuxiliary.testSplits(stratifiedData, weights, defaultSeed,
n, false)
+ }
+
+ // vary fractionPositive
+ for (fractionPositive <- List(0.1, 0.3, 0.5, 0.7, 0.9)) {
+ val n = 500
--- End diff --
I notice this is `500` vs `100` in the exact test. Is the difference
intentional?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]