Generate CSV partitions within the supplied directory
(
tmp_dir: &TempDir,
partition_count: usize,
file_extension: &str,
)
| 176 | |
| 177 | /// Generate CSV partitions within the supplied directory |
| 178 | fn populate_csv_partitions( |
| 179 | tmp_dir: &TempDir, |
| 180 | partition_count: usize, |
| 181 | file_extension: &str, |
| 182 | ) -> Result<SchemaRef> { |
| 183 | // define schema for data source (csv file) |
| 184 | let schema = Arc::new(Schema::new(vec![ |
| 185 | Field::new("c1", DataType::UInt32, false), |
| 186 | Field::new("c2", DataType::UInt64, false), |
| 187 | Field::new("c3", DataType::Boolean, false), |
| 188 | ])); |
| 189 | |
| 190 | // generate a partitioned file |
| 191 | for partition in 0..partition_count { |
| 192 | let filename = format!("partition-{partition}.{file_extension}"); |
| 193 | let file_path = tmp_dir.path().join(filename); |
| 194 | let mut file = File::create(file_path)?; |
| 195 | |
| 196 | // generate some data |
| 197 | for i in 0..=10 { |
| 198 | let data = format!("{},{},{}\n", partition, i, i % 2 == 0); |
| 199 | file.write_all(data.as_bytes())?; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | Ok(schema) |
| 204 | } |
| 205 | |
| 206 | /// Specialized String representation |
| 207 | fn col_str(column: &ArrayRef, row_index: usize) -> String { |