@@ -5343,9 +5343,7 @@ async fn test_insert_into_checking() -> Result<()> {
53435343 Ok ( ( ) )
53445344}
53455345
5346- #[ tokio:: test]
5347- async fn test_fill_null ( ) -> Result < ( ) > {
5348- // Create a simple table with nulls.
5346+ async fn create_null_table ( ) -> Result < DataFrame > {
53495347 let schema = Arc :: new ( Schema :: new ( vec ! [
53505348 Field :: new( "a" , DataType :: Int32 , true ) ,
53515349 Field :: new( "b" , DataType :: Utf8 , true ) ,
@@ -5361,6 +5359,12 @@ async fn test_fill_null() -> Result<()> {
53615359 let table = MemTable :: try_new ( schema. clone ( ) , vec ! [ vec![ batch] ] ) ?;
53625360 ctx. register_table ( "t_null" , Arc :: new ( table) ) ?;
53635361 let df = ctx. table ( "t_null" ) . await ?;
5362+ Ok ( df)
5363+ }
5364+
5365+ #[ tokio:: test]
5366+ async fn test_fill_null ( ) -> Result < ( ) > {
5367+ let df = create_null_table ( ) . await ?;
53645368
53655369 // Use fill_null to replace nulls on each column.
53665370 let df_filled = df
@@ -5383,3 +5387,42 @@ async fn test_fill_null() -> Result<()> {
53835387 assert_batches_sorted_eq ! ( expected, & results) ;
53845388 Ok ( ( ) )
53855389}
5390+
5391+ #[ tokio:: test]
5392+ async fn test_fill_null_all_columns ( ) -> Result < ( ) > {
5393+ let df = create_null_table ( ) . await ?;
5394+
5395+ // Use fill_null to replace nulls on all columns.
5396+ // Only column "b" will be replaced since ScalarValue::Utf8(Some("default".to_string()))
5397+ // can be cast to Utf8.
5398+ let df_filled = df. fill_null ( ScalarValue :: Utf8 ( Some ( "default" . to_string ( ) ) ) , None ) ?;
5399+
5400+ let results = df_filled. clone ( ) . collect ( ) . await ?;
5401+
5402+ let expected = vec ! [
5403+ "+---+---------+" ,
5404+ "| a | b |" ,
5405+ "+---+---------+" ,
5406+ "| 1 | x |" ,
5407+ "| | default |" ,
5408+ "| 3 | z |" ,
5409+ "+---+---------+" ,
5410+ ] ;
5411+
5412+ assert_batches_sorted_eq ! ( expected, & results) ;
5413+
5414+ let df_filled = df_filled. fill_null ( ScalarValue :: Int32 ( Some ( 0 ) ) , None ) ?;
5415+
5416+ let results = df_filled. collect ( ) . await ?;
5417+ let expected = vec ! [
5418+ "+---+---------+" ,
5419+ "| a | b |" ,
5420+ "+---+---------+" ,
5421+ "| 1 | x |" ,
5422+ "| 0 | default |" ,
5423+ "| 3 | z |" ,
5424+ "+---+---------+" ,
5425+ ] ;
5426+ assert_batches_sorted_eq ! ( expected, & results) ;
5427+ Ok ( ( ) )
5428+ }
0 commit comments