(
path: &Path,
columns: Vec<(&str, Vec<i32>)>,
max_row_group_size: Option<usize>,
)
| 27 | use serde::de::DeserializeOwned; |
| 28 | |
| 29 | pub(crate) fn write_int_parquet_file( |
| 30 | path: &Path, |
| 31 | columns: Vec<(&str, Vec<i32>)>, |
| 32 | max_row_group_size: Option<usize>, |
| 33 | ) { |
| 34 | let schema = Arc::new(ArrowSchema::new( |
| 35 | columns |
| 36 | .iter() |
| 37 | .map(|(name, _)| ArrowField::new(*name, ArrowDataType::Int32, false)) |
| 38 | .collect::<Vec<_>>(), |
| 39 | )); |
| 40 | let arrays: Vec<Arc<dyn Array>> = columns |
| 41 | .iter() |
| 42 | .map(|(_, values)| Arc::new(Int32Array::from(values.clone())) as Arc<dyn Array>) |
| 43 | .collect(); |
| 44 | let batch = RecordBatch::try_new(schema.clone(), arrays).unwrap(); |
| 45 | |
| 46 | let props = max_row_group_size.map(|size| { |
| 47 | WriterProperties::builder() |
| 48 | .set_max_row_group_row_count(Some(size)) |
| 49 | .build() |
| 50 | }); |
| 51 | let file = File::create(path).unwrap(); |
| 52 | let mut writer = ArrowWriter::try_new(file, schema, props).unwrap(); |
| 53 | writer.write(&batch).unwrap(); |
| 54 | writer.close().unwrap(); |
| 55 | } |
| 56 | |
| 57 | pub(crate) fn local_file_path(path: &Path) -> String { |
| 58 | let normalized = path.to_string_lossy().replace('\\', "/"); |
no test coverage detected