Skip to content

Commit 9b9f045

Browse files
authored
Remove unused take_into function (#3236)
Believe it or not, this is never actually called anywhere by Vortex scans. Happy to look into adding `invoke_into` to all compute functions in the future if it's warranted, but for now it breaks the compute function API for something that isn't used anywhere. The benchmarks degrade, but they exercise a code path that isn't used in practice. So not too bothered about them at the moment.
1 parent 0d7b23a commit 9b9f045

File tree

8 files changed

+7
-321
lines changed

8 files changed

+7
-321
lines changed

encodings/dict/src/array.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use std::fmt::Debug;
22

33
use arrow_buffer::BooleanBuffer;
4-
use vortex_array::builders::ArrayBuilder;
5-
use vortex_array::compute::{cast, take, take_into};
4+
use vortex_array::compute::{cast, take};
65
use vortex_array::stats::{ArrayStats, StatsSetRef};
76
use vortex_array::variants::PrimitiveArrayTrait;
87
use vortex_array::vtable::VTableRef;
@@ -107,22 +106,6 @@ impl ArrayCanonicalImpl for DictArray {
107106
_ => take(self.values(), self.codes())?.to_canonical(),
108107
}
109108
}
110-
111-
fn _append_to_builder(&self, builder: &mut dyn ArrayBuilder) -> VortexResult<()> {
112-
match self.dtype() {
113-
// NOTE: Utf8 and Binary will decompress into VarBinViewArray, which requires a full
114-
// decompression to construct the views child array.
115-
// For this case, it is *always* faster to decompress the values first and then create
116-
// copies of the view pointers.
117-
// TODO(joe): is the above still true?, investigate this.
118-
DType::Utf8(_) | DType::Binary(_) => {
119-
let canonical_values: ArrayRef = self.values().to_canonical()?.into_array();
120-
take_into(&canonical_values, self.codes(), builder)
121-
}
122-
// Non-string case: take and then canonicalize
123-
_ => take_into(self.values(), self.codes(), builder),
124-
}
125-
}
126109
}
127110

128111
impl ArrayValidityImpl for DictArray {

encodings/fsst/src/compute/mod.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ mod compare;
22
mod filter;
33

44
use vortex_array::arrays::VarBinArray;
5-
use vortex_array::builders::ArrayBuilder;
65
use vortex_array::compute::{TakeFn, fill_null, take};
76
use vortex_array::vtable::ComputeVTable;
87
use vortex_array::{Array, ArrayExt, ArrayRef};
@@ -35,13 +34,4 @@ impl TakeFn<&FSSTArray> for FSSTEncoding {
3534
)?
3635
.into_array())
3736
}
38-
39-
fn take_into(
40-
&self,
41-
array: &FSSTArray,
42-
indices: &dyn Array,
43-
builder: &mut dyn ArrayBuilder,
44-
) -> VortexResult<()> {
45-
builder.extend_from_array(&take(array, indices)?)
46-
}
4737
}

vortex-array/src/arrays/bool/compute/take.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use vortex_mask::Mask;
77
use vortex_scalar::Scalar;
88

99
use crate::arrays::{BoolArray, BoolEncoding, ConstantArray};
10-
use crate::builders::ArrayBuilder;
1110
use crate::compute::{TakeFn, fill_null};
1211
use crate::variants::PrimitiveArrayTrait;
1312
use crate::{Array, ArrayRef, ToCanonical};
@@ -32,15 +31,6 @@ impl TakeFn<&BoolArray> for BoolEncoding {
3231

3332
Ok(BoolArray::new(buffer, array.validity().take(indices)?).into_array())
3433
}
35-
36-
fn take_into(
37-
&self,
38-
array: &BoolArray,
39-
indices: &dyn Array,
40-
builder: &mut dyn ArrayBuilder,
41-
) -> VortexResult<()> {
42-
builder.extend_from_array(&self.take(array, indices)?)
43-
}
4434
}
4535

