Skip to content

Commit 791dbb7

Browse files
committed
chore: add take null test
1 parent 6f1a74d commit 791dbb7

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

src/datatypes/src/vectors/constant.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::fmt;
1717
use std::sync::Arc;
1818

1919
use arrow::array::{Array, ArrayRef, UInt32Array};
20-
use snafu::{ensure, IntoError, ResultExt};
20+
use snafu::{ensure, ResultExt};
2121

2222
use crate::data_type::ConcreteDataType;
2323
use crate::error::{self, Result, SerializeSnafu};
@@ -104,9 +104,7 @@ impl ConstantVector {
104104
)
105105
.unwrap()
106106
{
107-
return Err(error::ArrowComputeSnafu.into_error(
108-
arrow::error::ArrowError::ComputeError("Array index out of bounds".to_string()),
109-
));
107+
panic!("Array index out of bounds, cannot take index out of the length of the array: {len}");
110108
}
111109

112110
Ok(Arc::new(ConstantVector::new(

src/datatypes/src/vectors/operations/take.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ mod tests {
4343
use crate::types::{LogicalPrimitiveType, WrapperType};
4444
use crate::vectors::operations::VectorOp;
4545
use crate::vectors::{
46-
BooleanVector, ConstantVector, Int32Vector, PrimitiveVector, StringVector, UInt32Vector,
46+
BooleanVector, ConstantVector, Int32Vector, NullVector, PrimitiveVector, StringVector,
47+
UInt32Vector,
4748
};
4849

4950
fn check_take_primitive<T>(
@@ -132,6 +133,32 @@ mod tests {
132133
fn test_take_constant() {
133134
check_take_constant(2, 5, &[3, 4]);
134135
check_take_constant(3, 10, &[1, 2, 3]);
136+
check_take_constant(4, 10, &[1, 5, 3, 6]);
137+
check_take_constant(5, 10, &[1, 9, 8, 7, 3]);
138+
}
139+
140+
#[test]
141+
#[should_panic]
142+
fn test_take_constant_out_of_index() {
143+
check_take_constant(2, 5, &[3, 5]);
144+
}
145+
146+
#[test]
147+
#[should_panic]
148+
fn test_take_out_of_index() {
149+
let v = Int32Vector::from_slice(&[1, 2, 3, 4, 5]);
150+
let indies = UInt32Vector::from_slice(&[1, 5, 6]);
151+
v.take(&indies).unwrap();
152+
}
153+
154+
#[test]
155+
fn test_take_null() {
156+
let v = NullVector::new(5);
157+
let indices = UInt32Vector::from_slice([1, 3, 2]);
158+
let out = v.take(&indices).unwrap();
159+
160+
let expect: VectorRef = Arc::new(NullVector::new(3));
161+
assert_eq!(expect, out);
135162
}
136163

137164
#[test]

0 commit comments

Comments
 (0)