File tree Expand file tree Collapse file tree 12 files changed +123
-0
lines changed
Expand file tree Collapse file tree 12 files changed +123
-0
lines changed Original file line number Diff line number Diff line change @@ -254,6 +254,21 @@ impl<T: BinaryViewType> VectorOps for BinaryViewVector<T> {
254254 ) )
255255 }
256256 }
257+
258+ fn into_mut ( self ) -> BinaryViewVectorMut < T > {
259+ let views_mut = self . views . into_mut ( ) ;
260+ let validity_mut = self . validity . into_mut ( ) ;
261+
262+ // If someone else has a strong reference to the `Arc`, clone the underlying data (which is
263+ // just a **different** reference count increment).
264+ let buffers_mut = Arc :: try_unwrap ( self . buffers )
265+ . unwrap_or_else ( |arc| ( * arc) . clone ( ) )
266+ . into_vec ( ) ;
267+
268+ // SAFETY: The BinaryViewVector maintains the exact same invariants as the immutable
269+ // version, so all invariants are still upheld.
270+ unsafe { BinaryViewVectorMut :: new_unchecked ( views_mut, validity_mut, buffers_mut) }
271+ }
257272}
258273
259274#[ cfg( test) ]
Original file line number Diff line number Diff line change @@ -121,4 +121,11 @@ impl VectorOps for BoolVector {
121121 } ) ,
122122 }
123123 }
124+
125+ fn into_mut ( self ) -> BoolVectorMut {
126+ BoolVectorMut {
127+ bits : self . bits . into_mut ( ) ,
128+ validity : self . validity . into_mut ( ) ,
129+ }
130+ }
124131}
Original file line number Diff line number Diff line change @@ -203,4 +203,12 @@ impl<D: NativeDecimalType> VectorOps for DVector<D> {
203203 } ) ,
204204 }
205205 }
206+
207+ fn into_mut ( self ) -> DVectorMut < D > {
208+ DVectorMut {
209+ ps : self . ps ,
210+ elements : self . elements . into_mut ( ) ,
211+ validity : self . validity . into_mut ( ) ,
212+ }
213+ }
206214}
Original file line number Diff line number Diff line change @@ -70,6 +70,10 @@ impl VectorOps for DecimalVector {
7070 . map_err( Self :: from)
7171 } )
7272 }
73+
74+ fn into_mut ( self ) -> DecimalVectorMut {
75+ match_each_dvector ! ( self , |v| { DecimalVectorMut :: from( v. into_mut( ) ) } )
76+ }
7377}
7478
7579impl DecimalTypeDowncast for DecimalVector {
Original file line number Diff line number Diff line change @@ -199,6 +199,23 @@ impl VectorOps for FixedSizeListVector {
199199 } ) ,
200200 }
201201 }
202+
203+ fn into_mut ( self ) -> FixedSizeListVectorMut {
204+ let len = self . len ;
205+ let list_size = self . list_size ;
206+ let validity = self . validity . into_mut ( ) ;
207+
208+ // If someone else has a strong reference to the `Arc`, clone the underlying data (which is
209+ // just a **different** reference count increment).
210+ let elements = Arc :: try_unwrap ( self . elements ) . unwrap_or_else ( |arc| ( * arc) . clone ( ) ) ;
211+
212+ FixedSizeListVectorMut {
213+ elements : Box :: new ( elements. into_mut ( ) ) ,
214+ list_size,
215+ validity,
216+ len,
217+ }
218+ }
202219}
203220
204221#[ cfg( test) ]
Original file line number Diff line number Diff line change @@ -285,6 +285,25 @@ impl VectorOps for ListViewVector {
285285 } ) ,
286286 }
287287 }
288+
289+ fn into_mut ( self ) -> ListViewVectorMut {
290+ let len = self . len ;
291+ let validity = self . validity . into_mut ( ) ;
292+ let offsets = self . offsets . into_mut ( ) ;
293+ let sizes = self . sizes . into_mut ( ) ;
294+
295+ // If someone else has a strong reference to the `Arc`, clone the underlying data (which is
296+ // just a **different** reference count increment).
297+ let elements = Arc :: try_unwrap ( self . elements ) . unwrap_or_else ( |arc| ( * arc) . clone ( ) ) ;
298+
299+ ListViewVectorMut {
300+ offsets,
301+ sizes,
302+ elements : Box :: new ( elements. into_mut ( ) ) ,
303+ validity,
304+ len,
305+ }
306+ }
288307}
289308
290309// TODO(connor): It would be better to separate everything inside the macros into its own function,
Original file line number Diff line number Diff line change @@ -60,4 +60,8 @@ impl VectorOps for NullVector {
6060 fn try_into_mut ( self ) -> Result < NullVectorMut , Self > {
6161 Ok ( NullVectorMut :: new ( self . len ) )
6262 }
63+
64+ fn into_mut ( self ) -> NullVectorMut {
65+ NullVectorMut :: new ( self . len )
66+ }
6367}
Original file line number Diff line number Diff line change @@ -156,4 +156,11 @@ impl<T: NativePType> VectorOps for PVector<T> {
156156 } ) ,
157157 }
158158 }
159+
160+ fn into_mut ( self ) -> PVectorMut < T > {
161+ let elements = self . elements . into_mut ( ) ;
162+ let validity = self . validity . into_mut ( ) ;
163+
164+ PVectorMut { elements, validity }
165+ }
159166}
Original file line number Diff line number Diff line change @@ -93,6 +93,10 @@ impl VectorOps for PrimitiveVector {
9393 . map_err( Self :: from)
9494 } )
9595 }
96+
97+ fn into_mut ( self ) -> PrimitiveVectorMut {
98+ match_each_pvector ! ( self , |v| { v. into_mut( ) . into( ) } )
99+ }
96100}
97101
98102impl PTypeUpcast for PrimitiveVector {
Original file line number Diff line number Diff line change @@ -197,4 +197,25 @@ impl VectorOps for StructVector {
197197 validity,
198198 } )
199199 }
200+
201+ fn into_mut ( self ) -> StructVectorMut {
202+ let len = self . len ;
203+ let validity = self . validity . into_mut ( ) ;
204+
205+ // If someone else has a strong reference to the `Arc`, clone the underlying data (which is
206+ // just a **different** reference count increment).
207+ let fields = Arc :: try_unwrap ( self . fields ) . unwrap_or_else ( |arc| ( * arc) . clone ( ) ) ;
208+
209+ let mutable_fields: Box < [ _ ] > = fields
210+ . into_vec ( )
211+ . into_iter ( )
212+ . map ( |field| field. into_mut ( ) )
213+ . collect ( ) ;
214+
215+ StructVectorMut {
216+ fields : mutable_fields,
217+ len,
218+ validity,
219+ }
220+ }
200221}
You can’t perform that action at this time.
0 commit comments