@@ -304,6 +304,7 @@ mod test {
304304 } ;
305305 use arrow:: buffer:: NullBuffer ;
306306 use arrow:: compute:: CastOptions ;
307+ use arrow:: datatypes:: DataType :: { Int16 , Int32 , Int64 , UInt16 , UInt32 , UInt64 , UInt8 } ;
307308 use arrow_schema:: { DataType , Field , FieldRef , Fields } ;
308309 use parquet_variant:: { Variant , VariantPath , EMPTY_VARIANT_METADATA_BYTES } ;
309310
@@ -661,19 +662,6 @@ mod test {
661662 numeric_perfectly_shredded_test ! ( f64 , perfectly_shredded_float64_variant_array) ;
662663 }
663664
664- /// Shredding: Extract the typed value as Int32Array
665- #[ test]
666- fn get_variant_perfectly_shredded_int32_as_int32 ( ) {
667- // Extract the typed value as Int32Array
668- let array = perfectly_shredded_int32_variant_array ( ) ;
669- // specify we want the typed value as Int32
670- let field = Field :: new ( "typed_value" , DataType :: Int32 , true ) ;
671- let options = GetOptions :: new ( ) . with_as_type ( Some ( FieldRef :: from ( field) ) ) ;
672- let result = variant_get ( & array, options) . unwrap ( ) ;
673- let expected: ArrayRef = Arc :: new ( Int32Array :: from ( vec ! [ Some ( 1 ) , Some ( 2 ) , Some ( 3 ) ] ) ) ;
674- assert_eq ! ( & result, & expected)
675- }
676-
677665 /// AllNull: extract a value as a VariantArray
678666 #[ test]
679667 fn get_variant_all_null_as_variant ( ) {
@@ -708,18 +696,69 @@ mod test {
708696 assert_eq ! ( & result, & expected)
709697 }
710698
711- #[ test]
712- fn get_variant_perfectly_shredded_int16_as_int16 ( ) {
713- // Extract the typed value as Int16Array
714- let array = perfectly_shredded_int16_variant_array ( ) ;
715- // specify we want the typed value as Int16
716- let field = Field :: new ( "typed_value" , DataType :: Int16 , true ) ;
717- let options = GetOptions :: new ( ) . with_as_type ( Some ( FieldRef :: from ( field) ) ) ;
718- let result = variant_get ( & array, options) . unwrap ( ) ;
719- let expected: ArrayRef = Arc :: new ( Int16Array :: from ( vec ! [ Some ( 1 ) , Some ( 2 ) , Some ( 3 ) ] ) ) ;
720- assert_eq ! ( & result, & expected)
699+ macro_rules! perfectly_shredded_to_arrow_primitive_test {
700+ ( $name: ident, $primitive_type: ident, $perfectly_shredded_array_gen_fun: ident, $expected_array: expr) => {
701+ #[ test]
702+ fn $name( ) {
703+ let array = $perfectly_shredded_array_gen_fun( ) ;
704+ let field = Field :: new( "typed_value" , $primitive_type, true ) ;
705+ let options = GetOptions :: new( ) . with_as_type( Some ( FieldRef :: from( field) ) ) ;
706+ let result = variant_get( & array, options) . unwrap( ) ;
707+ let expected_array: ArrayRef = Arc :: new( $expected_array) ;
708+ assert_eq!( & result, & expected_array) ;
709+ }
710+ } ;
721711 }
722712
713+ perfectly_shredded_to_arrow_primitive_test ! (
714+ get_variant_perfectly_shredded_int16_as_int16,
715+ Int16 ,
716+ perfectly_shredded_int16_variant_array,
717+ Int16Array :: from( vec![ Some ( 1 ) , Some ( 2 ) , Some ( 3 ) ] )
718+ ) ;
719+
720+ perfectly_shredded_to_arrow_primitive_test ! (
721+ get_variant_perfectly_shredded_int32_as_int32,
722+ Int32 ,
723+ perfectly_shredded_int32_variant_array,
724+ Int32Array :: from( vec![ Some ( 1 ) , Some ( 2 ) , Some ( 3 ) ] )
725+ ) ;
726+
727+ perfectly_shredded_to_arrow_primitive_test ! (
728+ get_variant_perfectly_shredded_int64_as_int64,
729+ Int64 ,
730+ perfectly_shredded_int64_variant_array,
731+ Int64Array :: from( vec![ Some ( 1 ) , Some ( 2 ) , Some ( 3 ) ] )
732+ ) ;
733+
734+ perfectly_shredded_to_arrow_primitive_test ! (
735+ get_variant_perfectly_shredded_uint8_as_int8,
736+ UInt8 ,
737+ perfectly_shredded_uint8_variant_array,
738+ UInt8Array :: from( vec![ Some ( 1 ) , Some ( 2 ) , Some ( 3 ) ] )
739+ ) ;
740+
741+ perfectly_shredded_to_arrow_primitive_test ! (
742+ get_variant_perfectly_shredded_uint16_as_uint16,
743+ UInt16 ,
744+ perfectly_shredded_uint16_variant_array,
745+ UInt16Array :: from( vec![ Some ( 1 ) , Some ( 2 ) , Some ( 3 ) ] )
746+ ) ;
747+
748+ perfectly_shredded_to_arrow_primitive_test ! (
749+ get_variant_perfectly_shredded_uint32_as_uint32,
750+ UInt32 ,
751+ perfectly_shredded_uint32_variant_array,
752+ UInt32Array :: from( vec![ Some ( 1 ) , Some ( 2 ) , Some ( 3 ) ] )
753+ ) ;
754+
755+ perfectly_shredded_to_arrow_primitive_test ! (
756+ get_variant_perfectly_shredded_uint64_as_uint64,
757+ UInt64 ,
758+ perfectly_shredded_uint64_variant_array,
759+ UInt64Array :: from( vec![ Some ( 1 ) , Some ( 2 ) , Some ( 3 ) ] )
760+ ) ;
761+
723762 /// Return a VariantArray that represents a perfectly "shredded" variant
724763 /// for the given typed value.
725764 ///
0 commit comments