Skip to main content

AsyncArrowInserter

Struct AsyncArrowInserter 

Source
pub struct AsyncArrowInserter<'conn> { /* private fields */ }
Expand description

Async inserter for Arrow IPC stream data into a Hyper table.

This is the async version of ArrowInserter, designed for use in tokio-based async applications.

§Ownership & Drop

You must call either execute() or cancel() to properly terminate the COPY session. If the inserter is dropped without calling one of these, a best-effort CopyFail is queued and the connection will self-heal on the next async operation. Data sent so far will be lost.

§Example

use hyperdb_api::{AsyncArrowInserter, AsyncConnection, CreateMode, TableDefinition, SqlType, Result};

#[tokio::main]
async fn main() -> Result<()> {
    let conn = AsyncConnection::connect("localhost:7483", "test.hyper", CreateMode::CreateIfNotExists).await?;

    let table_def = TableDefinition::new("data")
        .add_required_column("id", SqlType::int())
        .add_nullable_column("value", SqlType::double());

    // Arrow IPC data from external source
    let arrow_data: Vec<u8> = vec![]; // Your Arrow IPC stream here

    let mut inserter = AsyncArrowInserter::new(&conn, &table_def)?;
    inserter.insert_data(&arrow_data).await?;
    let rows = inserter.execute().await?;
    println!("Inserted {} rows", rows);
    Ok(())
}

Implementations§

Source§

impl<'conn> AsyncArrowInserter<'conn>

Source

pub fn new( connection: &'conn AsyncConnection, table_def: &TableDefinition, ) -> Result<Self>

Creates a new async Arrow inserter for the given table.

The underlying COPY session is started lazily on the first data write, so construction is lightweight. However, the connection’s transport is validated eagerly — using a gRPC connection will return an error immediately.

§Arguments
  • connection - The async database connection (must be TCP, not gRPC).
  • table_def - The table definition for the target table.
§Errors
  • Returns Error::Other with message "Table definition must have at least one column" if table_def has no columns.
  • Returns Error::Other if connection is using gRPC transport (COPY is TCP-only).
Source

pub fn with_flush_threshold(self, threshold: usize) -> Self

Sets a custom flush threshold in bytes.

Data is buffered until the threshold is reached, then flushed to the server. Default is 16 MB (matching HyperBinary Inserter).

Source

pub async fn insert_data(&mut self, arrow_ipc_data: &[u8]) -> Result<()>

Inserts a complete Arrow IPC stream (schema + record batches).

Use this method for single-chunk inserts or for the first chunk of multi-chunk inserts. The Arrow IPC stream must include the schema message followed by one or more record batch messages.

§Errors
Source

pub async fn insert_record_batches( &mut self, arrow_batch_data: &[u8], ) -> Result<()>

Inserts Arrow record batch data without schema.

Use this method for subsequent chunks after the first insert_data() call. The data should contain only Arrow record batch messages, not the schema.

§Errors
Source

pub async fn insert_raw(&mut self, data: &[u8]) -> Result<()>

Inserts raw Arrow data without schema tracking.

This is a low-level method that sends data directly without checking whether schema has been sent. Use this only if you are managing schema handling yourself.

§Errors
Source

pub async fn execute(self) -> Result<u64>

Finishes the insert operation and returns the number of rows inserted.

This sends any remaining buffered data to the server and completes the COPY session. Always call this (or cancel()) to properly terminate the session.

§Errors

Returns Error::Client or Error::Io if the CommandComplete round-trip fails (server rejected some buffered batch, or the socket closed mid-flush). If no data was ever written, returns Ok(0).

Source

pub async fn cancel(self)

Cancels the insert operation.

All data sent so far will be discarded.

Source

pub fn has_data(&self) -> bool

Returns whether any data has been sent.

Source

pub fn total_bytes(&self) -> usize

Returns the total bytes sent so far.

Source

pub fn chunk_count(&self) -> usize

Returns the number of chunks sent so far.

Trait Implementations§

Source§

impl<'conn> Debug for AsyncArrowInserter<'conn>

Source§

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

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

impl Drop for AsyncArrowInserter<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'conn> Freeze for AsyncArrowInserter<'conn>

§

impl<'conn> !RefUnwindSafe for AsyncArrowInserter<'conn>

§

impl<'conn> Send for AsyncArrowInserter<'conn>

§

impl<'conn> Sync for AsyncArrowInserter<'conn>

§

impl<'conn> Unpin for AsyncArrowInserter<'conn>

§

impl<'conn> UnsafeUnpin for AsyncArrowInserter<'conn>

§

impl<'conn> !UnwindSafe for AsyncArrowInserter<'conn>

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