Skip to content

Commit 4d70ebf

Browse files
committed
Move dataset generator test forward to 2.x+ only, add release notes.
1 parent 1330816 commit 4d70ebf

File tree

3 files changed

+59
-40
lines changed

3 files changed

+59
-40
lines changed

RELEASE_NOTES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 0.10.0
2+
- Add support for Spark 2.3.1, 2.1.3
3+
- Add better sized generators
4+
- Improve logging for differing output sizes
5+
# 0.9.0
6+
- Add Spark 2.1.2
7+
- Add Spark 2.3.0
18
# 0.8.1
29
- Add support for Spark 2.2.1
310
# 0.8.0

src/test/1.6/scala/com/holdenkarau/spark/testing/SampleDatasetGeneratorTest.scala

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -64,46 +64,6 @@ class SampleDatasetGeneratorTest extends FunSuite
6464

6565
check(property)
6666
}
67-
68-
test("test generating sized Datasets[Custom Class]") {
69-
val sqlContext = new SQLContext(sc)
70-
import sqlContext.implicits._
71-
72-
// In 2.3 List is fine, however in 2.0 and earlier the generator returns
73-
// a concrete sub type which isn't handled well.
74-
val carGen: Gen[Dataset[Seq[Car]]] =
75-
DatasetGenerator.genSizedDataset[Seq[Car]](sqlContext) { size =>
76-
val slowCarsTopNumber = math.ceil(size * 0.1).toInt
77-
def carGenerator(speed: Gen[Int]): Gen[Car] = for {
78-
name <- Arbitrary.arbitrary[String]
79-
speed <- speed
80-
} yield Car(name, speed)
81-
82-
val cars: Gen[List[Car]] = for {
83-
slowCarsNumber: Int <- Gen.choose(0, slowCarsTopNumber)
84-
slowCars: List[Car] <- Gen.listOfN(slowCarsNumber, carGenerator(Gen.choose(0, 20)))
85-
normalSpeedCars: List[Car] <- Gen.listOfN(
86-
size - slowCarsNumber,
87-
carGenerator(Gen.choose(21, 150))
88-
)
89-
} yield {
90-
slowCars ++ normalSpeedCars
91-
}
92-
cars
93-
}
94-
95-
val property =
96-
forAll(carGen.map(_.flatMap(identity))) {
97-
dataset =>
98-
val cars = dataset.collect()
99-
val dataSetSize = cars.length
100-
val slowCars = cars.filter(_.speed < 21)
101-
slowCars.length <= dataSetSize * 0.1 &&
102-
cars.map(_.speed).length == dataSetSize
103-
}
104-
105-
check(property)
106-
}
10767
}
10868

10969
case class Car(name: String, speed: Int)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.holdenkarau.spark.testing
2+
3+
import org.apache.spark.sql.{Dataset, SQLContext}
4+
import org.scalacheck.{Gen, Arbitrary}
5+
import org.scalacheck.Prop.forAll
6+
import org.scalatest.FunSuite
7+
import org.scalatest.prop.Checkers
8+
9+
class DatasetGeneratorSizeSpecial extends FunSuite
10+
with SharedSparkContext with Checkers {
11+
12+
test("test generating sized Datasets[Custom Class]") {
13+
val sqlContext = new SQLContext(sc)
14+
import sqlContext.implicits._
15+
16+
// In 2.3 List is fine, however prior to 2.1 the generator returns
17+
// a concrete sub type which isn't handled well.
18+
// This works in 1.6.1+ but we only test in 2.0+ because that's easier
19+
val carGen: Gen[Dataset[Seq[Car]]] =
20+
DatasetGenerator.genSizedDataset[Seq[Car]](sqlContext) { size =>
21+
val slowCarsTopNumber = math.ceil(size * 0.1).toInt
22+
def carGenerator(speed: Gen[Int]): Gen[Car] = for {
23+
name <- Arbitrary.arbitrary[String]
24+
speed <- speed
25+
} yield Car(name, speed)
26+
27+
val cars: Gen[List[Car]] = for {
28+
slowCarsNumber: Int <- Gen.choose(0, slowCarsTopNumber)
29+
slowCars: List[Car] <- Gen.listOfN(slowCarsNumber, carGenerator(Gen.choose(0, 20)))
30+
normalSpeedCars: List[Car] <- Gen.listOfN(
31+
size - slowCarsNumber,
32+
carGenerator(Gen.choose(21, 150))
33+
)
34+
} yield {
35+
slowCars ++ normalSpeedCars
36+
}
37+
cars
38+
}
39+
40+
val property =
41+
forAll(carGen.map(_.flatMap(identity))) {
42+
dataset =>
43+
val cars = dataset.collect()
44+
val dataSetSize = cars.length
45+
val slowCars = cars.filter(_.speed < 21)
46+
slowCars.length <= dataSetSize * 0.1 &&
47+
cars.map(_.speed).length == dataSetSize
48+
}
49+
50+
check(property)
51+
}
52+
}

0 commit comments

Comments
 (0)