pub trait ArrayGenerator: Send + Sync {
// Required methods
fn generate(
&mut self,
length: RowCount,
rng: &mut Xoshiro256PlusPlus,
) -> Result<Arc<dyn Array>, ArrowError>;
fn data_type(&self) -> &DataType;
fn element_size_bytes(&self) -> Option<ByteCount>;
// Provided method
fn metadata(&self) -> Option<HashMap<String, String>> { ... }
}
Expand description
A trait for anything that can generate arrays of data
Required Methods§
Sourcefn generate(
&mut self,
length: RowCount,
rng: &mut Xoshiro256PlusPlus,
) -> Result<Arc<dyn Array>, ArrowError>
fn generate( &mut self, length: RowCount, rng: &mut Xoshiro256PlusPlus, ) -> Result<Arc<dyn Array>, ArrowError>
Generate an array of the given length
§Arguments
length
- The number of elements to generaterng
- The random number generator to use
§Returns
An array of the given length
Note: Not every generator needs an rng. However, it is passed here because many do and this lets us manage RNGs at the batch level instead of the array level.
Sourcefn data_type(&self) -> &DataType
fn data_type(&self) -> &DataType
Get the data type of the array that this generator produces
§Returns
The data type of the array that this generator produces
Sourcefn element_size_bytes(&self) -> Option<ByteCount>
fn element_size_bytes(&self) -> Option<ByteCount>
Get the size of each element in bytes
§Returns
The size of each element in bytes. Will be None if the size varies by element.
Provided Methods§
Trait Implementations§
Source§impl ArrayGeneratorExt for Box<dyn ArrayGenerator>
impl ArrayGeneratorExt for Box<dyn ArrayGenerator>
Source§fn with_random_nulls(self, null_probability: f64) -> Box<dyn ArrayGenerator>
fn with_random_nulls(self, null_probability: f64) -> Box<dyn ArrayGenerator>
Replaces the validity bitmap of generated arrays, inserting nulls with a given probability
Source§fn with_nulls(self, nulls: &[bool]) -> Box<dyn ArrayGenerator>
fn with_nulls(self, nulls: &[bool]) -> Box<dyn ArrayGenerator>
Replaces the validity bitmap of generated arrays with the inverse of
nulls
, cycling if neededSource§fn with_validity(self, validity: &[bool]) -> Box<dyn ArrayGenerator>
fn with_validity(self, validity: &[bool]) -> Box<dyn ArrayGenerator>
Replaces the validity bitmap of generated arrays with
validity
, cycling if needed