Creates a new csv file at the specified location
(
path: PathBuf,
batches: impl IntoIterator<Item = RecordBatch>,
)
| 35 | impl TestCsvFile { |
| 36 | /// Creates a new csv file at the specified location |
| 37 | pub fn try_new( |
| 38 | path: PathBuf, |
| 39 | batches: impl IntoIterator<Item = RecordBatch>, |
| 40 | ) -> Result<Self> { |
| 41 | let file = File::create(&path).unwrap(); |
| 42 | let builder = WriterBuilder::new().with_header(true); |
| 43 | let mut writer = builder.build(file); |
| 44 | |
| 45 | let mut batches = batches.into_iter(); |
| 46 | let first_batch = batches.next().expect("need at least one record batch"); |
| 47 | let schema = first_batch.schema(); |
| 48 | |
| 49 | let mut num_rows = 0; |
| 50 | for batch in batches { |
| 51 | writer.write(&batch)?; |
| 52 | num_rows += batch.num_rows(); |
| 53 | } |
| 54 | |
| 55 | println!("Generated test dataset with {num_rows} rows"); |
| 56 | |
| 57 | Ok(Self { path, schema }) |
| 58 | } |
| 59 | |
| 60 | /// The schema of this csv file |
| 61 | pub fn schema(&self) -> SchemaRef { |