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
108 lines (100 loc) · 2.97 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
98
99
100
101
102
103
104
105
106
107
108
mod basic;
mod decimal;
mod time;
use arrow2::array::*;
use arrow2::compute::arithmetics::*;
use arrow2::datatypes::DataType::*;
use arrow2::datatypes::{IntervalUnit, TimeUnit};
use arrow2::scalar::PrimitiveScalar;
#[test]
fn test_add() {
let a = Int32Array::from(&[None, Some(6), None, Some(6)]);
let b = Int32Array::from(&[Some(5), None, None, Some(6)]);
let result = add(&a, &b);
let expected = Int32Array::from(&[None, None, None, Some(12)]);
assert_eq!(expected, result.as_ref());
}
#[test]
fn test_add_scalar() {
let a = Int32Array::from(&[None, Some(6), None, Some(6)]);
let b: PrimitiveScalar<i32> = Some(1i32).into();
let result = add_scalar(&a, &b);
let expected = Int32Array::from(&[None, Some(7), None, Some(7)]);
assert_eq!(expected, result.as_ref());
}
#[test]
fn consistency() {
let datatypes = vec![
Null,
Boolean,
UInt8,
UInt16,
UInt32,
UInt64,
Int8,
Int16,
Int32,
Int64,
Float32,
Float64,
Timestamp(TimeUnit::Second, None),
Timestamp(TimeUnit::Millisecond, None),
Timestamp(TimeUnit::Microsecond, None),
Timestamp(TimeUnit::Nanosecond, None),
Time64(TimeUnit::Microsecond),
Time64(TimeUnit::Nanosecond),
Date32,
Time32(TimeUnit::Second),
Time32(TimeUnit::Millisecond),
Date64,
Utf8,
LargeUtf8,
Binary,
LargeBinary,
Duration(TimeUnit::Second),
Duration(TimeUnit::Millisecond),
Duration(TimeUnit::Microsecond),
Duration(TimeUnit::Nanosecond),
Interval(IntervalUnit::MonthDayNano),
];
let cases = datatypes.clone().into_iter().zip(datatypes.into_iter());
cases.for_each(|(lhs, rhs)| {
let lhs_a = new_empty_array(lhs.clone());
let rhs_a = new_empty_array(rhs.clone());
if can_add(&lhs, &rhs) {
add(lhs_a.as_ref(), rhs_a.as_ref());
}
if can_sub(&lhs, &rhs) {
sub(lhs_a.as_ref(), rhs_a.as_ref());
}
if can_mul(&lhs, &rhs) {
mul(lhs_a.as_ref(), rhs_a.as_ref());
}
if can_div(&lhs, &rhs) {
div(lhs_a.as_ref(), rhs_a.as_ref());
}
if can_rem(&lhs, &rhs) {
rem(lhs_a.as_ref(), rhs_a.as_ref());
}
});
}
#[test]
fn test_neg() {
let a = Int32Array::from(&[None, Some(6), None, Some(6)]);
let result = neg(&a);
let expected = Int32Array::from(&[None, Some(-6), None, Some(-6)]);
assert_eq!(expected, result.as_ref());
}
#[test]
fn test_neg_dict() {
let a = DictionaryArray::<u8>::from_data(
UInt8Array::from_slice(&[0, 0, 1]),
std::sync::Arc::new(Int8Array::from_slice(&[1, 2])),
);
let result = neg(&a);
let expected = DictionaryArray::<u8>::from_data(
UInt8Array::from_slice(&[0, 0, 1]),
std::sync::Arc::new(Int8Array::from_slice(&[-1, -2])),
);
assert_eq!(expected, result.as_ref());
}