Skip to main content

SamplingStrategy

Enum SamplingStrategy 

Source
pub enum SamplingStrategy {
    None,
    Random {
        size: usize,
    },
    Reservoir {
        size: usize,
    },
    Stratified {
        key_columns: Vec<String>,
        samples_per_stratum: usize,
    },
    Progressive {
        initial_size: usize,
        confidence_level: f64,
        max_size: usize,
    },
    Systematic {
        interval: usize,
    },
    Importance {
        weight_column: String,
        weight_threshold: f64,
    },
    MultiStage {
        stages: Vec<SamplingStrategy>,
    },
}
Expand description

How rows are selected for profiling.

Strategies divide into two families, which differ in cost. Streaming strategies decide each row as it arrives and add no memory. Fixed-size strategies — Random and Reservoir — cannot know the final sample until the source ends, so they hold size rows in memory and the profile is computed from that buffer.

Every strategy is applied by RowSampler, which carries the state they need across rows.

Variants§

§

None

No sampling - analyze all data

§

Random

A uniform random sample of exactly size rows (or every row, when the source is shorter).

Over a source of unknown length this is reservoir sampling, so it holds size rows in memory and is equivalent to Reservoir; both names are kept because both are familiar.

Fields

§size: usize
§

Reservoir

A uniform random sample of exactly size rows, selected with Algorithm R over a single pass.

Holds size rows in memory: membership is not final until the source ends, and statistics folded in earlier could not be retracted.

Fields

§size: usize
§

Stratified

Up to samples_per_stratum rows for each distinct combination of key_columns observed in the data.

Strata are discovered as rows arrive, so the sample size grows with the number of distinct keys rather than being fixed up front.

Fields

§key_columns: Vec<String>
§samples_per_stratum: usize
§

Progressive

Grow the sample until the mean of every numeric column is precise enough, bounded by initial_size and max_size.

confidence_level sets a target relative standard error of 1.0 - confidence_level: at 0.95, sampling stops once the standard error of each numeric column’s mean is within 5% of that mean. Precision is measured from the sampled data, so a low-variance column stops early and a volatile one runs to max_size.

A source with no numeric columns has no measurable precision, so it always samples max_size rows.

Fields

§initial_size: usize
§confidence_level: f64
§max_size: usize
§

Systematic

Every interval-th row, starting at the first.

Fields

§interval: usize
§

Importance

Rows whose weight_column holds a number at or above weight_threshold.

The caller states what matters: there is no built-in notion of an important row. Rows where the column is absent or unparseable are excluded. Note that this is a filter, not a probability-weighted sample — the resulting profile describes the rows that met the threshold, not the source as a whole.

Fields

§weight_column: String
§weight_threshold: f64
§

MultiStage

Several strategies applied in order.

Streaming stages act as filters that a row must pass in sequence. At most one fixed-size stage may appear, and it must be last, since it draws its sample from whatever the filters let through.

Fields

Implementations§

Source§

impl SamplingStrategy

Source

pub fn adaptive(total_rows: Option<usize>, file_size_mb: f64) -> Self

Create adaptive strategy based on data characteristics

Source

pub fn stratified(key_columns: Vec<String>, samples_per_stratum: usize) -> Self

Create stratified sampling strategy

Source

pub fn importance( weight_column: impl Into<String>, weight_threshold: f64, ) -> Self

Create an importance filter over a caller-nominated weight column.

Source

pub fn target_sample_size(&self) -> Option<usize>

Source

pub fn description(&self) -> String

Get description of the sampling strategy

Trait Implementations§

Source§

impl Clone for SamplingStrategy

Source§

fn clone(&self) -> SamplingStrategy

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SamplingStrategy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V