@@ -309,6 +309,7 @@ mod tests {
309309 use vortex_array:: IntoArray ;
310310 use vortex_array:: LEGACY_SESSION ;
311311 use vortex_array:: Precision ;
312+ use vortex_array:: VTable ;
312313 use vortex_array:: VortexSessionExecute ;
313314 use vortex_array:: arrays:: PrimitiveArray ;
314315 use vortex_array:: arrays:: VarBinViewArray ;
@@ -364,6 +365,44 @@ mod tests {
364365 . unwrap ( )
365366 }
366367
368+ fn typed_value_variant_array ( ) -> VortexResult < ArrayRef > {
369+ let mut metadata = BinaryViewBuilder :: new ( ) ;
370+ for _ in 0 ..3 {
371+ metadata. append_value ( b"\x01 \x00 " ) ;
372+ }
373+ let metadata: ArrowArrayRef = Arc :: new ( metadata. finish ( ) ) ;
374+ let typed_value: ArrowArrayRef = Arc :: new ( Int32Array :: from ( vec ! [ 10 , 20 , 30 ] ) ) ;
375+ let arrow_storage = StructArray :: try_new (
376+ vec ! [
377+ Arc :: new( Field :: new( "metadata" , DataType :: BinaryView , false ) ) ,
378+ Arc :: new( Field :: new( "typed_value" , DataType :: Int32 , false ) ) ,
379+ ]
380+ . into ( ) ,
381+ vec ! [ metadata, typed_value] ,
382+ None ,
383+ ) ?;
384+
385+ ParquetVariant :: from_arrow_variant ( & ArrowVariantArray :: try_new ( & arrow_storage) ?)
386+ }
387+
388+ fn parquet_variant_file_session ( ) -> VortexSession {
389+ let session = VortexSession :: empty ( )
390+ . with :: < ArraySession > ( )
391+ . with :: < LayoutSession > ( )
392+ . with :: < RuntimeSession > ( ) ;
393+ vortex_file:: register_default_encodings ( & session) ;
394+ session. arrays ( ) . register ( ParquetVariant ) ;
395+ session
396+ }
397+
398+ fn write_strategy_with_parquet_variant ( ) -> Arc < dyn vortex_layout:: LayoutStrategy > {
399+ let mut allowed = vortex_file:: ALLOWED_ENCODINGS . clone ( ) ;
400+ allowed. insert ( ParquetVariant . id ( ) ) ;
401+ vortex_file:: WriteStrategyBuilder :: default ( )
402+ . with_allow_encodings ( allowed)
403+ . build ( )
404+ }
405+
367406 #[ test]
368407 fn test_execute_exposes_typed_value_as_canonical_shredded ( ) -> VortexResult < ( ) > {
369408 let metadata =
@@ -405,37 +444,38 @@ mod tests {
405444 }
406445
407446 #[ tokio:: test]
408- async fn test_file_roundtrip_typed_value_variant ( ) -> VortexResult < ( ) > {
409- let mut metadata = BinaryViewBuilder :: new ( ) ;
410- for _ in 0 ..3 {
411- metadata. append_value ( b"\x01 \x00 " ) ;
412- }
413- let metadata: ArrowArrayRef = Arc :: new ( metadata. finish ( ) ) ;
414- let typed_value: ArrowArrayRef = Arc :: new ( Int32Array :: from ( vec ! [ 10 , 20 , 30 ] ) ) ;
415- let arrow_storage = StructArray :: try_new (
416- vec ! [
417- Arc :: new( Field :: new( "metadata" , DataType :: BinaryView , false ) ) ,
418- Arc :: new( Field :: new( "typed_value" , DataType :: Int32 , false ) ) ,
419- ]
420- . into ( ) ,
421- vec ! [ metadata, typed_value] ,
422- None ,
423- ) ?;
424- let expected =
425- ParquetVariant :: from_arrow_variant ( & ArrowVariantArray :: try_new ( & arrow_storage) ?) ?;
426-
427- let session = VortexSession :: empty ( )
428- . with :: < ArraySession > ( )
429- . with :: < LayoutSession > ( )
430- . with :: < RuntimeSession > ( ) ;
431- vortex_file:: register_default_encodings ( & session) ;
432- session. arrays ( ) . register ( ParquetVariant ) ;
447+ async fn test_file_roundtrip_typed_value_variant_with_statistics ( ) -> VortexResult < ( ) > {
448+ let expected = typed_value_variant_array ( ) ?;
449+ let session = parquet_variant_file_session ( ) ;
433450
434451 let mut bytes = ByteBufferMut :: empty ( ) ;
435452 session
436453 . write_options ( )
437454 . with_strategy ( Arc :: new ( FlatLayoutStrategy :: default ( ) ) )
438- . with_file_statistics ( Vec :: new ( ) )
455+ . write ( & mut bytes, expected. to_array_stream ( ) )
456+ . await ?;
457+
458+ let actual = session
459+ . open_options ( )
460+ . open_buffer ( bytes) ?
461+ . scan ( ) ?
462+ . into_array_stream ( ) ?
463+ . read_all ( )
464+ . await ?;
465+
466+ assert_arrays_eq ! ( expected, actual) ;
467+ Ok ( ( ) )
468+ }
469+
470+ #[ tokio:: test]
471+ async fn test_file_roundtrip_typed_value_variant_with_zoned_strategy ( ) -> VortexResult < ( ) > {
472+ let expected = typed_value_variant_array ( ) ?;
473+ let session = parquet_variant_file_session ( ) ;
474+
475+ let mut bytes = ByteBufferMut :: empty ( ) ;
476+ session
477+ . write_options ( )
478+ . with_strategy ( write_strategy_with_parquet_variant ( ) )
439479 . write ( & mut bytes, expected. to_array_stream ( ) )
440480 . await ?;
441481
0 commit comments