Skip to content

Commit 46b29c2

Browse files
committed
take nullability chunked array failure
Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
1 parent 61dfc79 commit 46b29c2

File tree

1 file changed

+41
-3
lines changed
  • vortex-array/src/arrays/chunked/compute

1 file changed

+41
-3
lines changed

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

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use vortex_buffer::BufferMut;
2-
use vortex_dtype::PType;
2+
use vortex_dtype::{DType, PType};
33
use vortex_error::VortexResult;
44

55
use crate::arrays::ChunkedVTable;
@@ -9,7 +9,11 @@ use crate::{Array, ArrayRef, IntoArray, ToCanonical, register_kernel};
99

1010
impl TakeKernel for ChunkedVTable {
1111
fn take(&self, array: &ChunkedArray, indices: &dyn Array) -> VortexResult<ArrayRef> {
12-
let indices = cast(indices, PType::U64.into())?.to_primitive()?;
12+
let indices = cast(
13+
indices,
14+
&DType::Primitive(PType::U64, indices.dtype().nullability()),
15+
)?
16+
.to_primitive()?;
1317

1418
// While the chunk idx remains the same, accumulate a list of chunk indices.
1519
let mut chunks = Vec::new();
@@ -37,7 +41,14 @@ impl TakeKernel for ChunkedVTable {
3741
chunks.push(take(array.chunk(prev_chunk_idx)?, &indices_in_chunk_array)?);
3842
}
3943

40-
Ok(ChunkedArray::new_unchecked(chunks, array.dtype().clone()).into_array())
44+
Ok(ChunkedArray::new_unchecked(
45+
chunks,
46+
array
47+
.dtype()
48+
.clone()
49+
.union_nullability(indices.dtype().nullability()),
50+
)
51+
.into_array())
4152
}
4253
}
4354

@@ -50,8 +61,10 @@ mod test {
5061
use crate::IntoArray;
5162
use crate::array::Array;
5263
use crate::arrays::chunked::ChunkedArray;
64+
use crate::arrays::{BoolArray, PrimitiveArray, StructArray};
5365
use crate::canonical::ToCanonical;
5466
use crate::compute::take;
67+
use crate::validity::Validity;
5568

5669
#[test]
5770
fn test_take() {
@@ -68,4 +81,29 @@ mod test {
6881
.unwrap();
6982
assert_eq!(result.as_slice::<i32>(), &[1, 1, 1, 2]);
7083
}
84+
85+
#[test]
86+
fn test_take_nullability() {
87+
let struct_array =
88+
StructArray::try_new([].into(), vec![], 100, Validity::NonNullable).unwrap();
89+
90+
let arr = ChunkedArray::from_iter(vec![struct_array.to_array(), struct_array.to_array()]);
91+
92+
let result = take(
93+
arr.as_ref(),
94+
PrimitiveArray::from_option_iter(vec![Some(0), None, Some(101)]).as_ref(),
95+
)
96+
.unwrap();
97+
98+
let expect = StructArray::try_new(
99+
[].into(),
100+
vec![],
101+
2,
102+
Validity::Array(BoolArray::from_iter(vec![true, false]).to_array()),
103+
)
104+
.unwrap();
105+
assert_eq!(result.dtype(), expect.dtype());
106+
assert_eq!(result.scalar_at(0).unwrap(), expect.scalar_at(0).unwrap());
107+
assert_eq!(result.scalar_at(1).unwrap(), expect.scalar_at(1).unwrap());
108+
}
71109
}

0 commit comments

Comments
 (0)