MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / encode_column_blocks

Function encode_column_blocks

nodedb-columnar/src/writer/block.rs:22–65  ·  view source on GitHub ↗

Encode all blocks for a single column, appending to `buf`. Returns per-block statistics.

(
    buf: &mut Vec<u8>,
    col_data: &ColumnData,
    col_type: &ColumnType,
    codec: ResolvedColumnCodec,
    row_count: usize,
    governor: Option<&Arc<MemoryGovernor>>,
)

Source from the content-addressed store, hash-verified

20/// Encode all blocks for a single column, appending to `buf`.
21/// Returns per-block statistics.
22pub(super) fn encode_column_blocks(
23 buf: &mut Vec<u8>,
24 col_data: &ColumnData,
25 col_type: &ColumnType,
26 codec: ResolvedColumnCodec,
27 row_count: usize,
28 governor: Option<&Arc<MemoryGovernor>>,
29) -> Result<Vec<BlockStats>, ColumnarError> {
30 let num_blocks = row_count.div_ceil(BLOCK_SIZE);
31 let _stats_guard = governor
32 .map(|g| {
33 g.reserve(
34 EngineId::Columnar,
35 num_blocks * std::mem::size_of::<BlockStats>(),
36 )
37 })
38 .transpose()?;
39 let mut block_stats = Vec::with_capacity(num_blocks);
40
41 for block_idx in 0..num_blocks {
42 let start = block_idx * BLOCK_SIZE;
43 let end = (start + BLOCK_SIZE).min(row_count);
44 let block_row_count = end - start;
45
46 let (compressed, stats) = encode_single_block(
47 col_data,
48 col_type,
49 codec,
50 start,
51 end,
52 block_row_count,
53 governor,
54 )?;
55
56 // Write block: [compressed_len: u32 LE][compressed_data].
57 let len = compressed.len() as u32;
58 buf.extend_from_slice(&len.to_le_bytes());
59 buf.extend_from_slice(&compressed);
60
61 block_stats.push(stats);
62 }
63
64 Ok(block_stats)
65}
66
67/// Encode a single block of rows for a column.
68fn encode_single_block(

Callers 1

write_segmentMethod · 0.85

Calls 4

encode_single_blockFunction · 0.85
reserveMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected