@@ -2,28 +2,35 @@ package frameless
2
2
3
3
import com .globalmentor .apache .hadoop .fs .BareLocalFileSystem
4
4
import org .apache .hadoop .fs .local .StreamingFS
5
- import org .apache .spark .{SparkConf , SparkContext }
6
- import org .apache .spark .sql .{SQLContext , SparkSession }
5
+ import org .apache .spark .{ SparkConf , SparkContext }
6
+ import org .apache .spark .sql .{ SQLContext , SparkSession }
7
7
import org .scalactic .anyvals .PosZInt
8
8
import org .scalatest .BeforeAndAfterAll
9
9
import org .scalatestplus .scalacheck .Checkers
10
10
import org .scalacheck .Prop
11
11
import org .scalacheck .Prop ._
12
12
13
- import scala .util .{Properties , Try }
13
+ import scala .util .{ Properties , Try }
14
14
import org .scalatest .funsuite .AnyFunSuite
15
15
16
16
trait SparkTesting { self : BeforeAndAfterAll =>
17
17
18
- val appID : String = new java.util.Date ().toString + math.floor(math.random * 10E4 ).toLong.toString
18
+ val appID : String = new java.util.Date ().toString + math
19
+ .floor(math.random * 10e4 )
20
+ .toLong
21
+ .toString
19
22
20
23
/**
21
24
* Allows bare naked to be used instead of winutils for testing / dev
22
25
*/
23
26
def registerFS (sparkConf : SparkConf ): SparkConf = {
24
27
if (System .getProperty(" os.name" ).startsWith(" Windows" ))
25
- sparkConf.set(" spark.hadoop.fs.file.impl" , classOf [BareLocalFileSystem ].getName).
26
- set(" spark.hadoop.fs.AbstractFileSystem.file.impl" , classOf [StreamingFS ].getName)
28
+ sparkConf
29
+ .set(" spark.hadoop.fs.file.impl" , classOf [BareLocalFileSystem ].getName)
30
+ .set(
31
+ " spark.hadoop.fs.AbstractFileSystem.file.impl" ,
32
+ classOf [StreamingFS ].getName
33
+ )
27
34
else
28
35
sparkConf
29
36
}
@@ -33,16 +40,20 @@ trait SparkTesting { self: BeforeAndAfterAll =>
33
40
.setAppName(" test" )
34
41
.set(" spark.ui.enabled" , " false" )
35
42
.set(" spark.app.id" , appID)
43
+ .set(
44
+ " spark.sql.ansi.enabled" ,
45
+ " false"
46
+ ) // 43 tests fail on overflow / casting issues
36
47
37
48
private var s : SparkSession = _
38
49
39
50
implicit def session : SparkSession = s
40
51
implicit def sc : SparkContext = session.sparkContext
41
52
implicit def sqlContext : SQLContext = session.sqlContext
42
53
43
- def registerOptimizations (sqlContext : SQLContext ): Unit = { }
54
+ def registerOptimizations (sqlContext : SQLContext ): Unit = {}
44
55
45
- def addSparkConfigProperties (config : SparkConf ): Unit = { }
56
+ def addSparkConfigProperties (config : SparkConf ): Unit = {}
46
57
47
58
override def beforeAll (): Unit = {
48
59
assert(s == null )
@@ -59,11 +70,16 @@ trait SparkTesting { self: BeforeAndAfterAll =>
59
70
}
60
71
}
61
72
73
+ class TypedDatasetSuite
74
+ extends AnyFunSuite
75
+ with Checkers
76
+ with BeforeAndAfterAll
77
+ with SparkTesting {
62
78
63
- class TypedDatasetSuite extends AnyFunSuite with Checkers with BeforeAndAfterAll with SparkTesting {
64
79
// Limit size of generated collections and number of checks to avoid OutOfMemoryError
65
80
implicit override val generatorDrivenConfig : PropertyCheckConfiguration = {
66
- def getPosZInt (name : String , default : PosZInt ) = Properties .envOrNone(s " FRAMELESS_GEN_ ${name}" )
81
+ def getPosZInt (name : String , default : PosZInt ) = Properties
82
+ .envOrNone(s " FRAMELESS_GEN_ ${name}" )
67
83
.flatMap(s => Try (s.toInt).toOption)
68
84
.flatMap(PosZInt .from)
69
85
.getOrElse(default)
@@ -75,17 +91,24 @@ class TypedDatasetSuite extends AnyFunSuite with Checkers with BeforeAndAfterAll
75
91
76
92
implicit val sparkDelay : SparkDelay [Job ] = Job .framelessSparkDelayForJob
77
93
78
- def approximatelyEqual [A ](a : A , b : A )(implicit numeric : Numeric [A ]): Prop = {
94
+ def approximatelyEqual [A ](
95
+ a : A ,
96
+ b : A
97
+ )(implicit
98
+ numeric : Numeric [A ]
99
+ ): Prop = {
79
100
val da = numeric.toDouble(a)
80
101
val db = numeric.toDouble(b)
81
- val epsilon = 1E -6
102
+ val epsilon = 1e -6
82
103
// Spark has a weird behaviour concerning expressions that should return Inf
83
104
// Most of the time they return NaN instead, for instance stddev of Seq(-7.827553978923477E227, -5.009124275715786E153)
84
- if ((da.isNaN || da.isInfinity) && (db.isNaN || db.isInfinity)) proved
105
+ if ((da.isNaN || da.isInfinity) && (db.isNaN || db.isInfinity)) proved
85
106
else if (
86
107
(da - db).abs < epsilon ||
87
- (da - db).abs < da.abs / 100 )
88
- proved
89
- else falsified :| s " Expected $a but got $b, which is more than 1% off and greater than epsilon = $epsilon. "
108
+ (da - db).abs < da.abs / 100
109
+ )
110
+ proved
111
+ else
112
+ falsified :| s " Expected $a but got $b, which is more than 1% off and greater than epsilon = $epsilon. "
90
113
}
91
114
}
0 commit comments