@@ -37,7 +37,7 @@ use std::sync::Arc;
3737/// `VariantToArrowRowBuilder` (below) and `VariantToShreddedPrimitiveVariantRowBuilder` (in
3838/// `shred_variant.rs`).
3939pub ( crate ) enum PrimitiveVariantToArrowRowBuilder < ' a > {
40- Null ( VariantToNullArrowRowBuilder ) ,
40+ Null ( VariantToNullArrowRowBuilder < ' a > ) ,
4141 Boolean ( VariantToBooleanArrowRowBuilder < ' a > ) ,
4242 Int8 ( VariantToPrimitiveArrowRowBuilder < ' a , datatypes:: Int8Type > ) ,
4343 Int16 ( VariantToPrimitiveArrowRowBuilder < ' a , datatypes:: Int16Type > ) ,
@@ -232,7 +232,7 @@ pub(crate) fn make_primitive_variant_to_arrow_row_builder<'a>(
232232
233233 let builder =
234234 match data_type {
235- DataType :: Null => Null ( VariantToNullArrowRowBuilder :: new ( capacity ) ) ,
235+ DataType :: Null => Null ( VariantToNullArrowRowBuilder :: new ( cast_options ) ) ,
236236 DataType :: Boolean => {
237237 Boolean ( VariantToBooleanArrowRowBuilder :: new ( cast_options, capacity) )
238238 }
@@ -696,10 +696,43 @@ impl VariantToBinaryVariantArrowRowBuilder {
696696 }
697697}
698698
699- pub ( crate ) struct VariantToNullArrowRowBuilder {
700- capacity : usize ,
699+ pub ( crate ) struct VariantToNullArrowRowBuilder < ' a > {
700+ cast_option : & ' a CastOptions < ' a > ,
701+ item_count : usize ,
701702}
702703
704+ impl < ' a > VariantToNullArrowRowBuilder < ' a > {
705+ fn new ( cast_option : & ' a CastOptions < ' a > ) -> Self {
706+ Self {
707+ cast_option,
708+ item_count : 0 ,
709+ }
710+ }
711+
712+ fn append_value ( & mut self , value : & Variant < ' _ , ' _ > ) -> Result < bool > {
713+ if value. as_null ( ) . is_some ( ) {
714+ self . item_count += 1 ;
715+ Ok ( true )
716+ } else if self . cast_option . safe {
717+ self . append_null ( ) ?;
718+ Ok ( false )
719+ } else {
720+ Err ( ArrowError :: CastError ( format ! (
721+ "Failed to extract Null from variant {:?} at path VariantPath([])" ,
722+ value
723+ ) ) )
724+ }
725+ }
726+
727+ fn append_null ( & mut self ) -> Result < ( ) > {
728+ self . item_count += 1 ;
729+ Ok ( ( ) )
730+ }
731+
732+ fn finish ( self ) -> Result < ArrayRef > {
733+ Ok ( Arc :: new ( NullArray :: new ( self . item_count ) ) )
734+ }
735+ }
703736
704737#[ cfg( test) ]
705738mod tests {
@@ -756,28 +789,3 @@ mod tests {
756789 }
757790 }
758791}
759- impl VariantToNullArrowRowBuilder {
760- fn new ( capacity : usize ) -> Self {
761- Self { capacity }
762- }
763-
764- fn append_value ( & mut self , value : & Variant < ' _ , ' _ > ) -> Result < bool > {
765- if value. as_null ( ) . is_some ( ) {
766- Ok ( true )
767- } else {
768- // Null type only accepts nulls
769- Err ( ArrowError :: CastError ( format ! (
770- "Failed to extract Null from variant {:?} at path VariantPath([])" ,
771- value
772- ) ) )
773- }
774- }
775-
776- fn append_null ( & mut self ) -> Result < ( ) > {
777- Ok ( ( ) )
778- }
779-
780- fn finish ( self ) -> Result < ArrayRef > {
781- Ok ( Arc :: new ( NullArray :: new ( self . capacity ) ) )
782- }
783- }
0 commit comments