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.
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.
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.
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.
Systematic
Every interval-th row, starting at the first.
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.
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
stages: Vec<SamplingStrategy>Implementations§
Source§impl SamplingStrategy
impl SamplingStrategy
Sourcepub fn adaptive(total_rows: Option<usize>, file_size_mb: f64) -> Self
pub fn adaptive(total_rows: Option<usize>, file_size_mb: f64) -> Self
Create adaptive strategy based on data characteristics
Sourcepub fn stratified(key_columns: Vec<String>, samples_per_stratum: usize) -> Self
pub fn stratified(key_columns: Vec<String>, samples_per_stratum: usize) -> Self
Create stratified sampling strategy
Sourcepub fn importance(
weight_column: impl Into<String>,
weight_threshold: f64,
) -> Self
pub fn importance( weight_column: impl Into<String>, weight_threshold: f64, ) -> Self
Create an importance filter over a caller-nominated weight column.
pub fn target_sample_size(&self) -> Option<usize>
Sourcepub fn description(&self) -> String
pub fn description(&self) -> String
Get description of the sampling strategy
Trait Implementations§
Source§impl Clone for SamplingStrategy
impl Clone for SamplingStrategy
Source§fn clone(&self) -> SamplingStrategy
fn clone(&self) -> SamplingStrategy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more