Skip to main content

InsertChunk

Struct InsertChunk 

Source
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

Source

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 row
  • column_nullable - Whether each column is nullable
Source

pub fn from_table_definition(table_def: &TableDefinition) -> Self

Creates a chunk from a table definition.

Source

pub fn row_count(&self) -> usize

Returns the number of complete rows in this chunk.

Source

pub fn buffer_size(&self) -> usize

Returns the current buffer size in bytes.

Source

pub fn should_flush(&self) -> bool

Returns true if the chunk has reached size or row limits and should be sent.

Source

pub fn is_empty(&self) -> bool

Returns true if the chunk is empty (no rows).

Source

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).

Source

pub fn clear(&mut self)

Resets the chunk for reuse without reallocating.

Source

pub fn add_null(&mut self) -> Result<()>

Adds a NULL value for the current column.

§Errors
  • Returns Error::Other with message "Too many columns in row" if the current row already has all columns supplied.
  • Returns Error::Other with message "Cannot add NULL to non-nullable column" if the current column is NOT NULL in the schema.
Source

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.

Source

pub fn add_i16(&mut self, value: i16) -> Result<()>

Adds an i16 value (SMALLINT).

§Errors

See add_bool.

Source

pub fn add_i32(&mut self, value: i32) -> Result<()>

Adds an i32 value (INT).

§Errors

See add_bool.

Source

pub fn add_i64(&mut self, value: i64) -> Result<()>

Adds an i64 value (BIGINT).

§Errors

See add_bool.

Source

pub fn add_f32(&mut self, value: f32) -> Result<()>

Adds an f32 value (REAL/FLOAT4).

§Errors

See add_bool.

Source

pub fn add_f64(&mut self, value: f64) -> Result<()>

Adds an f64 value (DOUBLE PRECISION/FLOAT8).

§Errors

See add_bool.

Source

pub fn add_str(&mut self, value: &str) -> Result<()>

Adds a string value (TEXT/VARCHAR).

§Errors

See add_bool.

Source

pub fn add_bytes(&mut self, value: &[u8]) -> Result<()>

Adds a bytes value (BYTEA).

§Errors

See add_bool.

Source

pub fn add_data128(&mut self, value: &[u8; 16]) -> Result<()>

Adds a 128-bit value (NUMERIC/INTERVAL).

§Errors

See add_bool.

Source

pub fn add_date(&mut self, value: Date) -> Result<()>

Adds a Date value.

§Errors

See add_bool.

Source

pub fn add_time(&mut self, value: Time) -> Result<()>

Adds a Time value.

§Errors

See add_bool.

Source

pub fn add_timestamp(&mut self, value: Timestamp) -> Result<()>

Adds a Timestamp value.

§Errors

See add_bool.

Source

pub fn add_offset_timestamp(&mut self, value: OffsetTimestamp) -> Result<()>

Adds an OffsetTimestamp (TIMESTAMP WITH TIME ZONE) value.

§Errors

See add_bool.

Source

pub fn add_interval(&mut self, value: Interval) -> Result<()>

Adds an Interval value.

§Errors

See add_bool.

Source

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.

Source

pub fn column_index(&self) -> usize

Returns the current column index (for checking incomplete rows).

Trait Implementations§

Source§

impl Debug for InsertChunk

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Send for InsertChunk

Source§

impl Sync for InsertChunk

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,