Skip to main content

RowEncoder

Trait RowEncoder 

Source
pub trait RowEncoder<F>: Send
where F: RecFamily,
{ // Required method fn encode<'buf>( &mut self, rec: &Record<<F as RecFamily>::Rec<'buf>>, buf: &mut BytesMut, ) -> Result<(), SinkError>; // Provided methods fn buffered_bytes(&self) -> usize { ... } fn finish_chunk(&mut self, buf: &mut BytesMut) -> Result<(), SinkError> { ... } }
Expand description

The CPU half of a sink connector: encodes one record into the sink’s wire format. Runs on pinned pipeline threads inside the chain’s terminal stage; must not perform I/O. Family-generic and dyn-compatible, like Deserializer.

Required Methods§

Source

fn encode<'buf>( &mut self, rec: &Record<<F as RecFamily>::Rec<'buf>>, buf: &mut BytesMut, ) -> Result<(), SinkError>

Append rec’s encoding to buf. Errors are record-level and subject to the sink stage’s ErrorPolicy — except errors of ErrorClass::Fatal, which stop the pipeline regardless of policy (fatal means the encoder itself is broken, e.g. the row type cannot match the target schema; every subsequent record would fail identically).

Provided Methods§

Source

fn buffered_bytes(&self) -> usize

Bytes the encoder is holding internally that have not yet been flushed to a frame. Row formats append directly in encode and buffer nothing, so the default is 0. Columnar formats (which must transpose a whole block before any bytes exist) return the approximate size of the block under assembly; the terminal stage adds this to the shard buffer length when deciding whether to seal a chunk, so a columnar block still respects ChunkConfig::target_bytes.

Source

fn finish_chunk(&mut self, buf: &mut BytesMut) -> Result<(), SinkError>

Finalize the pending chunk: flush any internally-buffered rows into buf as exactly one complete, self-describing wire frame, leaving the encoder empty and ready for the next chunk. Row formats already wrote every row in encode, so the default is a no-op. The terminal stage calls this immediately before it seals each EncodedChunk — in steady state, on data lulls, and at drain — so a columnar encoder’s buffered rows are never silently dropped.

An Err is fatal (a broken encoder, not a bad record): the stage ships no partial frame and the buffered rows’ acknowledgements fail on teardown, so the data replays. Because a Native block concatenates with the blocks around it, each finish_chunk frame is independently valid — workers still accumulate frames without re-encoding.

Implementations on Foreign Types§

§

impl RowEncoder<Owned<Vec<u8>>> for PreEncodedRows

§

fn encode<'buf>( &mut self, rec: &Record<Vec<u8>>, buf: &mut BytesMut, ) -> Result<(), SinkError>

§

impl<F> RowEncoder<F> for ClickHouseEncoder<F>
where F: RecFamily, <F as RecFamily>::Rec<'b>: for<'b> Serialize,

§

fn encode<'buf>( &mut self, rec: &Record<<F as RecFamily>::Rec<'buf>>, buf: &mut BytesMut, ) -> Result<(), SinkError>

§

impl<F> RowEncoder<F> for NativeEncoder<F>
where F: RecFamily, <F as RecFamily>::Rec<'b>: for<'b> Serialize,

§

fn encode<'buf>( &mut self, rec: &Record<<F as RecFamily>::Rec<'buf>>, _buf: &mut BytesMut, ) -> Result<(), SinkError>

§

fn buffered_bytes(&self) -> usize

§

fn finish_chunk(&mut self, buf: &mut BytesMut) -> Result<(), SinkError>

Implementors§