gnitz-zset 0.1.1

The Z-set kernel of the gnitz database: schema, columnar batches, cursors and operators
//! The reduce output row emitter.

use super::agg::Accumulator;
use crate::repr::{Batch, MemBatch};
use crate::schema::ColumnLocator;

/// Emit one `[key…, group columns…, aggregates…]` row at weight +1, copying the
/// group columns from `group`'s row at its locators; the ground row has none.
pub(crate) fn emit_reduce_row(
    output: &mut Batch,
    group: Option<(&MemBatch, usize, &[ColumnLocator])>,
    out_pk_bytes: &[u8],
    accs: &[Accumulator],
) {
    output.begin_row(out_pk_bytes, 1);
    if let Some((src, row, locs)) = group {
        output.append_cells_from(0, locs, src, row);
    }
    for acc in accs {
        acc.emit(output);
    }
    output.commit_row();
}