|
16 | 16 | // under the License. |
17 | 17 |
|
18 | 18 | use arrow::array::{ |
19 | | - ArrayRef, BinaryViewArray, BooleanBuilder, GenericStringBuilder, NullArray, NullBufferBuilder, |
20 | | - OffsetSizeTrait, PrimitiveBuilder, |
| 19 | + ArrayRef, BinaryViewArray, BooleanBuilder, GenericByteBuilder, GenericStringBuilder, NullArray, |
| 20 | + NullBufferBuilder, OffsetSizeTrait, PrimitiveBuilder, |
21 | 21 | }; |
22 | 22 | use arrow::compute::{CastOptions, DecimalCast}; |
23 | | -use arrow::datatypes::{self, DataType, DecimalType}; |
| 23 | +use arrow::datatypes::{self, DataType, DecimalType, GenericBinaryType}; |
24 | 24 | use arrow::error::{ArrowError, Result}; |
25 | 25 | use parquet_variant::{Variant, VariantPath}; |
26 | 26 |
|
@@ -63,6 +63,7 @@ pub(crate) enum PrimitiveVariantToArrowRowBuilder<'a> { |
63 | 63 | Date(VariantToPrimitiveArrowRowBuilder<'a, datatypes::Date32Type>), |
64 | 64 | Utf8(VariantToUtf8ArrowRowBuilder<'a, i32>), |
65 | 65 | LargeUtf8(VariantToUtf8ArrowRowBuilder<'a, i64>), |
| 66 | + Binary(VariantToBinaryRowBuilder<'a>), |
66 | 67 | } |
67 | 68 |
|
68 | 69 | /// Builder for converting variant values into strongly typed Arrow arrays. |
@@ -106,6 +107,7 @@ impl<'a> PrimitiveVariantToArrowRowBuilder<'a> { |
106 | 107 | Date(b) => b.append_null(), |
107 | 108 | Utf8(b) => b.append_null(), |
108 | 109 | LargeUtf8(b) => b.append_null(), |
| 110 | + Binary(b) => b.append_null(), |
109 | 111 | } |
110 | 112 | } |
111 | 113 |
|
@@ -137,6 +139,7 @@ impl<'a> PrimitiveVariantToArrowRowBuilder<'a> { |
137 | 139 | Date(b) => b.append_value(value), |
138 | 140 | Utf8(b) => b.append_value(value), |
139 | 141 | LargeUtf8(b) => b.append_value(value), |
| 142 | + Binary(b) => b.append_value(value), |
140 | 143 | } |
141 | 144 | } |
142 | 145 |
|
@@ -168,6 +171,7 @@ impl<'a> PrimitiveVariantToArrowRowBuilder<'a> { |
168 | 171 | Date(b) => b.finish(), |
169 | 172 | Utf8(b) => b.finish(), |
170 | 173 | LargeUtf8(b) => b.finish(), |
| 174 | + Binary(b) => b.finish(), |
171 | 175 | } |
172 | 176 | } |
173 | 177 | } |
@@ -294,6 +298,7 @@ pub(crate) fn make_primitive_variant_to_arrow_row_builder<'a>( |
294 | 298 | DataType::LargeUtf8 => { |
295 | 299 | LargeUtf8(VariantToUtf8ArrowRowBuilder::new(cast_options, capacity)) |
296 | 300 | } |
| 301 | + DataType::Binary => Binary(VariantToBinaryRowBuilder::new(cast_options, capacity)), |
297 | 302 | _ if data_type.is_primitive() => { |
298 | 303 | return Err(ArrowError::NotYetImplemented(format!( |
299 | 304 | "Primitive data_type {data_type:?} not yet implemented" |
@@ -478,6 +483,13 @@ define_variant_to_primitive_builder!( |
478 | 483 | type_name: format!("{}Utf8", O::PREFIX) |
479 | 484 | ); |
480 | 485 |
|
| 486 | +define_variant_to_primitive_builder!( |
| 487 | + struct VariantToBinaryRowBuilder<'a> |
| 488 | + |capacity| -> GenericByteBuilder<GenericBinaryType<i32>> { GenericByteBuilder::<GenericBinaryType<i32>>::with_capacity(capacity, 1024) }, |
| 489 | + |value| value.as_u8_slice(), |
| 490 | + type_name: "Binary" |
| 491 | +); |
| 492 | + |
481 | 493 | /// Builder for converting variant values to arrow Decimal values |
482 | 494 | pub(crate) struct VariantToDecimalArrowRowBuilder<'a, T> |
483 | 495 | where |
|
0 commit comments