4636
fn take_valid_indices<I: AsPrimitive<usize>>(

vortex-array/src/arrays/primitive/compute/take.rs

Lines changed: 2 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ use vortex_dtype::{
77
NativePType, Nullability, PType, match_each_integer_ptype, match_each_native_ptype,
88
match_each_native_simd_ptype, match_each_unsigned_integer_ptype,
99
};
10-
use vortex_error::{VortexResult, vortex_err};
11-
use vortex_mask::Mask;
10+
use vortex_error::VortexResult;
1211

1312
use crate::arrays::PrimitiveEncoding;
1413
use crate::arrays::primitive::PrimitiveArray;
15-
use crate::builders::{ArrayBuilder, PrimitiveBuilder};
1614
use crate::compute::TakeFn;
1715
use crate::variants::PrimitiveArrayTrait;
1816
use crate::{Array, ArrayRef, ToCanonical};
@@ -51,43 +49,6 @@ impl TakeFn<&PrimitiveArray> for PrimitiveEncoding {
5149
})
5250
})
5351
}
54-
55-
fn take_into(
56-
&self,
57-
array: &PrimitiveArray,
58-
indices: &dyn Array,
59-
builder: &mut dyn ArrayBuilder,
60-
) -> VortexResult<()> {
61-
let indices = indices.to_primitive()?;
62-
let mask = array.validity().take(&indices)?.to_mask(indices.len())?;
63-
64-
match_each_native_ptype!(array.ptype(), |$T| {
65-
match_each_integer_ptype!(indices.ptype(), |$I| {
66-
take_into_impl(array.as_slice::<$T>(), indices.as_slice::<$I>(), mask, builder)
67-
})
68-
})
69-
}
70-
}
71-
72-
fn take_into_impl<T: NativePType, I: NativePType + AsPrimitive<usize>>(
73-
array: &[T],
74-
indices: &[I],
75-
mask: Mask,
76-
builder: &mut dyn ArrayBuilder,
77-
) -> VortexResult<()> {
78-
assert_eq!(indices.len(), mask.len());
79-
80-
let builder = builder
81-
.as_any_mut()
82-
.downcast_mut::<PrimitiveBuilder<T>>()
83-
.ok_or_else(|| {
84-
vortex_err!(
85-
"Failed to downcast builder to PrimitiveBuilder<{}>",
86-
T::PTYPE
87-
)
88-
})?;
89-
builder.extend_with_iterator(indices.iter().map(|idx| array[idx.as_()]), mask);
90-
Ok(())
9152
}
9253

