Skip to main content

ArrowOptions

Struct ArrowOptions 

Source
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>

Source

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.

Source

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.

Source

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.

Source

pub const unsafe fn from_raw(raw: duckdb_arrow_options) -> Self

Takes ownership of a raw duckdb_arrow_options.

§Safety

raw must be a non-null handle the caller is responsible for destroying, and nobody else may destroy it. The connection it was read from must stay open for all of 'conn.

Source

pub const fn as_raw(&self) -> duckdb_arrow_options

The raw handle, still owned by this value.

Source

pub const fn into_raw(self) -> duckdb_arrow_options

Relinquishes ownership, returning the raw handle.

The caller becomes responsible for duckdb_destroy_arrow_options, and for not using the handle after the connection closes.

Trait Implementations§

Source§

impl Debug for ArrowOptions<'_>

Source§

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

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

impl Drop for ArrowOptions<'_>

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> !Send for ArrowOptions<'conn>

§

impl<'conn> !Sync for ArrowOptions<'conn>

§

impl<'conn> Freeze for ArrowOptions<'conn>

§

impl<'conn> RefUnwindSafe for ArrowOptions<'conn>

§

impl<'conn> Unpin for ArrowOptions<'conn>

§

impl<'conn> UnsafeUnpin for ArrowOptions<'conn>

§

impl<'conn> UnwindSafe for ArrowOptions<'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, 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, 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.