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>
impl<'conn> AsyncArrowInserter<'conn>
Sourcepub fn new(
connection: &'conn AsyncConnection,
table_def: &TableDefinition,
) -> Result<Self>
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::Otherwith message"Table definition must have at least one column"iftable_defhas no columns. - Returns
Error::Otherifconnectionis using gRPC transport (COPY is TCP-only).
Sourcepub fn with_flush_threshold(self, threshold: usize) -> Self
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).
Sourcepub async fn insert_data(&mut self, arrow_ipc_data: &[u8]) -> Result<()>
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
- Returns
Error::Otherif a schema was already sent (callinsert_record_batchesfor subsequent chunks instead). - Returns
Error::Other/Error::Clientif the lazy COPY session cannot be opened. - Returns
Error::Client/Error::Ioif the server rejects the data or the socket write fails.
Sourcepub async fn insert_record_batches(
&mut self,
arrow_batch_data: &[u8],
) -> Result<()>
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
- Returns
Error::Otherif no schema has been sent yet (callinsert_datafirst). - Returns
Error::Client/Error::Ioif the server rejects the data or the socket write fails.
Sourcepub async fn insert_raw(&mut self, data: &[u8]) -> Result<()>
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
- Returns
Error::Other/Error::Clientif the lazy COPY session cannot be opened. - Returns
Error::Client/Error::Ioif the server rejects the data or the socket write fails.
Sourcepub async fn execute(self) -> Result<u64>
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).
Sourcepub async fn cancel(self)
pub async fn cancel(self)
Cancels the insert operation.
All data sent so far will be discarded.
Sourcepub fn total_bytes(&self) -> usize
pub fn total_bytes(&self) -> usize
Returns the total bytes sent so far.
Sourcepub fn chunk_count(&self) -> usize
pub fn chunk_count(&self) -> usize
Returns the number of chunks sent so far.
Trait Implementations§
Source§impl<'conn> Debug for AsyncArrowInserter<'conn>
impl<'conn> Debug for AsyncArrowInserter<'conn>
Source§impl Drop for AsyncArrowInserter<'_>
impl Drop for AsyncArrowInserter<'_>
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> 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