Skip to main content

TypedTableFunctionBuilder

Struct TypedTableFunctionBuilder 

Source
pub struct TypedTableFunctionBuilder<S: Send + 'static> { /* private fields */ }
Expand description

Closure-based builder for table functions with a typed, mutable scan state.

Obtain one via TableFunctionBuilder::with_state or TableFunctionBuilder::with_bind_init. Set a scan closure with scan and finish with build to recover a fully-configured TableFunctionBuilder that can be passed to any Registrar.

§Example

See the module-level docs for a complete example.

Implementations§

Source§

impl<S: Send + 'static> TypedTableFunctionBuilder<S>

Source

pub fn scan<F>(self, f: F) -> Self
where F: Fn(&mut S, &DataChunk) -> Result<(), ExtensionError> + Send + Sync + 'static,

Sets the scan closure.

The closure receives a mutable reference to the scan state for the current execution, plus a DataChunk for the output chunk. It must fill the chunk with zero or more output rows and set the chunk size via DataChunk::set_size or a ChunkWriter. Returning with chunk size zero signals end-of-stream to DuckDB.

Column i of the chunk is the i-th column declared in bind: the typed builder never enables projection pushdown (and build refuses a raw builder that had it enabled).

Errors are reported through duckdb_function_set_error and terminate the scan.

Source

pub fn name(&self) -> &str

Returns the underlying function name.

Source

pub fn param(self, type_id: TypeId) -> Self

Adds a positional parameter. Delegates to TableFunctionBuilder::param.

Source

pub fn param_logical(self, logical_type: LogicalType) -> Self

Adds a positional parameter with a complex LogicalType. Delegates to TableFunctionBuilder::param_logical.

Source

pub fn named_param(self, name: &str, type_id: TypeId) -> Self

Adds a named parameter. Delegates to TableFunctionBuilder::named_param.

Source

pub fn named_param_logical(self, name: &str, logical_type: LogicalType) -> Self

Adds a named parameter with a complex LogicalType. Delegates to TableFunctionBuilder::named_param_logical.

Source

pub fn build(self) -> Result<TableFunctionBuilder, ExtensionError>

Finalises the typed builder into a raw TableFunctionBuilder ready for registration.

The returned builder has its bind, init, and scan callbacks wired to closure trampolines, and stores the user closures in extra_info for the lifetime of the registered function.

The closures are owned by the returned builder’s extra_info: they are handed to DuckDB on successful registration, and freed when the builder is dropped otherwise — an unregistered builder does not leak.

§Errors

Returns an error if scan was never called (the bind closure is always set at construction time), or if projection_pushdown was enabled on the raw builder before it was turned into a typed one. The typed scan closure writes columns in declaration order and cannot learn the projection, so with pushdown on SELECT b would receive column a’s values. Switching it off silently would change configuration the caller asked for, so it is an error instead.

Trait Implementations§

Source§

impl<S: Send + 'static> Debug for TypedTableFunctionBuilder<S>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.