9354
fn take_primitive<T: NativePType, I: NativePType + AsPrimitive<usize>>(
@@ -167,14 +128,12 @@ where
167128
#[cfg(test)]
168129
mod test {
169130
use vortex_buffer::buffer;
170-
use vortex_dtype::Nullability;
171131
use vortex_scalar::Scalar;
172132

173133
use crate::array::Array;
174134
use crate::arrays::primitive::compute::take::take_primitive;
175135
use crate::arrays::{BoolArray, PrimitiveArray};
176-
use crate::builders::{ArrayBuilder as _, PrimitiveBuilder};
177-
use crate::compute::{take, take_into};
136+
use crate::compute::take;
178137
use crate::validity::Validity;
179138

180139
#[test]
@@ -201,50 +160,4 @@ mod test {
201160
// the third index is null
202161
assert_eq!(actual.scalar_at(2).unwrap(), Scalar::null_typed::<i32>());
203162
}
204-
205-
#[test]
206-
fn test_take_into() {
207-
let values = PrimitiveArray::new(buffer![1i32, 2, 3, 4, 5], Validity::NonNullable);
208-
let all_valid_indices = PrimitiveArray::new(
209-
buffer![0, 3, 4],
210-
Validity::Array(BoolArray::from_iter([true, true, true]).into_array()),
211-
);
212-
let mut builder = PrimitiveBuilder::<i32>::new(Nullability::Nullable);
213-
take_into(&values, &all_valid_indices, &mut builder).unwrap();
214-
let actual = builder.finish();
215-
assert_eq!(actual.scalar_at(0).unwrap(), Scalar::from(Some(1)));
216-
assert_eq!(actual.scalar_at(1).unwrap(), Scalar::from(Some(4)));
217-
assert_eq!(actual.scalar_at(2).unwrap(), Scalar::from(Some(5)));
218-
219-
let mixed_valid_indices = PrimitiveArray::new(
220-
buffer![0, 3, 4],
221-
Validity::Array(BoolArray::from_iter([true, true, false]).into_array()),
222-
);
223-
let mut builder = PrimitiveBuilder::<i32>::new(Nullability::Nullable);
224-
take_into(&values, &mixed_valid_indices, &mut builder).unwrap();
225-
let actual = builder.finish();
226-
assert_eq!(actual.scalar_at(0).unwrap(), Scalar::from(Some(1)));
227-
assert_eq!(actual.scalar_at(1).unwrap(), Scalar::from(Some(4)));
228-
// the third index is null
229-
assert_eq!(actual.scalar_at(2).unwrap(), Scalar::null_typed::<i32>());
230-
231-
let all_invalid_indices = PrimitiveArray::new(
232-
buffer![0, 3, 4],
233-
Validity::Array(BoolArray::from_iter([false, false, false]).into_array()),
234-
);
235-
let mut builder = PrimitiveBuilder::<i32>::new(Nullability::Nullable);
236-
take_into(&values, &all_invalid_indices, &mut builder).unwrap();
237-
let actual = builder.finish();
238-
assert_eq!(actual.scalar_at(0).unwrap(), Scalar::null_typed::<i32>());
239-
assert_eq!(actual.scalar_at(1).unwrap(), Scalar::null_typed::<i32>());
240-
assert_eq!(actual.scalar_at(2).unwrap(), Scalar::null_typed::<i32>());
241-
242-
let non_null_indices = PrimitiveArray::new(buffer![0, 3, 4], Validity::NonNullable);
243-
let mut builder = PrimitiveBuilder::<i32>::new(Nullability::NonNullable);
244-
take_into(&values, &non_null_indices, &mut builder).unwrap();
245-
let actual = builder.finish();
246-
assert_eq!(actual.scalar_at(0).unwrap(), Scalar::from(1));
247-
assert_eq!(actual.scalar_at(1).unwrap(), Scalar::from(4));
248-
assert_eq!(actual.scalar_at(2).unwrap(), Scalar::from(5));
249-
}
250163
}

vortex-array/src/arrays/varbinview/compute/mod.rs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ mod tests {
2424
use crate::accessor::ArrayAccessor;
2525
use crate::array::Array;
2626
use crate::arrays::VarBinViewArray;
27-
use crate::builders::{ArrayBuilder, VarBinViewBuilder};
2827
use crate::canonical::ToCanonical;
2928
use crate::compute::conformance::mask::test_mask;
30-
use crate::compute::{take, take_into};
29+
use crate::compute::take;
3130

3231
#[test]
3332
fn take_nullable() {
@@ -69,33 +68,4 @@ mod tests {
6968
Some("five"),
7069
]));
7170
}
72-
73-
#[test]
74-
fn take_into_nullable() {
75-
let arr = VarBinViewArray::from_iter_nullable_str([
76-
Some("one"),
77-
None,
78-
Some("three"),
79-
Some("four"),
80-
None,
81-
Some("six"),
82-
]);
83-
84-
let mut builder = VarBinViewBuilder::with_capacity(arr.dtype().clone(), arr.len());
85-
86-
take_into(&arr, &buffer![0, 3].into_array(), &mut builder).unwrap();
87-
88-
let taken = builder.finish();
89-
assert!(taken.dtype().is_nullable());
90-
assert_eq!(
91-
taken
92-
.to_varbinview()
93-
.unwrap()
94-
.with_iterator(|it| it
95-
.map(|v| v.map(|b| unsafe { String::from_utf8_unchecked(b.to_vec()) }))
96-
.collect::<Vec<_>>())
97-
.unwrap(),
98-
[Some("one".to_string()), Some("four".to_string())]
99-
);
100-
}
10171
}

