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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
use std::cmp::Ordering;
use crate::array::*;
use crate::datatypes::*;
use crate::error::{ArrowError, Result};
use TimeUnit::*;
pub trait OrdArray: Array {
fn cmp_value(&self, i: usize, j: usize) -> Ordering;
}
impl<T: ArrowPrimitiveType> OrdArray for PrimitiveArray<T>
where
T::Native: std::cmp::Ord,
{
fn cmp_value(&self, i: usize, j: usize) -> Ordering {
self.value(i).cmp(&self.value(j))
}
}
impl OrdArray for StringArray {
fn cmp_value(&self, i: usize, j: usize) -> Ordering {
self.value(i).cmp(self.value(j))
}
}
impl OrdArray for NullArray {
fn cmp_value(&self, _i: usize, _j: usize) -> Ordering {
Ordering::Equal
}
}
pub fn as_ordarray(values: &ArrayRef) -> Result<Box<&OrdArray>> {
match values.data_type() {
DataType::Boolean => Ok(Box::new(as_boolean_array(&values))),
DataType::Utf8 => Ok(Box::new(as_string_array(&values))),
DataType::Null => Ok(Box::new(as_null_array(&values))),
DataType::Int8 => Ok(Box::new(as_primitive_array::<Int8Type>(&values))),
DataType::Int16 => Ok(Box::new(as_primitive_array::<Int16Type>(&values))),
DataType::Int32 => Ok(Box::new(as_primitive_array::<Int32Type>(&values))),
DataType::Int64 => Ok(Box::new(as_primitive_array::<Int64Type>(&values))),
DataType::UInt8 => Ok(Box::new(as_primitive_array::<UInt8Type>(&values))),
DataType::UInt16 => Ok(Box::new(as_primitive_array::<UInt16Type>(&values))),
DataType::UInt32 => Ok(Box::new(as_primitive_array::<UInt32Type>(&values))),
DataType::UInt64 => Ok(Box::new(as_primitive_array::<UInt64Type>(&values))),
DataType::Date32(_) => Ok(Box::new(as_primitive_array::<Date32Type>(&values))),
DataType::Date64(_) => Ok(Box::new(as_primitive_array::<Date64Type>(&values))),
DataType::Time32(Second) => {
Ok(Box::new(as_primitive_array::<Time32SecondType>(&values)))
}
DataType::Time32(Millisecond) => Ok(Box::new(as_primitive_array::<
Time32MillisecondType,
>(&values))),
DataType::Time64(Microsecond) => Ok(Box::new(as_primitive_array::<
Time64MicrosecondType,
>(&values))),
DataType::Time64(Nanosecond) => Ok(Box::new(as_primitive_array::<
Time64NanosecondType,
>(&values))),
DataType::Timestamp(Second, _) => {
Ok(Box::new(as_primitive_array::<TimestampSecondType>(&values)))
}
DataType::Timestamp(Millisecond, _) => Ok(Box::new(as_primitive_array::<
TimestampMillisecondType,
>(&values))),
DataType::Timestamp(Microsecond, _) => Ok(Box::new(as_primitive_array::<
TimestampMicrosecondType,
>(&values))),
DataType::Timestamp(Nanosecond, _) => Ok(Box::new(as_primitive_array::<
TimestampNanosecondType,
>(&values))),
DataType::Interval(IntervalUnit::YearMonth) => Ok(Box::new(
as_primitive_array::<IntervalYearMonthType>(&values),
)),
DataType::Interval(IntervalUnit::DayTime) => {
Ok(Box::new(as_primitive_array::<IntervalDayTimeType>(&values)))
}
DataType::Duration(TimeUnit::Second) => {
Ok(Box::new(as_primitive_array::<DurationSecondType>(&values)))
}
DataType::Duration(TimeUnit::Millisecond) => Ok(Box::new(as_primitive_array::<
DurationMillisecondType,
>(&values))),
DataType::Duration(TimeUnit::Microsecond) => Ok(Box::new(as_primitive_array::<
DurationMicrosecondType,
>(&values))),
DataType::Duration(TimeUnit::Nanosecond) => Ok(Box::new(as_primitive_array::<
DurationNanosecondType,
>(&values))),
t => Err(ArrowError::ComputeError(format!(
"Lexical Sort not supported for data type {:?}",
t
))),
}
}