@@ -38,23 +38,23 @@ use crate::arrays::VarBinViewArray;
3838use crate :: validity:: Validity ;
3939
4040/// Trait for converting vector types into arrays.
41- pub trait VectorIntoArray {
41+ pub trait VectorIntoArray < T > {
4242 /// Converts the vector into an array of the specified data type.
43- fn into_array ( self , dtype : & DType ) -> ArrayRef ;
43+ fn into_array ( self , dtype : & DType ) -> T ;
4444}
4545
46- impl VectorIntoArray for Vector {
46+ impl VectorIntoArray < ArrayRef > for Vector {
4747 fn into_array ( self , dtype : & DType ) -> ArrayRef {
4848 match dtype {
49- DType :: Null => self . into_null ( ) . into_array ( dtype) ,
50- DType :: Bool ( _) => self . into_bool ( ) . into_array ( dtype) ,
51- DType :: Primitive ( ..) => self . into_primitive ( ) . into_array ( dtype) ,
52- DType :: Decimal ( ..) => self . into_decimal ( ) . into_array ( dtype) ,
53- DType :: Utf8 ( _) => self . into_string ( ) . into_array ( dtype) ,
54- DType :: Binary ( _) => self . into_binary ( ) . into_array ( dtype) ,
55- DType :: List ( ..) => self . into_list ( ) . into_array ( dtype) ,
56- DType :: FixedSizeList ( ..) => self . into_fixed_size_list ( ) . into_array ( dtype) ,
57- DType :: Struct ( ..) => self . into_struct ( ) . into_array ( dtype) ,
49+ DType :: Null => self . into_null ( ) . into_array ( dtype) . into_array ( ) ,
50+ DType :: Bool ( _) => self . into_bool ( ) . into_array ( dtype) . into_array ( ) ,
51+ DType :: Primitive ( ..) => self . into_primitive ( ) . into_array ( dtype) . into_array ( ) ,
52+ DType :: Decimal ( ..) => self . into_decimal ( ) . into_array ( dtype) . into_array ( ) ,
53+ DType :: Utf8 ( _) => self . into_string ( ) . into_array ( dtype) . into_array ( ) ,
54+ DType :: Binary ( _) => self . into_binary ( ) . into_array ( dtype) . into_array ( ) ,
55+ DType :: List ( ..) => self . into_list ( ) . into_array ( dtype) . into_array ( ) ,
56+ DType :: FixedSizeList ( ..) => self . into_fixed_size_list ( ) . into_array ( dtype) . into_array ( ) ,
57+ DType :: Struct ( ..) => self . into_struct ( ) . into_array ( dtype) . into_array ( ) ,
5858 DType :: Extension ( ext_dtype) => {
5959 let storage = self . into_array ( ext_dtype. storage_dtype ( ) ) ;
6060 ExtensionArray :: new ( ext_dtype. clone ( ) , storage) . into_array ( )
@@ -63,33 +63,32 @@ impl VectorIntoArray for Vector {
6363 }
6464}
6565
66- impl VectorIntoArray for NullVector {
67- fn into_array ( self , dtype : & DType ) -> ArrayRef {
66+ impl VectorIntoArray < NullArray > for NullVector {
67+ fn into_array ( self , dtype : & DType ) -> NullArray {
6868 assert ! ( matches!( dtype, DType :: Null ) ) ;
69- NullArray :: new ( self . len ( ) ) . into_array ( )
69+ NullArray :: new ( self . len ( ) )
7070 }
7171}
7272
73- impl VectorIntoArray for BoolVector {
74- fn into_array ( self , dtype : & DType ) -> ArrayRef {
73+ impl VectorIntoArray < BoolArray > for BoolVector {
74+ fn into_array ( self , dtype : & DType ) -> BoolArray {
7575 assert ! ( matches!( dtype, DType :: Bool ( _) ) ) ;
7676
7777 let ( bits, validity) = self . into_parts ( ) ;
7878 BoolArray :: from_bit_buffer ( bits, Validity :: from_mask ( validity, dtype. nullability ( ) ) )
79- . into_array ( )
8079 }
8180}
8281
83- impl VectorIntoArray for PrimitiveVector {
84- fn into_array ( self , dtype : & DType ) -> ArrayRef {
82+ impl VectorIntoArray < PrimitiveArray > for PrimitiveVector {
83+ fn into_array ( self , dtype : & DType ) -> PrimitiveArray {
8584 match_each_native_ptype ! ( self . ptype( ) , |T | {
8685 <T as NativePType >:: downcast( self ) . into_array( dtype)
8786 } )
8887 }
8988}
9089
91- impl < T : NativePType > VectorIntoArray for PVector < T > {
92- fn into_array ( self , dtype : & DType ) -> ArrayRef {
90+ impl < T : NativePType > VectorIntoArray < PrimitiveArray > for PVector < T > {
91+ fn into_array ( self , dtype : & DType ) -> PrimitiveArray {
9392 assert ! ( matches!( dtype, DType :: Primitive ( _, _) ) ) ;
9493 assert_eq ! ( T :: PTYPE , dtype. as_ptype( ) ) ;
9594
@@ -101,20 +100,19 @@ impl<T: NativePType> VectorIntoArray for PVector<T> {
101100 Validity :: from_mask ( validity, dtype. nullability ( ) ) ,
102101 )
103102 }
104- . into_array ( )
105103 }
106104}
107105
108- impl VectorIntoArray for DecimalVector {
109- fn into_array ( self , dtype : & DType ) -> ArrayRef {
106+ impl VectorIntoArray < DecimalArray > for DecimalVector {
107+ fn into_array ( self , dtype : & DType ) -> DecimalArray {
110108 match_each_decimal_value_type ! ( self . decimal_type( ) , |D | {
111109 <D as NativeDecimalType >:: downcast( self ) . into_array( dtype)
112110 } )
113111 }
114112}
115113
116- impl < D : NativeDecimalType > VectorIntoArray for DVector < D > {
117- fn into_array ( self , dtype : & DType ) -> ArrayRef {
114+ impl < D : NativeDecimalType > VectorIntoArray < DecimalArray > for DVector < D > {
115+ fn into_array ( self , dtype : & DType ) -> DecimalArray {
118116 assert ! ( matches!( dtype, DType :: Decimal ( _, _) ) ) ;
119117
120118 let nullability = dtype. nullability ( ) ;
@@ -133,12 +131,11 @@ impl<D: NativeDecimalType> VectorIntoArray for DVector<D> {
133131 Validity :: from_mask ( validity, nullability) ,
134132 )
135133 }
136- . into_array ( )
137134 }
138135}
139136
140- impl < T : BinaryViewType > VectorIntoArray for BinaryViewVector < T > {
141- fn into_array ( self , dtype : & DType ) -> ArrayRef {
137+ impl < T : BinaryViewType > VectorIntoArray < VarBinViewArray > for BinaryViewVector < T > {
138+ fn into_array ( self , dtype : & DType ) -> VarBinViewArray {
142139 assert ! ( matches!( dtype, DType :: Utf8 ( _) ) ) ;
143140
144141 let ( views, buffers, validity) = self . into_parts ( ) ;
@@ -155,12 +152,11 @@ impl<T: BinaryViewType> VectorIntoArray for BinaryViewVector<T> {
155152 validity,
156153 )
157154 }
158- . into_array ( )
159155 }
160156}
161157
162- impl VectorIntoArray for ListViewVector {
163- fn into_array ( self , dtype : & DType ) -> ArrayRef {
158+ impl VectorIntoArray < ListViewArray > for ListViewVector {
159+ fn into_array ( self , dtype : & DType ) -> ListViewArray {
164160 assert ! ( matches!( dtype, DType :: List ( _, _) ) ) ;
165161
166162 let ( elements, offsets, sizes, validity) = self . into_parts ( ) ;
@@ -178,12 +174,19 @@ impl VectorIntoArray for ListViewVector {
178174 let sizes = sizes. into_array ( & sizes_dtype) ;
179175
180176 // SAFETY: vectors maintain all invariants required for array creation
181- unsafe { ListViewArray :: new_unchecked ( elements, offsets, sizes, validity) } . into_array ( )
177+ unsafe {
178+ ListViewArray :: new_unchecked (
179+ elements,
180+ offsets. into_array ( ) ,
181+ sizes. into_array ( ) ,
182+ validity,
183+ )
184+ }
182185 }
183186}
184187
185- impl VectorIntoArray for FixedSizeListVector {
186- fn into_array ( self , dtype : & DType ) -> ArrayRef {
188+ impl VectorIntoArray < FixedSizeListArray > for FixedSizeListVector {
189+ fn into_array ( self , dtype : & DType ) -> FixedSizeListArray {
187190 assert ! ( matches!( dtype, DType :: FixedSizeList ( _, _, _) ) ) ;
188191
189192 let len = self . len ( ) ;
@@ -198,12 +201,12 @@ impl VectorIntoArray for FixedSizeListVector {
198201 . into_array ( elements_dtype) ;
199202
200203 // SAFETY: vectors maintain all invariants required for array creation
201- unsafe { FixedSizeListArray :: new_unchecked ( elements, size, validity, len) } . into_array ( )
204+ unsafe { FixedSizeListArray :: new_unchecked ( elements, size, validity, len) }
202205 }
203206}
204207
205- impl VectorIntoArray for StructVector {
206- fn into_array ( self , dtype : & DType ) -> ArrayRef {
208+ impl VectorIntoArray < StructArray > for StructVector {
209+ fn into_array ( self , dtype : & DType ) -> StructArray {
207210 assert ! ( matches!( dtype, DType :: Struct ( _, _) ) ) ;
208211
209212 let len = self . len ( ) ;
@@ -222,6 +225,5 @@ impl VectorIntoArray for StructVector {
222225
223226 // SAFETY: vectors maintain all invariants required for array creation
224227 unsafe { StructArray :: new_unchecked ( field_arrays, struct_fields. clone ( ) , len, validity) }
225- . into_array ( )
226228 }
227229}
0 commit comments