pub struct KWayMerger { /* private fields */ }Expand description
K-way merger for combining multiple SSTables
Uses a min-heap to efficiently merge k sorted SSTable runs into a single output. Each run maintains a small peek buffer for efficient lookahead.
§Usage
// Create merger from input SSTable paths
let merger = KWayMerger::new(input_paths, &schema)?;
// Option 1: Full merge to output writer
let stats = merger.merge(&mut output_writer)?;
// Option 2: Incremental merge (step-by-step)
loop {
match merger.step()? {
MergeStep::Partition { key, rows } => {
// Process partition
}
MergeStep::Complete => break,
}
}Implementations§
Source§impl KWayMerger
impl KWayMerger
Sourcepub fn new(input_paths: Vec<PathBuf>, schema: &TableSchema) -> Result<Self>
pub fn new(input_paths: Vec<PathBuf>, schema: &TableSchema) -> Result<Self>
Create a new k-way merger from input SSTable paths
§Arguments
input_paths- Paths to input SSTable Data.db files (ordered newest to oldest)schema- Table schema for schema-aware merging
§Returns
A new KWayMerger ready to merge the input SSTables.
§Errors
Returns an error if any input SSTable cannot be opened.
§Example
let input_paths = vec![
PathBuf::from("data/nb-1-big-Data.db"),
PathBuf::from("data/nb-2-big-Data.db"),
];
let merger = KWayMerger::new(input_paths, &schema)?;Sourcepub fn merge(self, output_writer: &mut SSTableWriter) -> Result<MergeStats>
pub fn merge(self, output_writer: &mut SSTableWriter) -> Result<MergeStats>
Perform a full merge to the output writer
This is a convenience method that repeatedly calls step() until
the merge is complete, writing each partition to the output writer.
§Arguments
output_writer- SSTableWriter to write merged output
§Returns
Statistics about the merge operation.
§Errors
Returns an error if reading or writing fails.
Sourcepub fn step(&mut self) -> Result<MergeStep>
pub fn step(&mut self) -> Result<MergeStep>
Perform one merge step (one partition)
Returns the next merged partition, or Complete if the merge is done. This allows incremental merging for better memory control.
§Returns
MergeStep::Partition- Next merged partition with all its rowsMergeStep::Complete- Merge is complete
§Errors
Returns an error if reading fails.