Create a random [RecordBatch] from a schema
(
schema: SchemaRef,
size: usize,
null_density: f32,
true_density: f32,
)
| 35 | |
| 36 | /// Create a random [RecordBatch] from a schema |
| 37 | pub fn create_random_batch( |
| 38 | schema: SchemaRef, |
| 39 | size: usize, |
| 40 | null_density: f32, |
| 41 | true_density: f32, |
| 42 | ) -> Result<RecordBatch> { |
| 43 | let columns = schema |
| 44 | .fields() |
| 45 | .iter() |
| 46 | .map(|field| create_random_array(field, size, null_density, true_density)) |
| 47 | .collect::<Result<Vec<ArrayRef>>>()?; |
| 48 | |
| 49 | RecordBatch::try_new_with_options( |
| 50 | schema, |
| 51 | columns, |
| 52 | &RecordBatchOptions::new().with_match_field_names(false), |
| 53 | ) |
| 54 | } |
| 55 | |
| 56 | /// Create a random [ArrayRef] from a [DataType] with a length, |
| 57 | /// null density and true density (for [BooleanArray]). |