@@ -60,19 +60,19 @@ class SparkSchemaHelperTest extends FlatSpec with ParallelTestExecution with Mat
60
60
}
61
61
62
62
it should " construct optional type from Row of null" in {
63
- val r = new GenericRowWithSchema (Array (null , null , null , null , null , null , null , null ), structType[TestTypeOption ]())
63
+ val r = new GenericRowWithSchema (Array [ Any ] (null , null , null , null , null , null , null , null ), structType[TestTypeOption ]())
64
64
fromRow[TestTypeOption ](r) should be(
65
65
TestTypeOption (None , None , None , None , None , None , None , None ))
66
66
}
67
67
68
68
it should " construct optional type from Row of map values that can be null" in {
69
- val r = new GenericRowWithSchema (Array (null , null , null , null , Map (" foo" -> " row" , " bar" -> " a" ), null , null , null ), structType[TestTypeOption ]())
69
+ val r = new GenericRowWithSchema (Array [ Any ] (null , null , null , null , Map (" foo" -> " row" , " bar" -> " a" ), null , null , null ), structType[TestTypeOption ]())
70
70
fromRow[TestTypeOption ](r) should be(
71
71
TestTypeOption (None , None , None , None , Some (Map (" foo" -> " row" , " bar" -> " a" )), None , None , None ))
72
72
}
73
73
74
74
it should " construct optional type from Row of seq values that can be null" in {
75
- val r = new GenericRowWithSchema (Array (null , null , null , null , null , null , Seq (20L , null ), null ), structType[TestTypeOption ]())
75
+ val r = new GenericRowWithSchema (Array [ Any ] (null , null , null , null , null , null , Seq [ Any ] (20L , null ), null ), structType[TestTypeOption ]())
76
76
fromRow[TestTypeOption ](r) should be(
77
77
TestTypeOption (None , None , None , None , None , None , Some (Seq (Some (20 ), None )), None ))
78
78
}
@@ -96,13 +96,13 @@ class SparkSchemaHelperTest extends FlatSpec with ParallelTestExecution with Mat
96
96
}
97
97
98
98
it should " ignore null in map" in {
99
- val x = new GenericRowWithSchema (Array (null , null , null , null , Map (" foo" -> " row" , " bar" -> null ), null , null , null ), structType[TestTypeOption ]())
99
+ val x = new GenericRowWithSchema (Array [ Any ] (null , null , null , null , Map (" foo" -> " row" , " bar" -> null ), null , null , null ), structType[TestTypeOption ]())
100
100
val row = fromRow[TestTypeOption ](x)
101
101
row.x.get shouldBe Map (" foo" -> " row" )
102
102
}
103
103
104
104
it should " ignore missing fields" in {
105
- val x = new GenericRowWithSchema (Array (1 , 2 , null ), structType[TestTypeOptionalField ]())
105
+ val x = new GenericRowWithSchema (Array [ Any ] (1 , 2 , null ), structType[TestTypeOptionalField ]())
106
106
val row = fromRow[TestTypeOption ](x)
107
107
row.a shouldBe Some (1 )
108
108
row.b shouldBe Some (2 )
@@ -112,7 +112,7 @@ class SparkSchemaHelperTest extends FlatSpec with ParallelTestExecution with Mat
112
112
113
113
it should " correctly return OptionalField" in {
114
114
val x = new GenericRowWithSchema (
115
- Array (1 , null ),
115
+ Array [ Any ] (1 , null ),
116
116
StructType (Seq (
117
117
StructField (" a" , DataTypes .IntegerType ),
118
118
StructField (" b" , DataTypes .IntegerType , nullable = true )
@@ -124,34 +124,34 @@ class SparkSchemaHelperTest extends FlatSpec with ParallelTestExecution with Mat
124
124
}
125
125
126
126
it should " fail nicely on different type in map" in {
127
- val x = new GenericRowWithSchema (Array (null , null , null , null , Map (" foo" -> " row" , " bar" -> 1 ), null , null , null ), structType[TestTypeOption ]())
127
+ val x = new GenericRowWithSchema (Array [ Any ] (null , null , null , null , Map [ Any , Any ] (" foo" -> " row" , " bar" -> 1 ), null , null , null ), structType[TestTypeOption ]())
128
128
val ex = intercept[CdfSparkIllegalArgumentException ] { fromRow[TestTypeOption ](x) }
129
129
ex.getMessage shouldBe " Map with string values was expected, but '1' of type Int was found (under key 'bar' on row [null,null,null,null,Map(foo -> row, bar -> 1),null,null,null])"
130
130
}
131
131
132
132
it should " fail nicely on type mismatch" in {
133
- val x = new GenericRowWithSchema (Array (" shouldBeInt" , 2 .toDouble, 3 .toByte,
133
+ val x = new GenericRowWithSchema (Array [ Any ] (" shouldBeInt" , 2 .toDouble, 3 .toByte,
134
134
4 .toFloat, Map (" foo" -> " bar" ), 5 .toLong, Seq [Long ](10 ), " foo" ), structType[TestTypeBasic ]())
135
135
val ex = intercept[CdfSparkIllegalArgumentException ] { fromRow[TestTypeBasic ](x) }
136
136
ex.getMessage shouldBe " Column 'a' was expected to have type Int, but 'shouldBeInt' of type String was found (on row [shouldBeInt,2.0,3,4.0,Map(foo -> bar),5,List(10),foo])."
137
137
}
138
138
139
139
it should " fail nicely on unexpected NULL in int" in {
140
- val x = new GenericRowWithSchema (Array (null , 2 .toDouble, 3 .toByte,
140
+ val x = new GenericRowWithSchema (Array [ Any ] (null , 2 .toDouble, 3 .toByte,
141
141
4 .toFloat, Map (" foo" -> " bar" ), 5 .toLong, Seq [Long ](10 ), " foo" ), structType[TestTypeBasic ]())
142
142
val ex = intercept[CdfSparkIllegalArgumentException ] { fromRow[TestTypeBasic ](x) }
143
143
ex.getMessage shouldBe " Column 'a' was expected to have type Int, but NULL was found (on row [null,2.0,3,4.0,Map(foo -> bar),5,List(10),foo])."
144
144
}
145
145
146
146
it should " fail nicely on unexpected NULL in string" in {
147
- val x = new GenericRowWithSchema (Array (1 , 2 .toDouble, 3 .toByte,
147
+ val x = new GenericRowWithSchema (Array [ Any ] (1 , 2 .toDouble, 3 .toByte,
148
148
4 .toFloat, Map (" foo" -> " bar" ), 5 .toLong, Seq [Long ](10 ), null ), structType[TestTypeBasic ]())
149
149
val ex = intercept[CdfSparkIllegalArgumentException ] { fromRow[TestTypeBasic ](x) }
150
150
ex.getMessage shouldBe " Column 's' was expected to have type String, but NULL was found (on row [1,2.0,3,4.0,Map(foo -> bar),5,List(10),null])."
151
151
}
152
152
153
153
it should " fail nicely on unexpected NULL in map" in {
154
- val x = new GenericRowWithSchema (Array (1 , 2 .toDouble, 3 .toByte,
154
+ val x = new GenericRowWithSchema (Array [ Any ] (1 , 2 .toDouble, 3 .toByte,
155
155
4 .toFloat, null , 5 .toLong, Seq [Long ](10 ), " foo" ), structType[TestTypeBasic ]())
156
156
val ex = intercept[CdfSparkIllegalArgumentException ] { fromRow[TestTypeBasic ](x) }
157
157
ex.getMessage shouldBe " Column 'x' was expected to have type Map[String,String], but NULL was found (on row [1,2.0,3,4.0,null,5,List(10),foo])."
0 commit comments