Synthesize one batch of length `n` covering rows `[start, start+n)`.
(start: usize, n: usize, schema: &SchemaRef)
| 143 | |
| 144 | /// Synthesize one batch of length `n` covering rows `[start, start+n)`. |
| 145 | fn synthesize_batch(start: usize, n: usize, schema: &SchemaRef) -> Result<RecordBatch> { |
| 146 | let id = Int64Array::from_iter_values((start..start + n).map(|i| i as i64)); |
| 147 | let value = Float64Array::from_iter_values( |
| 148 | (start..start + n).map(|i| 900.0 + ((i as f64 * 13.7) % 99100.0)), |
| 149 | ); |
| 150 | let count = |
| 151 | Int64Array::from_iter_values((start..start + n).map(|i| (i % 1000) as i64)); |
| 152 | // Date32 spread across ~6 years (epoch days; 8035 ≈ 1992-01-01). |
| 153 | let ts = Date32Array::from_iter_values( |
| 154 | (start..start + n).map(|i| 8035 + ((i % 2200) as i32)), |
| 155 | ); |
| 156 | let category = StringArray::from_iter_values( |
| 157 | (start..start + n).map(|i| CATEGORIES[i % CATEGORIES.len()]), |
| 158 | ); |
| 159 | let flag = |
| 160 | StringArray::from_iter_values((start..start + n).map(|i| FLAGS[i % FLAGS.len()])); |
| 161 | let status = StringArray::from_iter_values( |
| 162 | (start..start + n).map(|i| STATUSES[i % STATUSES.len()]), |
| 163 | ); |
| 164 | let text = StringArray::from_iter_values( |
| 165 | (start..start + n).map(|i| format!("synthetic event row {i:010} payload text")), |
| 166 | ); |
| 167 | |
| 168 | let cols: Vec<ArrayRef> = vec![ |
| 169 | Arc::new(id), |
| 170 | Arc::new(value), |
| 171 | Arc::new(count), |
| 172 | Arc::new(ts), |
| 173 | Arc::new(category), |
| 174 | Arc::new(flag), |
| 175 | Arc::new(status), |
| 176 | Arc::new(text), |
| 177 | ]; |
| 178 | |
| 179 | RecordBatch::try_new(Arc::clone(schema), cols) |
| 180 | .map_err(|e| exec_datafusion_err!("building synthetic batch: {e}")) |
| 181 | } |
| 182 | |
| 183 | /// Builds the wide schema by laying out the suffix-renamed zero-padded |
| 184 | /// copies first and the unsuffixed base columns last. Putting the base |