@@ -3653,18 +3653,20 @@ fn fmt_list(arr: ArrayRef, f: &mut fmt::Formatter) -> fmt::Result {
3653
3653
write ! ( f, "{value_formatter}" )
3654
3654
}
3655
3655
3656
+ /// writes a byte array to formatter. `[1, 2, 3]` ==> `"1,2,3"`
3657
+ fn fmt_binary ( data : & [ u8 ] , f : & mut fmt:: Formatter ) -> fmt:: Result {
3658
+ let mut iter = data. iter ( ) ;
3659
+ if let Some ( b) = iter. next ( ) {
3660
+ write ! ( f, "{b}" ) ?;
3661
+ }
3662
+ for b in iter {
3663
+ write ! ( f, ",{b}" ) ?;
3664
+ }
3665
+ Ok ( ( ) )
3666
+ }
3667
+
3656
3668
impl fmt:: Debug for ScalarValue {
3657
3669
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
3658
- fn fmt_binary ( data : & [ u8 ] , f : & mut fmt:: Formatter ) -> fmt:: Result {
3659
- write ! (
3660
- f,
3661
- "{}" ,
3662
- data. iter( )
3663
- . map( |v| format!( "{v}" ) )
3664
- . collect:: <Vec <_>>( )
3665
- . join( "," )
3666
- )
3667
- }
3668
3670
match self {
3669
3671
ScalarValue :: Decimal128 ( _, _, _) => write ! ( f, "Decimal128({self})" ) ,
3670
3672
ScalarValue :: Decimal256 ( _, _, _) => write ! ( f, "Decimal256({self})" ) ,
@@ -3714,7 +3716,7 @@ impl fmt::Debug for ScalarValue {
3714
3716
write ! ( f, "FixedSizeBinary({size}, {self})" )
3715
3717
}
3716
3718
ScalarValue :: FixedSizeBinary ( size, Some ( b) ) => {
3717
- write ! ( f, "Binary ({size}, \" " ) ?;
3719
+ write ! ( f, "FixedSizeBinary ({size}, \" " ) ?;
3718
3720
fmt_binary ( b. as_slice ( ) , f) ?;
3719
3721
write ! ( f, "\" )" )
3720
3722
}
@@ -6659,6 +6661,8 @@ mod tests {
6659
6661
fn test_binary_display ( ) {
6660
6662
let no_binary_value = ScalarValue :: Binary ( None ) ;
6661
6663
assert_eq ! ( format!( "{no_binary_value}" ) , "NULL" ) ;
6664
+ let single_binary_value = ScalarValue :: Binary ( Some ( vec ! [ 42u8 ] ) ) ;
6665
+ assert_eq ! ( format!( "{single_binary_value}" ) , "2A" ) ;
6662
6666
let small_binary_value = ScalarValue :: Binary ( Some ( vec ! [ 1u8 , 2 , 3 ] ) ) ;
6663
6667
assert_eq ! ( format!( "{small_binary_value}" ) , "010203" ) ;
6664
6668
let large_binary_value =
@@ -6692,6 +6696,60 @@ mod tests {
6692
6696
assert_eq ! ( format!( "{large_binary_value}" ) , "0102030405060708090A..." ) ;
6693
6697
}
6694
6698
6699
+ #[ test]
6700
+ fn test_binary_debug ( ) {
6701
+ let no_binary_value = ScalarValue :: Binary ( None ) ;
6702
+ assert_eq ! ( format!( "{no_binary_value:?}" ) , "Binary(NULL)" ) ;
6703
+ let single_binary_value = ScalarValue :: Binary ( Some ( vec ! [ 42u8 ] ) ) ;
6704
+ assert_eq ! ( format!( "{single_binary_value:?}" ) , "Binary(\" 42\" )" ) ;
6705
+ let small_binary_value = ScalarValue :: Binary ( Some ( vec ! [ 1u8 , 2 , 3 ] ) ) ;
6706
+ assert_eq ! ( format!( "{small_binary_value:?}" ) , "Binary(\" 1,2,3\" )" ) ;
6707
+ let large_binary_value =
6708
+ ScalarValue :: Binary ( Some ( vec ! [ 1u8 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ] ) ) ;
6709
+ assert_eq ! (
6710
+ format!( "{large_binary_value:?}" ) ,
6711
+ "Binary(\" 1,2,3,4,5,6,7,8,9,10,11\" )"
6712
+ ) ;
6713
+
6714
+ let no_binary_value = ScalarValue :: BinaryView ( None ) ;
6715
+ assert_eq ! ( format!( "{no_binary_value:?}" ) , "BinaryView(NULL)" ) ;
6716
+ let small_binary_value = ScalarValue :: BinaryView ( Some ( vec ! [ 1u8 , 2 , 3 ] ) ) ;
6717
+ assert_eq ! ( format!( "{small_binary_value:?}" ) , "BinaryView(\" 1,2,3\" )" ) ;
6718
+ let large_binary_value =
6719
+ ScalarValue :: BinaryView ( Some ( vec ! [ 1u8 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ] ) ) ;
6720
+ assert_eq ! (
6721
+ format!( "{large_binary_value:?}" ) ,
6722
+ "BinaryView(\" 1,2,3,4,5,6,7,8,9,10,11\" )"
6723
+ ) ;
6724
+
6725
+ let no_binary_value = ScalarValue :: LargeBinary ( None ) ;
6726
+ assert_eq ! ( format!( "{no_binary_value:?}" ) , "LargeBinary(NULL)" ) ;
6727
+ let small_binary_value = ScalarValue :: LargeBinary ( Some ( vec ! [ 1u8 , 2 , 3 ] ) ) ;
6728
+ assert_eq ! ( format!( "{small_binary_value:?}" ) , "LargeBinary(\" 1,2,3\" )" ) ;
6729
+ let large_binary_value =
6730
+ ScalarValue :: LargeBinary ( Some ( vec ! [ 1u8 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ] ) ) ;
6731
+ assert_eq ! (
6732
+ format!( "{large_binary_value:?}" ) ,
6733
+ "LargeBinary(\" 1,2,3,4,5,6,7,8,9,10,11\" )"
6734
+ ) ;
6735
+
6736
+ let no_binary_value = ScalarValue :: FixedSizeBinary ( 3 , None ) ;
6737
+ assert_eq ! ( format!( "{no_binary_value:?}" ) , "FixedSizeBinary(3, NULL)" ) ;
6738
+ let small_binary_value = ScalarValue :: FixedSizeBinary ( 3 , Some ( vec ! [ 1u8 , 2 , 3 ] ) ) ;
6739
+ assert_eq ! (
6740
+ format!( "{small_binary_value:?}" ) ,
6741
+ "FixedSizeBinary(3, \" 1,2,3\" )"
6742
+ ) ;
6743
+ let large_binary_value = ScalarValue :: FixedSizeBinary (
6744
+ 11 ,
6745
+ Some ( vec ! [ 1u8 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ] ) ,
6746
+ ) ;
6747
+ assert_eq ! (
6748
+ format!( "{large_binary_value:?}" ) ,
6749
+ "FixedSizeBinary(11, \" 1,2,3,4,5,6,7,8,9,10,11\" )"
6750
+ ) ;
6751
+ }
6752
+
6695
6753
#[ test]
6696
6754
fn test_build_timestamp_millisecond_list ( ) {
6697
6755
let values = vec ! [ ScalarValue :: TimestampMillisecond ( Some ( 1 ) , None ) ] ;
0 commit comments