forked from apache/iceberg-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_utils.rs
More file actions
184 lines (162 loc) · 6.22 KB
/
test_utils.rs
File metadata and controls
184 lines (162 loc) · 6.22 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
use std::collections::HashMap;
use super::blob::Blob;
use crate::io::{FileIOBuilder, InputFile};
use crate::puffin::compression::CompressionCodec;
use crate::puffin::metadata::{BlobMetadata, FileMetadata, CREATED_BY_PROPERTY};
const JAVA_TESTDATA: &str = "testdata/puffin/java-generated";
const EMPTY_UNCOMPRESSED: &str = "empty-puffin-uncompressed.bin";
const METRIC_UNCOMPRESSED: &str = "sample-metric-data-uncompressed.bin";
const METRIC_ZSTD_COMPRESSED: &str = "sample-metric-data-compressed-zstd.bin";
fn input_file_for_test_data(path: &str) -> InputFile {
FileIOBuilder::new_fs_io()
.build()
.unwrap()
.new_input(env!("CARGO_MANIFEST_DIR").to_owned() + "/" + path)
.unwrap()
}
pub(crate) fn java_empty_uncompressed_input_file() -> InputFile {
input_file_for_test_data(&[JAVA_TESTDATA, EMPTY_UNCOMPRESSED].join("/"))
}
pub(crate) fn java_uncompressed_metric_input_file() -> InputFile {
input_file_for_test_data(&[JAVA_TESTDATA, METRIC_UNCOMPRESSED].join("/"))
}
pub(crate) fn java_zstd_compressed_metric_input_file() -> InputFile {
input_file_for_test_data(&[JAVA_TESTDATA, METRIC_ZSTD_COMPRESSED].join("/"))
}
pub(crate) fn empty_footer_payload() -> FileMetadata {
FileMetadata {
blobs: Vec::new(),
properties: HashMap::new(),
}
}
pub(crate) fn empty_footer_payload_bytes() -> Vec<u8> {
serde_json::to_string::<FileMetadata>(&empty_footer_payload())
.unwrap()
.as_bytes()
.to_vec()
}
pub(crate) fn empty_footer_payload_bytes_length_bytes() -> [u8; 4] {
u32::to_le_bytes(empty_footer_payload_bytes().len() as u32)
}
pub(crate) const METRIC_BLOB_0_TYPE: &str = "some-blob";
pub(crate) const METRIC_BLOB_0_INPUT_FIELDS: [i32; 1] = [1];
pub(crate) const METRIC_BLOB_0_SNAPSHOT_ID: i64 = 2;
pub(crate) const METRIC_BLOB_0_SEQUENCE_NUMBER: i64 = 1;
pub(crate) const METRIC_BLOB_0_DATA: &str = "abcdefghi";
pub(crate) fn zstd_compressed_metric_blob_0_metadata() -> BlobMetadata {
BlobMetadata {
r#type: METRIC_BLOB_0_TYPE.to_string(),
fields: METRIC_BLOB_0_INPUT_FIELDS.to_vec(),
snapshot_id: METRIC_BLOB_0_SNAPSHOT_ID,
sequence_number: METRIC_BLOB_0_SEQUENCE_NUMBER,
offset: 4,
length: 22,
compression_codec: CompressionCodec::Zstd,
properties: HashMap::new(),
}
}
pub(crate) fn uncompressed_metric_blob_0_metadata() -> BlobMetadata {
BlobMetadata {
r#type: METRIC_BLOB_0_TYPE.to_string(),
fields: METRIC_BLOB_0_INPUT_FIELDS.to_vec(),
snapshot_id: METRIC_BLOB_0_SNAPSHOT_ID,
sequence_number: METRIC_BLOB_0_SEQUENCE_NUMBER,
offset: 4,
length: 9,
compression_codec: CompressionCodec::None,
properties: HashMap::new(),
}
}
pub(crate) fn blob_0() -> Blob {
Blob {
r#type: METRIC_BLOB_0_TYPE.to_string(),
fields: METRIC_BLOB_0_INPUT_FIELDS.to_vec(),
snapshot_id: METRIC_BLOB_0_SNAPSHOT_ID,
sequence_number: METRIC_BLOB_0_SEQUENCE_NUMBER,
data: METRIC_BLOB_0_DATA.as_bytes().to_vec(),
properties: HashMap::new(),
}
}
pub(crate) const METRIC_BLOB_1_TYPE: &str = "some-other-blob";
pub(crate) const METRIC_BLOB_1_INPUT_FIELDS: [i32; 1] = [2];
pub(crate) const METRIC_BLOB_1_SNAPSHOT_ID: i64 = 2;
pub(crate) const METRIC_BLOB_1_SEQUENCE_NUMBER: i64 = 1;
pub(crate) const METRIC_BLOB_1_DATA: &str =
"some blob \u{0000} binary data 🤯 that is not very very very very very very long, is it?";
pub(crate) fn uncompressed_metric_blob_1_metadata() -> BlobMetadata {
BlobMetadata {
r#type: METRIC_BLOB_1_TYPE.to_string(),
fields: METRIC_BLOB_1_INPUT_FIELDS.to_vec(),
snapshot_id: METRIC_BLOB_1_SNAPSHOT_ID,
sequence_number: METRIC_BLOB_1_SEQUENCE_NUMBER,
offset: 13,
length: 83,
compression_codec: CompressionCodec::None,
properties: HashMap::new(),
}
}
pub(crate) fn zstd_compressed_metric_blob_1_metadata() -> BlobMetadata {
BlobMetadata {
r#type: METRIC_BLOB_1_TYPE.to_string(),
fields: METRIC_BLOB_1_INPUT_FIELDS.to_vec(),
snapshot_id: METRIC_BLOB_1_SNAPSHOT_ID,
sequence_number: METRIC_BLOB_1_SEQUENCE_NUMBER,
offset: 26,
length: 77,
compression_codec: CompressionCodec::Zstd,
properties: HashMap::new(),
}
}
pub(crate) fn blob_1() -> Blob {
Blob {
r#type: METRIC_BLOB_1_TYPE.to_string(),
fields: METRIC_BLOB_1_INPUT_FIELDS.to_vec(),
snapshot_id: METRIC_BLOB_1_SNAPSHOT_ID,
sequence_number: METRIC_BLOB_1_SEQUENCE_NUMBER,
data: METRIC_BLOB_1_DATA.as_bytes().to_vec(),
properties: HashMap::new(),
}
}
pub(crate) const CREATED_BY_PROPERTY_VALUE: &str = "Test 1234";
pub(crate) fn file_properties() -> HashMap<String, String> {
let mut properties = HashMap::new();
properties.insert(
CREATED_BY_PROPERTY.to_string(),
CREATED_BY_PROPERTY_VALUE.to_string(),
);
properties
}
pub(crate) fn uncompressed_metric_file_metadata() -> FileMetadata {
FileMetadata {
blobs: vec![
uncompressed_metric_blob_0_metadata(),
uncompressed_metric_blob_1_metadata(),
],
properties: file_properties(),
}
}
pub(crate) fn zstd_compressed_metric_file_metadata() -> FileMetadata {
FileMetadata {
blobs: vec![
zstd_compressed_metric_blob_0_metadata(),
zstd_compressed_metric_blob_1_metadata(),
],
properties: file_properties(),
}
}