11// SPDX-License-Identifier: Apache-2.0
22// SPDX-FileCopyrightText: Copyright the Vortex contributors
33
4- // use std::ops::Deref;
5-
6- // use num_traits::AsPrimitive;
7- // use vortex_buffer::Buffer;
4+ //! Implementations of `take` on [`BinaryViewVector`].
5+ //!
6+ //! take` on the binary view simply performs a `take` on the views of the vector, which means the
7+ //! resulting vector may have "garbage" data in its child buffers.
8+ //!
9+ //! Note that it is on the outer array type to perform compaction / garbage collection.
10+
11+ use num_traits:: AsPrimitive ;
12+ use vortex_buffer:: Buffer ;
813use vortex_dtype:: UnsignedPType ;
914use vortex_vector:: VectorOps ;
10- // use vortex_vector::binaryview::BinaryView;
15+ use vortex_vector:: binaryview:: BinaryView ;
1116use vortex_vector:: binaryview:: BinaryViewType ;
1217use vortex_vector:: binaryview:: BinaryViewVector ;
1318use vortex_vector:: primitive:: PVector ;
@@ -29,11 +34,7 @@ impl<T: BinaryViewType, I: UnsignedPType> Take<PVector<I>> for &BinaryViewVector
2934impl < T : BinaryViewType , I : UnsignedPType > Take < [ I ] > for & BinaryViewVector < T > {
3035 type Output = BinaryViewVector < T > ;
3136
32- fn take ( self , _indices : & [ I ] ) -> BinaryViewVector < T > {
33- todo ! ( "TODO(connor): Implement `take` for `BinaryViewVector` and figure out rebuilding" ) ;
34-
35- /*
36-
37+ fn take ( self , indices : & [ I ] ) -> BinaryViewVector < T > {
3738 let taken_views = take_views ( self . views ( ) , indices) ;
3839 let taken_validity = self . validity ( ) . take ( indices) ;
3940
@@ -45,45 +46,34 @@ impl<T: BinaryViewType, I: UnsignedPType> Take<[I]> for &BinaryViewVector<T> {
4546 unsafe {
4647 BinaryViewVector :: new_unchecked ( taken_views, self . buffers ( ) . clone ( ) , taken_validity)
4748 }
48-
49- */
5049 }
5150}
5251
5352fn take_nullable < T : BinaryViewType , I : UnsignedPType > (
54- _bvector : & BinaryViewVector < T > ,
55- _indices : & PVector < I > ,
53+ binary_view : & BinaryViewVector < T > ,
54+ indices : & PVector < I > ,
5655) -> BinaryViewVector < T > {
57- todo ! ( "TODO(connor): Implement `take` for `BinaryViewVector` and figure out rebuilding" ) ;
58-
59- /*
60-
6156 // We ignore nullability when taking the views since we can let the `Mask` implementation
6257 // determine which elements are null.
63- let taken_views = take_views(bvector.views(), indices.elements().as_slice());
64- let taken_validity = bvector.validity().take(indices);
58+ let taken_views = take_views ( binary_view. views ( ) , indices. elements ( ) . as_slice ( ) ) ;
59+
60+ // Note that this is **not** the same as the `indices: &[I]` `take` implementation above.
61+ let taken_validity = binary_view. validity ( ) . take ( indices) ;
6562
6663 debug_assert_eq ! ( taken_views. len( ) , taken_validity. len( ) ) ;
6764
6865 // SAFETY: We used the same indices to take from both components, so they should still have the
6966 // same length. The views still point into the same buffers which we clone via Arc, so all view
7067 // references remain valid.
7168 unsafe {
72- BinaryViewVector::new_unchecked(taken_views, bvector .buffers().clone(), taken_validity)
69+ BinaryViewVector :: new_unchecked ( taken_views, binary_view . buffers ( ) . clone ( ) , taken_validity)
7370 }
74-
75- */
7671}
7772
78- /*
79-
8073/// Takes views at the given indices.
8174fn take_views < I : AsPrimitive < usize > > (
8275 views : & Buffer < BinaryView > ,
8376 indices : & [ I ] ,
8477) -> Buffer < BinaryView > {
85- let views_ref = views.deref();
86- Buffer::<BinaryView>::from_trusted_len_iter(indices.iter().map(|i| views_ref[(*i).as_()]))
78+ Buffer :: < BinaryView > :: from_trusted_len_iter ( indices. iter ( ) . map ( |i| views[ i. as_ ( ) ] ) )
8779}
88-
89- */
0 commit comments