|
19 | 19 |
|
20 | 20 | use crate::{BorrowedShreddingState, VariantArray, VariantValueArrayBuilder}; |
21 | 21 | use arrow::array::{ |
22 | | - Array, AsArray as _, BinaryViewArray, BooleanArray, FixedSizeBinaryArray, FixedSizeListArray, |
23 | | - GenericListArray, GenericListViewArray, LargeStringArray, ListLikeArray, PrimitiveArray, |
24 | | - StringArray, StringViewArray, StructArray, |
| 22 | + Array, AsArray as _, BinaryArray, BinaryViewArray, BooleanArray, FixedSizeBinaryArray, |
| 23 | + FixedSizeListArray, GenericListArray, GenericListViewArray, LargeBinaryArray, LargeStringArray, |
| 24 | + ListLikeArray, PrimitiveArray, StringArray, StringViewArray, StructArray, |
25 | 25 | }; |
26 | 26 | use arrow::buffer::NullBuffer; |
27 | 27 | use arrow::datatypes::{ |
@@ -107,7 +107,9 @@ enum UnshredVariantRowBuilder<'a> { |
107 | 107 | PrimitiveString(UnshredPrimitiveRowBuilder<'a, StringArray>), |
108 | 108 | PrimitiveStringView(UnshredPrimitiveRowBuilder<'a, StringViewArray>), |
109 | 109 | PrimitiveLargeString(UnshredPrimitiveRowBuilder<'a, LargeStringArray>), |
| 110 | + PrimitiveBinary(UnshredPrimitiveRowBuilder<'a, BinaryArray>), |
110 | 111 | PrimitiveBinaryView(UnshredPrimitiveRowBuilder<'a, BinaryViewArray>), |
| 112 | + PrimitiveLargeBinary(UnshredPrimitiveRowBuilder<'a, LargeBinaryArray>), |
111 | 113 | PrimitiveUuid(UnshredPrimitiveRowBuilder<'a, FixedSizeBinaryArray>), |
112 | 114 | List(ListUnshredVariantBuilder<'a, GenericListArray<i32>>), |
113 | 115 | LargeList(ListUnshredVariantBuilder<'a, GenericListArray<i64>>), |
@@ -150,7 +152,9 @@ impl<'a> UnshredVariantRowBuilder<'a> { |
150 | 152 | Self::PrimitiveString(b) => b.append_row(builder, metadata, index), |
151 | 153 | Self::PrimitiveStringView(b) => b.append_row(builder, metadata, index), |
152 | 154 | Self::PrimitiveLargeString(b) => b.append_row(builder, metadata, index), |
| 155 | + Self::PrimitiveBinary(b) => b.append_row(builder, metadata, index), |
153 | 156 | Self::PrimitiveBinaryView(b) => b.append_row(builder, metadata, index), |
| 157 | + Self::PrimitiveLargeBinary(b) => b.append_row(builder, metadata, index), |
154 | 158 | Self::PrimitiveUuid(b) => b.append_row(builder, metadata, index), |
155 | 159 | Self::List(b) => b.append_row(builder, metadata, index), |
156 | 160 | Self::LargeList(b) => b.append_row(builder, metadata, index), |
@@ -232,7 +236,9 @@ impl<'a> UnshredVariantRowBuilder<'a> { |
232 | 236 | DataType::Utf8 => primitive_builder!(PrimitiveString, as_string), |
233 | 237 | DataType::Utf8View => primitive_builder!(PrimitiveStringView, as_string_view), |
234 | 238 | DataType::LargeUtf8 => primitive_builder!(PrimitiveLargeString, as_string), |
| 239 | + DataType::Binary => primitive_builder!(PrimitiveBinary, as_binary), |
235 | 240 | DataType::BinaryView => primitive_builder!(PrimitiveBinaryView, as_binary_view), |
| 241 | + DataType::LargeBinary => primitive_builder!(PrimitiveLargeBinary, as_binary), |
236 | 242 | DataType::FixedSizeBinary(16) => { |
237 | 243 | primitive_builder!(PrimitiveUuid, as_fixed_size_binary) |
238 | 244 | } |
@@ -413,7 +419,9 @@ impl_append_to_variant_builder!(BooleanArray); |
413 | 419 | impl_append_to_variant_builder!(StringArray); |
414 | 420 | impl_append_to_variant_builder!(StringViewArray); |
415 | 421 | impl_append_to_variant_builder!(LargeStringArray); |
| 422 | +impl_append_to_variant_builder!(BinaryArray); |
416 | 423 | impl_append_to_variant_builder!(BinaryViewArray); |
| 424 | +impl_append_to_variant_builder!(LargeBinaryArray); |
417 | 425 | impl_append_to_variant_builder!(PrimitiveArray<Int8Type>); |
418 | 426 | impl_append_to_variant_builder!(PrimitiveArray<Int16Type>); |
419 | 427 | impl_append_to_variant_builder!(PrimitiveArray<Int32Type>); |
@@ -675,7 +683,9 @@ impl<'a, L: ListLikeArray> ListUnshredVariantBuilder<'a, L> { |
675 | 683 | #[cfg(test)] |
676 | 684 | mod tests { |
677 | 685 | use crate::VariantArray; |
678 | | - use arrow::array::{BinaryViewArray, LargeStringArray, StringViewArray}; |
| 686 | + use arrow::array::{ |
| 687 | + BinaryArray, BinaryViewArray, LargeBinaryArray, LargeStringArray, StringViewArray, |
| 688 | + }; |
679 | 689 | use parquet_variant::Variant; |
680 | 690 |
|
681 | 691 | #[test] |
@@ -720,4 +730,48 @@ mod tests { |
720 | 730 | assert_eq!(result.value(1), Variant::from("middle")); |
721 | 731 | assert_eq!(result.value(2), Variant::from("world")); |
722 | 732 | } |
| 733 | + |
| 734 | + #[test] |
| 735 | + fn test_unshred_binary_typed_value() { |
| 736 | + let metadata_bytes: &[u8] = &[0x01, 0x00, 0x00]; |
| 737 | + let metadata = BinaryViewArray::from_iter_values(vec![metadata_bytes; 3]); |
| 738 | + |
| 739 | + let typed_value: arrow::array::ArrayRef = |
| 740 | + std::sync::Arc::new(BinaryArray::from_iter_values(vec![ |
| 741 | + &b"\x00\x01\x02"[..], |
| 742 | + &b"\xff\xaa"[..], |
| 743 | + &b"\xde\xad\xbe\xef"[..], |
| 744 | + ])); |
| 745 | + |
| 746 | + let variant_array = VariantArray::from_parts(metadata, None, Some(typed_value), None); |
| 747 | + |
| 748 | + let result = crate::unshred_variant(&variant_array).unwrap(); |
| 749 | + |
| 750 | + assert_eq!(result.len(), 3); |
| 751 | + assert_eq!(result.value(0), Variant::from(&b"\x00\x01\x02"[..])); |
| 752 | + assert_eq!(result.value(1), Variant::from(&b"\xff\xaa"[..])); |
| 753 | + assert_eq!(result.value(2), Variant::from(&b"\xde\xad\xbe\xef"[..])); |
| 754 | + } |
| 755 | + |
| 756 | + #[test] |
| 757 | + fn test_unshred_largebinary_typed_value() { |
| 758 | + let metadata_bytes: &[u8] = &[0x01, 0x00, 0x00]; |
| 759 | + let metadata = BinaryViewArray::from_iter_values(vec![metadata_bytes; 3]); |
| 760 | + |
| 761 | + let typed_value: arrow::array::ArrayRef = |
| 762 | + std::sync::Arc::new(LargeBinaryArray::from_iter_values(vec![ |
| 763 | + &b"\x00\x01\x02"[..], |
| 764 | + &b"\xff\xaa"[..], |
| 765 | + &b"\xde\xad\xbe\xef"[..], |
| 766 | + ])); |
| 767 | + |
| 768 | + let variant_array = VariantArray::from_parts(metadata, None, Some(typed_value), None); |
| 769 | + |
| 770 | + let result = crate::unshred_variant(&variant_array).unwrap(); |
| 771 | + |
| 772 | + assert_eq!(result.len(), 3); |
| 773 | + assert_eq!(result.value(0), Variant::from(&b"\x00\x01\x02"[..])); |
| 774 | + assert_eq!(result.value(1), Variant::from(&b"\xff\xaa"[..])); |
| 775 | + assert_eq!(result.value(2), Variant::from(&b"\xde\xad\xbe\xef"[..])); |
| 776 | + } |
723 | 777 | } |
0 commit comments