Skip to main content
pub struct BatchingSqlClient  /* private fields */ 

A SQL client that automatically batches INSERT statements for high-performance bulk loading.

When you execute INSERT statements in a loop, this client accumulates them and automatically flushes through BulkInserter<GenericRecord> when the batch size is reached. This provides massive performance improvements over executing individual INSERT statements.

Example

Implementations

Source

pub fn new( kinetica: Arc<Kinetica>, batch_size: usize, num_workers: usize, ) -> Self

Create a new batching SQL client.

  • kinetica - The Kinetica client
  • batch_size - Number of records to accumulate before flushing (recommended: 10000-50000)
  • num_workers - Number of parallel workers for BulkInserter (recommended: 4-16)
Source

pub fn with_options( kinetica: Arc<Kinetica>, batch_size: usize, num_workers: usize, options: BulkInserterOptions, ) -> Self

Create a batching client with custom options (e.g., upsert mode).

Source

pub fn with_hints( kinetica: Arc<Kinetica>, batch_size: usize, num_workers: usize, hints: SqlHints, ) -> Self

Create a batching client with SQL hints.

Source

pub fn with_options_and_hints( kinetica: Arc<Kinetica>, batch_size: usize, num_workers: usize, options: BulkInserterOptions, hints: SqlHints, ) -> Self

Create a batching client with both BulkInserter options and SQL hints.

Source

pub fn set_hints(&mut self, hints: SqlHints)

Set SQL hints for non-INSERT statements.

Note: For INSERT statements, hints like update_on_existing_pk are automatically applied through the BulkInserter options. Use with_hints() constructor to set both at creation time.

Source

pub fn hints(&self) -> &SqlHints

Get the current SQL hints.

Source

pub async fn execute(&mut self, sql: &str) -> SqlOpResult<Option<SqlResult>>

Execute a SQL statement.

  • INSERT statements are accumulated and batched automatically
  • Other statements (SELECT, CREATE, etc.) are executed immediately with hints applied

When the batch size is reached, records are automatically flushed through BulkInserter<GenericRecord> with shard-aware routing.

For non-INSERT statements, any configured SQL hints (via set_hints() or with_hints()) will be applied to the execute_sql request.

Source

pub async fn flush(&mut self) -> SqlOpResult<()>

Flush all pending records for all tables.

Flush all pending records and return final statistics.

This should be called when you’re done inserting to ensure all records are flushed.

Source

pub fn stats(&self) -> BatchingStats

Get current statistics without closing.

Source

pub fn pending_count(&self) -> usize

Get the number of pending (unflushed) records across all tables.

Source

pub fn kinetica(&self) -> &Arc<Kinetica>

Get a reference to the underlying Kinetica client.