Skip to content

Commit f8870ae

Browse files
authored
Feature: add take for the view vectors (#5682)
Tracking Issue: #5652 I separated this out from #5653 just in case we wanted to discuss how to handle `take` on the view type vectors. See the module docs for more detail. After this gets merged I can implement `DictArray` `batch_execute`! Signed-off-by: Connor Tsui <[email protected]>
1 parent 9af4e14 commit f8870ae

File tree

2 files changed

+35
-48
lines changed

2 files changed

+35
-48
lines changed
Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
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;
813
use vortex_dtype::UnsignedPType;
914
use vortex_vector::VectorOps;
10-
// use vortex_vector::binaryview::BinaryView;
15+
use vortex_vector::binaryview::BinaryView;
1116
use vortex_vector::binaryview::BinaryViewType;
1217
use vortex_vector::binaryview::BinaryViewVector;
1318
use vortex_vector::primitive::PVector;
@@ -29,11 +34,7 @@ impl<T: BinaryViewType, I: UnsignedPType> Take<PVector<I>> for &BinaryViewVector
2934
impl<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

5352
fn 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.
8174
fn 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-
*/

vortex-compute/src/take/vector/listview.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4+
//! Implementations of `take` on [`ListViewVector`].
5+
//!
6+
//! take` on the list view simply performs a `take` on the views of the vector, which means the
7+
//! resulting vector may have "garbage" data in its `elements` child vector.
8+
//!
9+
//! Note that it is on the outer array type to perform compaction / garbage collection.
10+
411
use vortex_dtype::UnsignedPType;
512
use vortex_vector::VectorOps;
613
use vortex_vector::listview::ListViewVector;
@@ -23,11 +30,7 @@ impl<I: UnsignedPType> Take<PVector<I>> for &ListViewVector {
2330
impl<I: UnsignedPType> Take<[I]> for &ListViewVector {
2431
type Output = ListViewVector;
2532

26-
fn take(self, _indices: &[I]) -> ListViewVector {
27-
todo!("TODO(connor): Implement `take` for `ListViewVector` and figure out rebuilding");
28-
29-
/*
30-
33+
fn take(self, indices: &[I]) -> ListViewVector {
3134
let taken_offsets = self.offsets().take(indices);
3235
let taken_sizes = self.sizes().take(indices);
3336
let taken_validity = self.validity().take(indices);
@@ -46,24 +49,20 @@ impl<I: UnsignedPType> Take<[I]> for &ListViewVector {
4649
taken_validity,
4750
)
4851
}
49-
50-
*/
5152
}
5253
}
5354

5455
fn take_nullable<I: UnsignedPType>(
55-
_lvector: &ListViewVector,
56-
_indices: &PVector<I>,
56+
list_view: &ListViewVector,
57+
indices: &PVector<I>,
5758
) -> ListViewVector {
58-
todo!("TODO(connor): Implement `take` for `ListViewVector` and figure out rebuilding");
59-
60-
/*
61-
6259
// We ignore nullability when taking the offsets and sizes since we can let the `Mask`
6360
// implementation determine which elements are null.
64-
let taken_offsets = lvector.offsets().take(indices.elements().as_slice());
65-
let taken_sizes = lvector.sizes().take(indices.elements().as_slice());
66-
let taken_validity = lvector.validity().take(indices);
61+
let taken_offsets = list_view.offsets().take(indices.elements().as_slice());
62+
let taken_sizes = list_view.sizes().take(indices.elements().as_slice());
63+
64+
// Note that this is **not** the same as the `indices: &[I]` `take` implementation above.
65+
let taken_validity = list_view.validity().take(indices);
6766

6867
debug_assert_eq!(taken_offsets.len(), taken_validity.len());
6968
debug_assert_eq!(taken_sizes.len(), taken_validity.len());
@@ -73,12 +72,10 @@ fn take_nullable<I: UnsignedPType>(
7372
// via Arc, so all view references remain valid.
7473
unsafe {
7574
ListViewVector::new_unchecked(
76-
lvector.elements().clone(),
75+
list_view.elements().clone(),
7776
taken_offsets,
7877
taken_sizes,
7978
taken_validity,
8079
)
8180
}
82-
83-
*/
8481
}

0 commit comments

Comments
 (0)