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
use parquet_format_async_temp::LogicalType;
use crate::schema::types::{PhysicalType, PrimitiveConvertedType};
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum SortOrder {
Signed,
Unsigned,
Undefined,
}
pub fn get_sort_order(
logical_type: &Option<LogicalType>,
converted_type: &Option<PrimitiveConvertedType>,
physical_type: &PhysicalType,
) -> SortOrder {
if let Some(logical_type) = logical_type {
return get_logical_sort_order(logical_type);
};
if let Some(converted_type) = converted_type {
return get_converted_sort_order(converted_type);
};
get_physical_sort_order(physical_type)
}
fn get_logical_sort_order(logical_type: &LogicalType) -> SortOrder {
use LogicalType::*;
match logical_type {
STRING(_) | ENUM(_) | JSON(_) | BSON(_) => SortOrder::Unsigned,
INTEGER(t) => match t.is_signed {
true => SortOrder::Signed,
false => SortOrder::Unsigned,
},
MAP(_) | LIST(_) => SortOrder::Undefined,
DECIMAL(_) => SortOrder::Signed,
DATE(_) => SortOrder::Signed,
TIME(_) => SortOrder::Signed,
TIMESTAMP(_) => SortOrder::Signed,
UNKNOWN(_) => SortOrder::Undefined,
UUID(_) => SortOrder::Unsigned,
}
}
fn get_converted_sort_order(converted_type: &PrimitiveConvertedType) -> SortOrder {
use PrimitiveConvertedType::*;
match converted_type {
Utf8 | Json | Bson | Enum => SortOrder::Unsigned,
Int8 | Int16 | Int32 | Int64 => SortOrder::Signed,
Uint8 | Uint16 | Uint32 | Uint64 => SortOrder::Unsigned,
Decimal(_, _) => SortOrder::Signed,
Date => SortOrder::Signed,
TimeMillis | TimeMicros | TimestampMillis | TimestampMicros => SortOrder::Signed,
Interval => SortOrder::Undefined,
}
}
fn get_physical_sort_order(physical_type: &PhysicalType) -> SortOrder {
use PhysicalType::*;
match physical_type {
Boolean => SortOrder::Unsigned,
Int32 | Int64 => SortOrder::Signed,
Int96 => SortOrder::Undefined,
Float | Double => SortOrder::Signed,
ByteArray | FixedLenByteArray(_) => SortOrder::Unsigned,
}
}