@@ -16,12 +16,13 @@ use vortex_array::arrays::{
1616} ;
1717use vortex_array:: stream:: ArrayStreamExt ;
1818use vortex_array:: validity:: Validity ;
19- use vortex_array:: { Array , IntoArray , ToCanonical } ;
19+ use vortex_array:: { Array , ArrayRef , IntoArray , ToCanonical } ;
2020use vortex_buffer:: { Buffer , ByteBufferMut , buffer} ;
2121use vortex_dtype:: PType :: I32 ;
2222use vortex_dtype:: { DType , DecimalDType , Nullability , PType , StructFields } ;
2323use vortex_error:: VortexResult ;
24- use vortex_expr:: { and, eq, get_item, gt, gt_eq, lit, lt, lt_eq, or, root, select} ;
24+ use vortex_expr:: { PackExpr , and, eq, get_item, gt, gt_eq, lit, lt, lt_eq, or, root, select} ;
25+ use vortex_layout:: scan:: ScanBuilder ;
2526use vortex_scalar:: Scalar ;
2627
2728use crate :: { V1_FOOTER_FBS_SIZE , VERSION , VortexFile , VortexOpenOptions , VortexWriteOptions } ;
@@ -1149,6 +1150,26 @@ async fn write_nullable_top_level_struct() {
11491150 . unwrap ( ) ;
11501151}
11511152
1153+ async fn round_trip (
1154+ array : & dyn Array ,
1155+ f : impl Fn ( ScanBuilder < ArrayRef > ) -> VortexResult < ScanBuilder < ArrayRef > > ,
1156+ ) -> VortexResult < ArrayRef > {
1157+ let buffer: Bytes = VortexWriteOptions :: default ( )
1158+ . write ( vec ! [ ] , array. to_array_stream ( ) )
1159+ . await ?
1160+ . into ( ) ;
1161+
1162+ let vxf = VortexOpenOptions :: in_memory ( )
1163+ . with_dtype ( array. dtype ( ) . clone ( ) )
1164+ . open ( buffer)
1165+ . await ?;
1166+
1167+ assert_eq ! ( vxf. dtype( ) , array. dtype( ) ) ;
1168+ assert_eq ! ( vxf. row_count( ) , array. len( ) as u64 ) ;
1169+
1170+ f ( vxf. scan ( ) ?) ?. into_array_stream ( ) ?. read_all ( ) . await
1171+ }
1172+
11521173#[ tokio:: test]
11531174async fn write_nullable_nested_struct ( ) -> VortexResult < ( ) > {
11541175 let nested_dtype = DType :: struct_ (
@@ -1169,25 +1190,7 @@ async fn write_nullable_nested_struct() -> VortexResult<()> {
11691190 ) ?
11701191 . into_array ( ) ;
11711192
1172- let buffer: Bytes = VortexWriteOptions :: default ( )
1173- . write ( vec ! [ ] , array. to_array_stream ( ) )
1174- . await ?
1175- . into ( ) ;
1176-
1177- let vxf = VortexOpenOptions :: in_memory ( )
1178- . with_dtype ( array. dtype ( ) . clone ( ) )
1179- . open ( buffer)
1180- . await ?;
1181-
1182- assert_eq ! ( vxf. dtype( ) , array. dtype( ) ) ;
1183- assert_eq ! ( vxf. row_count( ) , 3 ) ;
1184-
1185- let result = vxf
1186- . scan ( ) ?
1187- . into_array_stream ( ) ?
1188- . read_all ( )
1189- . await ?
1190- . to_struct ( ) ?;
1193+ let result = round_trip ( & array, Ok ) . await ?. to_struct ( ) ?;
11911194
11921195 assert_eq ! ( result. len( ) , 3 ) ;
11931196 assert_eq ! ( result. fields( ) . len( ) , 1 ) ;
@@ -1200,3 +1203,21 @@ async fn write_nullable_nested_struct() -> VortexResult<()> {
12001203
12011204 Ok ( ( ) )
12021205}
1206+
1207+ #[ tokio:: test]
1208+ async fn scan_empty_fields ( ) -> VortexResult < ( ) > {
1209+ let array = ( 0 ..10000 ) . collect :: < PrimitiveArray > ( ) ;
1210+
1211+ let result = round_trip ( array. as_ref ( ) , |scan| {
1212+ Ok ( scan. with_projection ( PackExpr :: try_new_expr (
1213+ Default :: default ( ) ,
1214+ vec ! [ ] ,
1215+ Nullability :: Nullable ,
1216+ ) ?) )
1217+ } )
1218+ . await ?;
1219+
1220+ assert_eq ! ( result. len( ) , array. len( ) ) ;
1221+
1222+ Ok ( ( ) )
1223+ }
0 commit comments