@@ -472,6 +472,23 @@ mod test {
472
472
numeric_partially_shredded_test ! ( f64 , partially_shredded_float64_variant_array) ;
473
473
}
474
474
475
+ #[ test]
476
+ fn get_variant_partially_shredded_bool_as_variant ( ) {
477
+ let array = partially_shredded_bool_variant_array ( ) ;
478
+ let options = GetOptions :: new ( ) ;
479
+ let result = variant_get ( & array, options) . unwrap ( ) ;
480
+
481
+ // expect the result is a VariantArray
482
+ let result: & VariantArray = result. as_any ( ) . downcast_ref ( ) . unwrap ( ) ;
483
+ assert_eq ! ( result. len( ) , 4 ) ;
484
+
485
+ // Expect the values are the same as the original values
486
+ assert_eq ! ( result. value( 0 ) , Variant :: from( true ) ) ;
487
+ assert ! ( !result. is_valid( 1 ) ) ;
488
+ assert_eq ! ( result. value( 2 ) , Variant :: from( "n/a" ) ) ;
489
+ assert_eq ! ( result. value( 3 ) , Variant :: from( false ) ) ;
490
+ }
491
+
475
492
/// Shredding: extract a value as an Int32Array
476
493
#[ test]
477
494
fn get_variant_shredded_int32_as_int32_safe_cast ( ) {
@@ -874,6 +891,52 @@ mod test {
874
891
f64
875
892
) ;
876
893
894
+ /// Return a VariantArray that represents a partially "shredded" variant for bool
895
+ fn partially_shredded_bool_variant_array ( ) -> ArrayRef {
896
+ let ( metadata, string_value) = {
897
+ let mut builder = parquet_variant:: VariantBuilder :: new ( ) ;
898
+ builder. append_value ( "n/a" ) ;
899
+ builder. finish ( )
900
+ } ;
901
+
902
+ let nulls = NullBuffer :: from ( vec ! [
903
+ true , // row 0 non null
904
+ false , // row 1 is null
905
+ true , // row 2 non null
906
+ true , // row 3 non null
907
+ ] ) ;
908
+
909
+ // metadata is the same for all rows
910
+ let metadata = BinaryViewArray :: from_iter_values ( std:: iter:: repeat_n ( & metadata, 4 ) ) ;
911
+
912
+ // See https://docs.google.com/document/d/1pw0AWoMQY3SjD7R4LgbPvMjG_xSCtXp3rZHkVp9jpZ4/edit?disco=AAABml8WQrY
913
+ // about why row1 is an empty but non null, value.
914
+ let values = BinaryViewArray :: from ( vec ! [
915
+ None , // row 0 is shredded, so no value
916
+ Some ( b"" as & [ u8 ] ) , // row 1 is null, so empty value (why?)
917
+ Some ( & string_value) , // copy the string value "N/A"
918
+ None , // row 3 is shredded, so no value
919
+ ] ) ;
920
+
921
+ let typed_value = arrow:: array:: BooleanArray :: from ( vec ! [
922
+ Some ( true ) , // row 0 is shredded, so it has a value
923
+ None , // row 1 is null, so no value
924
+ None , // row 2 is a string, so no typed value
925
+ Some ( false ) , // row 3 is shredded, so it has a value
926
+ ] ) ;
927
+
928
+ let struct_array = StructArrayBuilder :: new ( )
929
+ . with_field ( "metadata" , Arc :: new ( metadata) )
930
+ . with_field ( "typed_value" , Arc :: new ( typed_value) )
931
+ . with_field ( "value" , Arc :: new ( values) )
932
+ . with_nulls ( nulls)
933
+ . build ( ) ;
934
+
935
+ Arc :: new (
936
+ VariantArray :: try_new ( Arc :: new ( struct_array) ) . expect ( "should create variant array" ) ,
937
+ )
938
+ }
939
+
877
940
/// Builds struct arrays from component fields
878
941
///
879
942
/// TODO: move to arrow crate
0 commit comments