pub struct ArrowOptions<'conn> { /* private fields */ }Expand description
The Arrow production settings of a connection or a result.
DuckDB needs these to decide how to render its types as Arrow — the
timezone to stamp on TIMESTAMPTZ, whether to emit large or regular string
offsets, which extension types are registered. Both
to_arrow_schema and data_chunk_to_arrow require one.
Destroyed on drop (duckdb_destroy_arrow_options).
§Lifetime
The handle is a copy of the connection’s ClientProperties, and that
struct keeps a raw pointer to the connection’s ClientContext, which
the conversion functions dereference (DBConfig::GetConfig(context)). Once
the connection closes, every use is a heap use-after-free. So the options
borrow the connection for 'conn:
use quack_rs::arrow::{data_chunk_to_arrow, ArrowOptions};
use quack_rs::query::OwnedConnection;
fn demo(con: OwnedConnection, chunk: &quack_rs::data_chunk::DataChunk) {
let options = ArrowOptions::from_connection(&con).unwrap();
drop(con); // error[E0505]: cannot move out of `con` because it is borrowed
let _ = data_chunk_to_arrow(&options, chunk);
}Options read from a QueryResult point at the connection that ran the
query, which a QueryResult does not borrow, so
from_result is unsafe.
Implementations§
Source§impl<'conn> ArrowOptions<'conn>
impl<'conn> ArrowOptions<'conn>
Sourcepub fn from_connection(
connection: &'conn OwnedConnection,
) -> Result<Self, ExtensionError>
pub fn from_connection( connection: &'conn OwnedConnection, ) -> Result<Self, ExtensionError>
Reads the Arrow options of a connection, borrowing it for as long as the options live.
§Errors
duckdb_connection_get_arrow_options has no error channel: it writes
null when the allocation throws. That is reported here as an
ExtensionError.
Sourcepub unsafe fn from_raw_connection(
connection: duckdb_connection,
) -> Result<Self, ExtensionError>
pub unsafe fn from_raw_connection( connection: duckdb_connection, ) -> Result<Self, ExtensionError>
Reads the Arrow options of a raw connection — for extension code that
holds a duckdb_connection rather than an OwnedConnection.
§Errors
Returns an ExtensionError when the connection is null or DuckDB
cannot allocate the options (it writes null in both cases).
§Safety
connection must be a live duckdb_connection, and it must not be
disconnected for all of 'conn (the caller picks 'conn; choose one no
longer than the connection stays open). See the type-level
lifetime docs.
Sourcepub unsafe fn from_result(result: &QueryResult) -> Result<Self, ExtensionError>
pub unsafe fn from_result(result: &QueryResult) -> Result<Self, ExtensionError>
Reads the Arrow options a result was produced with.
Prefer this over from_connection when
exporting that result’s chunks: a result carries the client properties
captured when it ran, which is what its chunks were built against.
§Errors
Returns an ExtensionError when DuckDB returns null, which it does
for a result with no internal data.
§Safety
The connection that ran the query producing result must stay open for
all of 'conn. The captured client properties point at that
connection’s ClientContext, and a QueryResult can outlive its
connection, so nothing checks this. See the type-level
lifetime docs.