pub struct InsertChunk { /* private fields */ }Expand description
A thread-safe chunk for encoding rows in parallel.
InsertChunk can be created and populated in any thread, then sent to a
ChunkSender for transmission. This enables parallel data encoding across
multiple worker threads while serializing the actual network sends.
§Example
use hyperdb_api::{InsertChunk, TableDefinition, SqlType, Result};
fn encode_chunk(table_def: &TableDefinition, start_id: i32) -> Result<InsertChunk> {
let mut chunk = InsertChunk::from_table_definition(table_def);
for i in 0..1000 {
chunk.add_i32(start_id + i)?;
chunk.add_str(&format!("Item {}", start_id + i))?;
chunk.end_row()?;
}
Ok(chunk)
}Implementations§
Source§impl InsertChunk
impl InsertChunk
Sourcepub fn new(column_count: usize, column_nullable: Vec<bool>) -> Self
pub fn new(column_count: usize, column_nullable: Vec<bool>) -> Self
Creates a new empty chunk with the given schema.
§Arguments
column_count- Number of columns per rowcolumn_nullable- Whether each column is nullable
Sourcepub fn from_table_definition(table_def: &TableDefinition) -> Self
pub fn from_table_definition(table_def: &TableDefinition) -> Self
Creates a chunk from a table definition.
Sourcepub fn buffer_size(&self) -> usize
pub fn buffer_size(&self) -> usize
Returns the current buffer size in bytes.
Sourcepub fn should_flush(&self) -> bool
pub fn should_flush(&self) -> bool
Returns true if the chunk has reached size or row limits and should be sent.
Sourcepub fn take(&mut self) -> Option<BytesMut>
pub fn take(&mut self) -> Option<BytesMut>
Takes the buffer, consuming the chunk data.
Returns None if the chunk is empty. After calling this, the chunk
can be reused by calling the add_* methods again.
Note: The header flag is NOT reset - subsequent chunks from the same
InsertChunk will NOT include the header (HyperBinary only needs one
header per COPY stream).
Sourcepub fn add_null(&mut self) -> Result<()>
pub fn add_null(&mut self) -> Result<()>
Adds a NULL value for the current column.
§Errors
- Returns
Error::Otherwith message"Too many columns in row"if the current row already has all columns supplied. - Returns
Error::Otherwith message"Cannot add NULL to non-nullable column"if the current column isNOT NULLin the schema.
Sourcepub fn add_bool(&mut self, value: bool) -> Result<()>
pub fn add_bool(&mut self, value: bool) -> Result<()>
Adds a boolean value.
§Errors
Returns Error::Other with message "Too many columns in row" if
the current row already has all columns supplied.
Sourcepub fn add_timestamp(&mut self, value: Timestamp) -> Result<()>
pub fn add_timestamp(&mut self, value: Timestamp) -> Result<()>
Sourcepub fn add_offset_timestamp(&mut self, value: OffsetTimestamp) -> Result<()>
pub fn add_offset_timestamp(&mut self, value: OffsetTimestamp) -> Result<()>
Sourcepub fn add_interval(&mut self, value: Interval) -> Result<()>
pub fn add_interval(&mut self, value: Interval) -> Result<()>
Sourcepub fn end_row(&mut self) -> Result<()>
pub fn end_row(&mut self) -> Result<()>
Ends the current row.
Returns an error if the wrong number of columns were added.
§Errors
Returns Error::Other if fewer (or more) columns were supplied
for this row than the chunk’s column count.
Sourcepub fn column_index(&self) -> usize
pub fn column_index(&self) -> usize
Returns the current column index (for checking incomplete rows).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for InsertChunk
impl RefUnwindSafe for InsertChunk
impl Unpin for InsertChunk
impl UnsafeUnpin for InsertChunk
impl UnwindSafe for InsertChunk
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request