Generate CSV partitions within the supplied directory
(
tmp_dir: &TempDir,
partition_count: usize,
file_extension: &str,
)
| 149 | |
| 150 | /// Generate CSV partitions within the supplied directory |
| 151 | pub fn populate_csv_partitions( |
| 152 | tmp_dir: &TempDir, |
| 153 | partition_count: usize, |
| 154 | file_extension: &str, |
| 155 | ) -> Result<SchemaRef> { |
| 156 | // define schema for data source (csv file) |
| 157 | let schema = Arc::new(Schema::new(vec![ |
| 158 | Field::new("c1", DataType::UInt32, false), |
| 159 | Field::new("c2", DataType::UInt64, false), |
| 160 | Field::new("c3", DataType::Boolean, false), |
| 161 | ])); |
| 162 | |
| 163 | // generate a partitioned file |
| 164 | for partition in 0..partition_count { |
| 165 | let filename = format!("partition-{partition}.{file_extension}"); |
| 166 | let file_path = tmp_dir.path().join(filename); |
| 167 | let mut file = File::create(file_path)?; |
| 168 | |
| 169 | // generate some data |
| 170 | for i in 0..=10 { |
| 171 | let data = format!("{},{},{}\n", partition, i, i % 2 == 0); |
| 172 | file.write_all(data.as_bytes())?; |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | Ok(schema) |
| 177 | } |
| 178 | |
| 179 | /// TableFactory for tests |
| 180 | #[derive(Default, Debug)] |