sample_arrow2/
struct_.rs

1//! Samplers for generating an arrow [`StructArray`].
2
3use crate::{array::ArraySampler, generate_validity};
4use arrow2::{
5    array::{Array, StructArray},
6    datatypes::DataType,
7};
8use sample_std::{Random, Sample};
9
10pub struct StructSampler<V> {
11    pub data_type: DataType,
12    pub null: Option<V>,
13    pub values: Vec<ArraySampler>,
14}
15
16impl<V> Sample for StructSampler<V>
17where
18    V: Sample<Output = bool>,
19{
20    type Output = Box<dyn Array>;
21
22    fn generate(&mut self, g: &mut Random) -> Self::Output {
23        let values: Vec<_> = self.values.iter_mut().map(|sa| sa.generate(g)).collect();
24        let validity = generate_validity(&mut self.null, g, values[0].len());
25
26        StructArray::new(self.data_type.clone(), values, validity).boxed()
27    }
28}