Build a sparse index from raw column data at flush time. Scans the column data in blocks of `block_size` rows, computing per-block timestamp ranges and per-column min/max statistics.
(
columns: &[ColumnData],
schema: &ColumnarSchema,
row_count: u64,
block_size: usize,
)
| 31 | /// Scans the column data in blocks of `block_size` rows, computing |
| 32 | /// per-block timestamp ranges and per-column min/max statistics. |
| 33 | pub fn build( |
| 34 | columns: &[ColumnData], |
| 35 | schema: &ColumnarSchema, |
| 36 | row_count: u64, |
| 37 | block_size: usize, |
| 38 | ) -> Self { |
| 39 | let block_size = block_size.max(64); // minimum 64 rows per block |
| 40 | let total_rows = row_count as usize; |
| 41 | let block_count = if total_rows == 0 { |
| 42 | 0 |
| 43 | } else { |
| 44 | total_rows.div_ceil(block_size) |
| 45 | }; |
| 46 | |
| 47 | let column_names: Vec<String> = schema.columns.iter().map(|(n, _)| n.clone()).collect(); |
| 48 | let ts_idx = schema.timestamp_idx; |
| 49 | |
| 50 | let mut blocks = Vec::with_capacity(block_count); |
| 51 | |
| 52 | for block_idx in 0..block_count { |
| 53 | let row_start = block_idx * block_size; |
| 54 | let row_end = (row_start + block_size).min(total_rows); |
| 55 | let count = row_end - row_start; |
| 56 | |
| 57 | let (min_ts, max_ts) = if ts_idx < columns.len() { |
| 58 | compute_ts_range(&columns[ts_idx], row_start, row_end) |
| 59 | } else { |
| 60 | (i64::MIN, i64::MAX) |
| 61 | }; |
| 62 | |
| 63 | let column_stats: Vec<BlockColumnStats> = columns |
| 64 | .iter() |
| 65 | .zip(schema.columns.iter()) |
| 66 | .map(|(col, (_, col_type))| compute_block_stats(col, *col_type, row_start, row_end)) |
| 67 | .collect(); |
| 68 | |
| 69 | blocks.push(BlockEntry { |
| 70 | row_offset: row_start as u32, |
| 71 | row_count: count as u32, |
| 72 | min_ts, |
| 73 | max_ts, |
| 74 | column_stats, |
| 75 | }); |
| 76 | } |
| 77 | |
| 78 | Self { |
| 79 | block_size: block_size as u32, |
| 80 | column_names, |
| 81 | blocks, |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | // -- Query methods -- |
| 86 |
nothing calls this directly
no test coverage detected