use matten_data::CsvBatchReader;
fn main() -> Result<(), matten_data::MattenDataError> {
let path = std::env::temp_dir().join(format!(
"matten_data_csv_batches_example_{}.csv",
std::process::id()
));
std::fs::write(&path, "sales,cost\n100,40\n150,45\n120,55\n90,30\n200,60").unwrap();
let mut reader = CsvBatchReader::open(&path, 2)?;
let mut total_rows = 0;
while let Some(batch) = reader.next_batch()? {
println!(
"batch: {} rows, columns {:?}",
batch.row_count(),
batch.column_names()
);
total_rows += batch.row_count();
}
assert!(reader.next_batch()?.is_none());
println!("total rows read across all batches: {total_rows}");
assert_eq!(total_rows, 5);
std::fs::remove_file(&path).ok();
println!("csv_batches: OK");
Ok(())
}