This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 221
/
mod.rs
97 lines (82 loc) · 2.66 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
use arrow2::{array::FixedSizeBinaryArray, bitmap::Bitmap, buffer::Buffer, datatypes::DataType};
mod mutable;
#[test]
fn basics() {
let array = FixedSizeBinaryArray::from_data(
DataType::FixedSizeBinary(2),
Buffer::from(vec![1, 2, 3, 4, 5, 6]),
Some(Bitmap::from([true, false, true])),
);
assert_eq!(array.size(), 2);
assert_eq!(array.len(), 3);
assert_eq!(array.validity(), Some(&Bitmap::from([true, false, true])));
assert_eq!(array.value(0), [1, 2]);
assert_eq!(array.value(2), [5, 6]);
let array = array.slice(1, 2);
assert_eq!(array.value(1), [5, 6]);
}
#[test]
fn with_validity() {
let values = Buffer::from(vec![1, 2, 3, 4, 5, 6]);
let a = FixedSizeBinaryArray::new(DataType::FixedSizeBinary(2), values, None);
let a = a.with_validity(Some(Bitmap::from([true, false, true])));
assert!(a.validity().is_some());
}
#[test]
fn debug() {
let values = Buffer::from(vec![1, 2, 3, 4, 5, 6]);
let a = FixedSizeBinaryArray::from_data(
DataType::FixedSizeBinary(2),
values,
Some(Bitmap::from([true, false, true])),
);
assert_eq!(
format!("{:?}", a),
"FixedSizeBinary(2)[[1, 2], None, [5, 6]]"
);
}
#[test]
fn empty() {
let array = FixedSizeBinaryArray::new_empty(DataType::FixedSizeBinary(2));
assert_eq!(array.values().len(), 0);
assert_eq!(array.validity(), None);
}
#[test]
fn null() {
let array = FixedSizeBinaryArray::new_null(DataType::FixedSizeBinary(2), 2);
assert_eq!(array.values().len(), 4);
assert_eq!(array.validity().cloned(), Some([false, false].into()));
}
#[test]
fn from_iter() {
let iter = std::iter::repeat(vec![1u8, 2]).take(2).map(Some);
let a = FixedSizeBinaryArray::from_iter(iter, 2);
assert_eq!(a.len(), 2);
}
#[test]
fn wrong_size() {
let values = Buffer::from(b"abb".to_vec());
assert!(FixedSizeBinaryArray::try_new(DataType::FixedSizeBinary(2), values, None).is_err());
}
#[test]
fn wrong_len() {
let values = Buffer::from(b"abba".to_vec());
let validity = Some([true, false, false].into()); // it should be 2
assert!(FixedSizeBinaryArray::try_new(DataType::FixedSizeBinary(2), values, validity).is_err());
}
#[test]
fn wrong_data_type() {
let values = Buffer::from(b"abba".to_vec());
assert!(FixedSizeBinaryArray::try_new(DataType::Binary, values, None).is_err());
}
#[test]
fn to() {
let values = Buffer::from(b"abba".to_vec());
let a = FixedSizeBinaryArray::new(DataType::FixedSizeBinary(2), values, None);
let extension = DataType::Extension(
"a".to_string(),
Box::new(DataType::FixedSizeBinary(2)),
None,
);
let _ = a.to(extension);
}