@@ -212,7 +212,14 @@ impl RecordBatch {
212
212
} )
213
213
. collect :: < Result < Vec < _ > > > ( ) ?;
214
214
215
- RecordBatch :: try_new ( SchemaRef :: new ( projected_schema) , batch_fields)
215
+ RecordBatch :: try_new_with_options (
216
+ SchemaRef :: new ( projected_schema) ,
217
+ batch_fields,
218
+ & RecordBatchOptions {
219
+ match_field_names : true ,
220
+ row_count : Some ( self . row_count ) ,
221
+ } ,
222
+ )
216
223
}
217
224
218
225
/// Returns the number of columns in the record batch.
@@ -865,6 +872,26 @@ mod tests {
865
872
assert_eq ! ( expected, record_batch. project( & [ 0 , 2 ] ) . unwrap( ) ) ;
866
873
}
867
874
875
+ #[ test]
876
+ fn project_empty ( ) {
877
+ let c: ArrayRef = Arc :: new ( StringArray :: from ( vec ! [ "d" , "e" , "f" ] ) ) ;
878
+
879
+ let record_batch =
880
+ RecordBatch :: try_from_iter ( vec ! [ ( "c" , c. clone( ) ) ] ) . expect ( "valid conversion" ) ;
881
+
882
+ let expected = RecordBatch :: try_new_with_options (
883
+ Arc :: new ( Schema :: empty ( ) ) ,
884
+ vec ! [ ] ,
885
+ & RecordBatchOptions {
886
+ match_field_names : true ,
887
+ row_count : Some ( 3 ) ,
888
+ } ,
889
+ )
890
+ . expect ( "valid conversion" ) ;
891
+
892
+ assert_eq ! ( expected, record_batch. project( & [ ] ) . unwrap( ) ) ;
893
+ }
894
+
868
895
#[ test]
869
896
fn test_no_column_record_batch ( ) {
870
897
let schema = Arc :: new ( Schema :: new ( vec ! [ ] ) ) ;
0 commit comments