@@ -51,17 +51,12 @@ pub(crate) fn binary_array_value(array: &dyn Array, index: usize) -> Option<&[u8
5151 }
5252}
5353
54- /// Returns `true` if the data type is `Binary`, `LargeBinary`, or `BinaryView`.
55- fn is_binary_like ( dt : & DataType ) -> bool {
56- matches ! (
57- dt,
58- DataType :: Binary | DataType :: LargeBinary | DataType :: BinaryView
59- )
60- }
61-
6254/// Validates that an array has a binary-like data type.
6355fn validate_binary_array ( array : & dyn Array , field_name : & str ) -> Result < ( ) > {
64- if is_binary_like ( array. data_type ( ) ) {
56+ if matches ! (
57+ array. data_type( ) ,
58+ DataType :: Binary | DataType :: LargeBinary | DataType :: BinaryView
59+ ) {
6560 Ok ( ( ) )
6661 } else {
6762 Err ( ArrowError :: InvalidArgumentError ( format ! (
@@ -397,10 +392,19 @@ impl VariantArray {
397392 }
398393 // Otherwise fall back to value, if available
399394 ( _, Some ( value) ) if value. is_valid ( index) => {
400- let metadata = binary_array_value ( self . metadata . as_ref ( ) , index)
401- . expect ( "metadata field must be a binary-like array" ) ;
402- let value = binary_array_value ( value. as_ref ( ) , index)
403- . expect ( "value field must be a binary-like array" ) ;
395+ let metadata =
396+ binary_array_value ( self . metadata . as_ref ( ) , index) . ok_or_else ( || {
397+ ArrowError :: InvalidArgumentError ( format ! (
398+ "metadata field must be a binary-like array, instead got {}" ,
399+ self . metadata. data_type( ) ,
400+ ) )
401+ } ) ?;
402+ let value = binary_array_value ( value. as_ref ( ) , index) . ok_or_else ( || {
403+ ArrowError :: InvalidArgumentError ( format ! (
404+ "value field must be a binary-like array, instead got {}" ,
405+ value. data_type( ) ,
406+ ) )
407+ } ) ?;
404408 Ok ( Variant :: new ( metadata, value) )
405409 }
406410 // It is technically invalid for neither value nor typed_value fields to be available,
@@ -983,9 +987,19 @@ fn typed_value_to_variant<'a>(
983987 let value = array. value ( index) ;
984988 Ok ( Uuid :: from_slice ( value) . unwrap ( ) . into ( ) ) // unwrap is safe: slice is always 16 bytes
985989 }
986- DataType :: Binary | DataType :: LargeBinary | DataType :: BinaryView => {
987- let value = binary_array_value ( typed_value. as_ref ( ) , index)
988- . expect ( "match arm guarantees the array is binary-like" ) ;
990+ DataType :: Binary => {
991+ let array = typed_value. as_binary :: < i32 > ( ) ;
992+ let value = array. value ( index) ;
993+ Ok ( Variant :: from ( value) )
994+ }
995+ DataType :: LargeBinary => {
996+ let array = typed_value. as_binary :: < i64 > ( ) ;
997+ let value = array. value ( index) ;
998+ Ok ( Variant :: from ( value) )
999+ }
1000+ DataType :: BinaryView => {
1001+ let array = typed_value. as_binary_view ( ) ;
1002+ let value = array. value ( index) ;
9891003 Ok ( Variant :: from ( value) )
9901004 }
9911005 DataType :: Utf8 => {
0 commit comments