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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#[cfg(test)]
mod tests {
use helios_sof::{
ContentType, ParquetOptions, RunOptions, SofBundle, SofViewDefinition,
run_view_definition_with_options,
};
use serde_json::json;
#[test]
#[cfg(feature = "R4")]
fn test_parquet_large_dataset_with_chunking() {
// Create a ViewDefinition for patient data
let view_definition_json = json!({
"resourceType": "ViewDefinition",
"status": "active",
"resource": "Patient",
"select": [
{
"column": [
{
"name": "id",
"path": "id"
},
{
"name": "gender",
"path": "gender"
},
{
"name": "birthDate",
"path": "birthDate"
},
{
"name": "active",
"path": "active"
},
{
"name": "familyName",
"path": "name.family"
},
{
"name": "givenNames",
"path": "name.given",
"collection": true
}
]
}
]
});
// Generate a large bundle with 10,000 patients
let mut entries = Vec::new();
for i in 0..10000 {
entries.push(json!({
"resource": {
"resourceType": "Patient",
"id": format!("patient-{}", i),
"gender": if i % 3 == 0 { "male" } else if i % 3 == 1 { "female" } else { "other" },
"birthDate": format!("19{:02}-{:02}-{:02}",
50 + (i % 50), // Year between 1950-1999
1 + (i % 12), // Month 1-12
1 + (i % 28) // Day 1-28
),
"active": i % 2 == 0,
"name": [
{
"family": format!("Family{}", i % 100),
"given": vec![format!("Given{}", i), format!("Middle{}", i % 10)]
}
]
}
}));
}
let bundle_json = json!({
"resourceType": "Bundle",
"type": "collection",
"entry": entries
});
let view_definition =
serde_json::from_value::<helios_fhir::r4::ViewDefinition>(view_definition_json.clone())
.expect("Failed to parse ViewDefinition");
let bundle = serde_json::from_value::<helios_fhir::r4::Bundle>(bundle_json.clone())
.expect("Failed to parse Bundle");
let sof_view = SofViewDefinition::R4(view_definition);
let sof_bundle = SofBundle::R4(bundle);
// Test with custom parquet options
let options = RunOptions {
parquet_options: Some(ParquetOptions {
row_group_size_mb: 128, // Smaller row groups for testing
page_size_kb: 512,
compression: "zstd".to_string(),
max_file_size_mb: None,
}),
..Default::default()
};
let result = run_view_definition_with_options(
sof_view.clone(),
sof_bundle.clone(),
ContentType::Parquet,
options,
);
assert!(
result.is_ok(),
"Parquet export with custom options failed: {:?}",
result.err()
);
let parquet_data = result.unwrap();
assert!(!parquet_data.is_empty(), "Parquet data should not be empty");
assert!(
parquet_data.starts_with(b"PAR1"),
"Should start with PAR1 magic bytes"
);
assert!(
parquet_data.ends_with(b"PAR1"),
"Should end with PAR1 magic bytes"
);
// Verify the file size is reasonable for 10K records
// With zstd compression and efficient chunking, the file can be quite small
// Parquet has overhead but also excellent compression
let file_size = parquet_data.len();
assert!(
file_size > 10_000,
"File too small for 10K records: {} bytes",
file_size
);
assert!(
file_size < 10_000_000,
"File too large for 10K records: {} bytes",
file_size
);
}
#[test]
#[cfg(feature = "R4")]
fn test_parquet_compression_algorithms() {
let view_definition_json = json!({
"resourceType": "ViewDefinition",
"status": "active",
"resource": "Patient",
"select": [
{
"column": [
{
"name": "id",
"path": "id"
},
{
"name": "text",
"path": "text.div"
}
]
}
]
});
// Create test data with highly compressible text
let mut entries = Vec::new();
for i in 0..100 {
entries.push(json!({
"resource": {
"resourceType": "Patient",
"id": format!("patient-{}", i),
"text": {
"div": "This is a repeating text pattern. ".repeat(10)
}
}
}));
}
let bundle_json = json!({
"resourceType": "Bundle",
"type": "collection",
"entry": entries
});
let view_definition =
serde_json::from_value::<helios_fhir::r4::ViewDefinition>(view_definition_json.clone())
.expect("Failed to parse ViewDefinition");
let bundle = serde_json::from_value::<helios_fhir::r4::Bundle>(bundle_json.clone())
.expect("Failed to parse Bundle");
let sof_view = SofViewDefinition::R4(view_definition);
let sof_bundle = SofBundle::R4(bundle);
// Test different compression algorithms
let compressions = vec!["none", "snappy", "gzip", "zstd", "brotli"];
for compression in compressions {
let options = RunOptions {
parquet_options: Some(ParquetOptions {
row_group_size_mb: 256,
page_size_kb: 1024,
compression: compression.to_string(),
max_file_size_mb: None,
}),
..Default::default()
};
let result = run_view_definition_with_options(
sof_view.clone(),
sof_bundle.clone(),
ContentType::Parquet,
options,
);
assert!(
result.is_ok(),
"Parquet export with {} compression failed: {:?}",
compression,
result.err()
);
let parquet_data = result.unwrap();
let file_size = parquet_data.len();
// Due to parquet overhead, very small files might not follow expected compression ratios
// So we only check that the file was created successfully
assert!(
file_size > 0,
"Parquet file with {} compression should not be empty",
compression
);
// Verify magic bytes
assert!(
parquet_data.starts_with(b"PAR1") && parquet_data.ends_with(b"PAR1"),
"Invalid parquet file format with {} compression",
compression
);
}
}
#[test]
#[cfg(feature = "R4")]
fn test_parquet_row_group_configuration() {
let view_definition_json = json!({
"resourceType": "ViewDefinition",
"status": "active",
"resource": "Observation",
"select": [
{
"column": [
{
"name": "id",
"path": "id"
},
{
"name": "status",
"path": "status"
},
{
"name": "value",
"path": "valueQuantity.value"
}
]
}
]
});
// Create 1000 observations
let mut entries = Vec::new();
for i in 0..1000 {
entries.push(json!({
"resource": {
"resourceType": "Observation",
"id": format!("obs-{}", i),
"status": "final",
"valueQuantity": {
"value": 98.6 + (i as f64 * 0.01),
"unit": "F"
}
}
}));
}
let bundle_json = json!({
"resourceType": "Bundle",
"type": "collection",
"entry": entries
});
let view_definition =
serde_json::from_value::<helios_fhir::r4::ViewDefinition>(view_definition_json.clone())
.expect("Failed to parse ViewDefinition");
let bundle = serde_json::from_value::<helios_fhir::r4::Bundle>(bundle_json.clone())
.expect("Failed to parse Bundle");
let sof_view = SofViewDefinition::R4(view_definition);
let sof_bundle = SofBundle::R4(bundle);
// Test with different row group sizes
let row_group_configs = vec![
(64, 64), // Minimum row group size
(256, 1024), // Default configuration
(512, 2048), // Larger configuration
(1024, 4096), // Maximum row group size
];
for (row_group_mb, page_kb) in row_group_configs {
let options = RunOptions {
parquet_options: Some(ParquetOptions {
row_group_size_mb: row_group_mb,
page_size_kb: page_kb,
compression: "snappy".to_string(),
max_file_size_mb: None,
}),
..Default::default()
};
let result = run_view_definition_with_options(
sof_view.clone(),
sof_bundle.clone(),
ContentType::Parquet,
options,
);
assert!(
result.is_ok(),
"Parquet export with {}MB row groups failed: {:?}",
row_group_mb,
result.err()
);
let parquet_data = result.unwrap();
assert!(
!parquet_data.is_empty(),
"Parquet data with {}MB row groups should not be empty",
row_group_mb
);
// Verify the file is valid Parquet
assert!(
parquet_data.starts_with(b"PAR1") && parquet_data.ends_with(b"PAR1"),
"Invalid parquet file with {}MB row groups",
row_group_mb
);
}
}
}