@@ -5,6 +5,7 @@ use std::ops::Range;
55use std:: sync:: Arc ;
66use std:: sync:: Weak ;
77
8+ use arrow_array:: RecordBatchOptions ;
89use arrow_schema:: Field ;
910use arrow_schema:: Schema ;
1011use datafusion_common:: DataFusionError ;
@@ -460,9 +461,13 @@ impl FileOpener for VortexOpener {
460461 batch. and_then ( |b| projector. project_batch ( & b) )
461462 } ?;
462463
463- batch
464- . with_schema ( Arc :: clone ( & output_schema) )
465- . map_err ( Into :: into)
464+ let ( _, columns, row_count) = batch. into_parts ( ) ;
465+ RecordBatch :: try_new_with_options (
466+ Arc :: clone ( & output_schema) ,
467+ columns,
468+ & RecordBatchOptions :: new ( ) . with_row_count ( Some ( row_count) ) ,
469+ )
470+ . map_err ( Into :: into)
466471 } )
467472 . boxed ( ) ;
468473
@@ -577,6 +582,7 @@ mod tests {
577582 use arrow_schema:: Fields ;
578583 use arrow_schema:: SchemaRef ;
579584 use datafusion:: arrow:: array:: DictionaryArray ;
585+ use datafusion:: arrow:: array:: Int32Array ;
580586 use datafusion:: arrow:: array:: RecordBatch ;
581587 use datafusion:: arrow:: array:: StringArray ;
582588 use datafusion:: arrow:: array:: StructArray ;
@@ -877,6 +883,34 @@ mod tests {
877883 Ok ( ( ) )
878884 }
879885
886+ #[ tokio:: test]
887+ async fn test_open_all_valid_nullable_columns_with_nonnullable_table_schema ( )
888+ -> anyhow:: Result < ( ) > {
889+ let object_store = Arc :: new ( InMemory :: new ( ) ) as Arc < dyn ObjectStore > ;
890+ let file_path = "nullable/file.vortex" ;
891+ let batch = RecordBatch :: try_new (
892+ Arc :: new ( Schema :: new ( vec ! [ Field :: new( "a" , DataType :: Int32 , true ) ] ) ) ,
893+ vec ! [ Arc :: new( Int32Array :: from( vec![ Some ( 1 ) , Some ( 2 ) , Some ( 3 ) ] ) ) ] ,
894+ ) ?;
895+ let data_size = write_arrow_to_vortex ( Arc :: clone ( & object_store) , file_path, batch) . await ?;
896+
897+ let expected_schema = Arc :: new ( Schema :: new ( vec ! [ Field :: new( "a" , DataType :: Int32 , false ) ] ) ) ;
898+ let table_schema = TableSchema :: from_file_schema ( Arc :: clone ( & expected_schema) ) ;
899+
900+ for projection_pushdown in [ false , true ] {
901+ let mut opener = make_opener ( Arc :: clone ( & object_store) , table_schema. clone ( ) , None ) ;
902+ opener. projection_pushdown = projection_pushdown;
903+
904+ let file = PartitionedFile :: new ( file_path. to_string ( ) , data_size) ;
905+ let batches = opener. open ( file) ?. await ?. try_collect :: < Vec < _ > > ( ) . await ?;
906+
907+ assert_eq ! ( batches. len( ) , 1 ) ;
908+ assert_eq ! ( batches[ 0 ] . schema( ) . as_ref( ) , expected_schema. as_ref( ) ) ;
909+ }
910+
911+ Ok ( ( ) )
912+ }
913+
880914 #[ tokio:: test]
881915 async fn test_file_pruning_replaces_partition_columns_without_file_statistics ( )
882916 -> anyhow:: Result < ( ) > {
0 commit comments