@@ -21,7 +21,6 @@ import scala.collection.JavaConverters._
2121
2222import org .apache .spark .sql .internal .SQLConf
2323import org .apache .spark .sql .test .SharedSQLContext
24- import org .apache .spark .sql .types ._
2524
2625class DataFrameNaFunctionsSuite extends QueryTest with SharedSQLContext {
2726 import testImplicits ._
@@ -233,10 +232,10 @@ class DataFrameNaFunctionsSuite extends QueryTest with SharedSQLContext {
233232 }
234233
235234 test(" replace" ) {
236- val input1 = createDF()
235+ val input = createDF()
237236
238237 // Replace two numeric columns: age and height
239- val out = input1 .na.replace(Seq (" age" , " height" ), Map (
238+ val out = input .na.replace(Seq (" age" , " height" ), Map (
240239 16 -> 61 ,
241240 60 -> 6 ,
242241 164.3 -> 461.3 // Alice is really tall
@@ -249,8 +248,8 @@ class DataFrameNaFunctionsSuite extends QueryTest with SharedSQLContext {
249248 assert(out(4 ) === Row (" Amy" , null , null ))
250249 assert(out(5 ) === Row (null , null , null ))
251250
252- // Replace only the age column and with null
253- val out1 = input1 .na.replace(" age" , Map [Any , Any ](
251+ // Replace only the age column
252+ val out1 = input .na.replace(" age" , Map [Any , Any ](
254253 16 -> 61 ,
255254 60 -> null ,
256255 164.3 -> 461.3 // Alice is really tall
@@ -262,19 +261,5 @@ class DataFrameNaFunctionsSuite extends QueryTest with SharedSQLContext {
262261 assert(out1(3 ).get(2 ).asInstanceOf [Double ].isNaN)
263262 assert(out1(4 ) === Row (" Amy" , null , null ))
264263 assert(out1(5 ) === Row (null , null , null ))
265-
266- // Replace with null on a column that is not nullable
267- val rows = spark.sparkContext.parallelize(Seq (
268- Row (" Bravo" , 28 , 183.5 ),
269- Row (" Jessie" , 18 , 165.8 )))
270- val schema = StructType (Seq (
271- StructField (" name" , StringType , nullable = false ),
272- StructField (" age" , IntegerType , nullable = true ),
273- StructField (" height" , DoubleType , nullable = true )))
274- val input2 = spark.createDataFrame(rows, schema)
275- val message = intercept[IllegalArgumentException ] {
276- input2.na.replace(" name" , Map (" Bravo" -> null ))
277- }.getMessage
278- assert(message === " Column 'name' is not nullable and can not be replaced to null." )
279264 }
280265}
0 commit comments