Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-parquet/src/parquet/schema/io_thrift/mod.rs
8512 views
1
mod from_thrift;
2
3
mod to_thrift;
4
5
#[cfg(test)]
6
mod tests {
7
use crate::parquet::error::ParquetResult;
8
use crate::parquet::schema::io_message::from_message;
9
use crate::parquet::schema::types::ParquetType;
10
11
fn test_round_trip(message: &str) -> ParquetResult<()> {
12
let expected_schema = from_message(message)?;
13
let thrift_schema = expected_schema.to_thrift();
14
let thrift_schema = thrift_schema.into_iter().collect::<Vec<_>>();
15
let result_schema = ParquetType::try_from_thrift(&thrift_schema)?;
16
assert_eq!(result_schema, expected_schema);
17
Ok(())
18
}
19
20
#[test]
21
fn test_schema_type_thrift_conversion() {
22
let message_type = "
23
message conversions {
24
REQUIRED INT64 id;
25
OPTIONAL group int_array_Array (LIST) {
26
REPEATED group list {
27
OPTIONAL group element (LIST) {
28
REPEATED group list {
29
OPTIONAL INT32 element;
30
}
31
}
32
}
33
}
34
OPTIONAL group int_map (MAP) {
35
REPEATED group map (MAP_KEY_VALUE) {
36
REQUIRED BYTE_ARRAY key (UTF8);
37
OPTIONAL INT32 value;
38
}
39
}
40
OPTIONAL group int_Map_Array (LIST) {
41
REPEATED group list {
42
OPTIONAL group g (MAP) {
43
REPEATED group map (MAP_KEY_VALUE) {
44
REQUIRED BYTE_ARRAY key (UTF8);
45
OPTIONAL group value {
46
OPTIONAL group H {
47
OPTIONAL group i (LIST) {
48
REPEATED group list {
49
OPTIONAL DOUBLE element;
50
}
51
}
52
}
53
}
54
}
55
}
56
}
57
}
58
OPTIONAL group nested_struct {
59
OPTIONAL INT32 A;
60
OPTIONAL group b (LIST) {
61
REPEATED group list {
62
REQUIRED FIXED_LEN_BYTE_ARRAY (16) element;
63
}
64
}
65
}
66
}
67
";
68
test_round_trip(message_type).unwrap();
69
}
70
71
#[test]
72
fn test_schema_type_thrift_conversion_decimal() {
73
let message_type = "
74
message decimals {
75
OPTIONAL INT32 field0;
76
OPTIONAL INT64 field1 (DECIMAL (18, 2));
77
OPTIONAL FIXED_LEN_BYTE_ARRAY (16) field2 (DECIMAL (38, 18));
78
OPTIONAL BYTE_ARRAY field3 (DECIMAL (9));
79
}
80
";
81
test_round_trip(message_type).unwrap();
82
}
83
}
84
85