vortex-array/src/arrays/varbinview/compute/take.rs

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
use std::ops::Deref;
22

33
use num_traits::AsPrimitive;
4-
use vortex_buffer::{Buffer, ByteBuffer};
4+
use vortex_buffer::Buffer;
55
use vortex_dtype::match_each_integer_ptype;
6-
use vortex_error::{VortexResult, vortex_bail};
7-
use vortex_mask::Mask;
6+
use vortex_error::VortexResult;
87

98
use crate::arrays::{BinaryView, VarBinViewArray, VarBinViewEncoding};
10-
use crate::builders::{ArrayBuilder, VarBinViewBuilder};
119
use crate::compute::TakeFn;
1210
use crate::variants::PrimitiveArrayTrait;
1311
use crate::{Array, ArrayRef, ToCanonical};
@@ -37,58 +35,6 @@ impl TakeFn<&VarBinViewArray> for VarBinViewEncoding {
3735
)?
3836
.into_array())
3937
}
40-
41-
fn take_into(
42-
&self,
43-
array: &VarBinViewArray,
44-
indices: &dyn Array,
45-
builder: &mut dyn ArrayBuilder,
46-
) -> VortexResult<()> {
47-
if array.len() == 0 {
48-
vortex_bail!("Cannot take_into from an empty array");
49-
}
50-
51-
let Some(builder) = builder.as_any_mut().downcast_mut::<VarBinViewBuilder>() else {
52-
vortex_bail!(
53-
"Cannot take_into a non-varbinview builder {:?}",
54-
builder.as_any().type_id()
55-
);
56-
};
57-
// Compute the new validity
58-
59-
// This is valid since all elements (of all arrays) even null values are inside must be the
60-
// min-max valid range.
61-
let validity = array.validity().take(indices)?;
62-
let mask = validity.to_mask(indices.len())?;
63-
let indices = indices.to_primitive()?;
64-
65-
match_each_integer_ptype!(indices.ptype(), |$I| {
66-
// This is valid since all elements even null values are inside the min-max valid range.
67-
take_views_into(array.views(), array.buffers(), indices.as_slice::<$I>(), mask, builder)?;
68-
});
69-
70-
Ok(())
71-
}
72-
}
73-
74-
fn take_views_into<I: AsPrimitive<usize>>(
75-
views: &Buffer<BinaryView>,
76-
buffers: &[ByteBuffer],
77-
indices: &[I],
78-
mask: Mask,
79-
builder: &mut VarBinViewBuilder,
80-
) -> VortexResult<()> {
81-
let buffers_offset = u32::try_from(builder.completed_block_count())?;
82-
// NOTE(ngates): this deref is not actually trivial, so we run it once.
83-
let views_ref = views.deref();
84-
builder.push_buffer_and_adjusted_views(
85-
buffers.iter().cloned(),
86-
indices
87-
.iter()
88-
.map(|i| views_ref[i.as_()].offset_view(buffers_offset)),
89-
mask,
90-
);
91-
Ok(())
9238
}
9339

9440
fn take_views<I: AsPrimitive<usize>>(

vortex-array/src/compute/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub use nan_count::*;
2828
pub use numeric::*;
2929
pub use search_sorted::*;
3030
pub use sum::*;
31-
pub use take::{TakeFn, take, take_into};
31+
pub use take::{TakeFn, take};
3232
pub use take_from::TakeFromFn;
3333
use vortex_dtype::DType;
3434
use vortex_error::{VortexError, VortexExpect, VortexResult, vortex_bail, vortex_err};

0 commit comments

Comments
 (0)