ArrayGenerator

Trait ArrayGenerator 

Source
pub trait ArrayGenerator:
    Send
    + Sync
    + Debug {
    // 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 methods
    fn generate_default(
        &mut self,
        length: RowCount,
    ) -> Result<Arc<dyn Array>, ArrowError> { ... }
    fn metadata(&self) -> Option<HashMap<String, String>> { ... }
}
Expand description

A trait for anything that can generate arrays of data

Required Methods§

Source

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 generate
  • rng - 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.

Source

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

Source

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§

Source

fn generate_default( &mut self, length: RowCount, ) -> Result<Arc<dyn Array>, ArrowError>

Generate an array of the given length using a new RNG with the default seed

§Arguments
  • length - The number of elements to generate
§Returns

An array of the given length

Source

fn metadata(&self) -> Option<HashMap<String, String>>

Gets metadata that should be associated with the field generated by this generator

Trait Implementations§

Source§

impl ArrayGeneratorExt for Box<dyn ArrayGenerator>

Source§

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>

Replaces the validity bitmap of generated arrays with the inverse of nulls, cycling if needed
Source§

fn with_nans(self, nans: &[bool]) -> Box<dyn ArrayGenerator>

Replaces the values of generated arrays with NaN values, cycling if needed Read more
Source§

fn with_validity(self, validity: &[bool]) -> Box<dyn ArrayGenerator>

Replaces the validity bitmap of generated arrays with validity, cycling if needed
Source§

fn with_metadata( self, metadata: HashMap<String, String>, ) -> Box<dyn ArrayGenerator>

Implementors§