Skip to main content

TableFunctionBuilder

Struct TableFunctionBuilder 

Source
pub struct TableFunctionBuilder { /* private fields */ }
Expand description

Builder for registering a DuckDB table function.

Table functions are the most powerful extension type — they can return arbitrary result schemas, support named parameters, projection pushdown, and parallel execution.

§Required fields

§Optional features

Implementations§

Source§

impl TableFunctionBuilder

Source

pub fn new(name: &str) -> Self

Creates a new builder for a table function with the given name.

§Panics

Panics if name contains an interior null byte.

Source

pub fn try_new(name: &str) -> Result<Self, ExtensionError>

Creates a new builder with function name validation.

§Errors

Returns ExtensionError if the name is invalid.

Source

pub fn name(&self) -> &str

Returns the function name.

Useful for introspection and for MockRegistrar.

Source

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

Adds a positional parameter with the given type.

Source

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

Adds a positional parameter with a complex LogicalType.

Use this for parameterized types that TypeId cannot express, such as LIST(BIGINT), MAP(VARCHAR, INTEGER), or STRUCT(...).

Source

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

Adds a named parameter (e.g., my_fn(path := 'data.csv')).

Named parameters are accessed in the bind callback via duckdb_bind_get_named_parameter.

§Panics

Panics if name contains an interior null byte.

Source

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

Adds a named parameter with a complex LogicalType.

Use this for parameterized types that TypeId cannot express.

§Panics

Panics if name contains an interior null byte.

Source

pub fn bind(self, f: BindFn) -> Self

Sets the bind callback.

The bind callback is called once at query-parse time. It must:

Source

pub fn init(self, f: InitFn) -> Self

Sets the global init callback.

Called once per query. Use crate::table::FfiInitData::set to store global scan state.

Source

pub fn local_init(self, f: InitFn) -> Self

Sets the per-thread local init callback (optional).

When set, DuckDB calls this once per worker thread. Use crate::table::FfiLocalInitData::set to store thread-local scan state. Setting a local init enables parallel scanning.

Source

pub fn scan(self, f: ScanFn) -> Self

Sets the scan callback.

Called repeatedly until all rows are produced. Set the output chunk’s size to 0 (via duckdb_data_chunk_set_size(output, 0)) to signal end of stream.

Source

pub const fn projection_pushdown(self, enable: bool) -> Self

Enables or disables projection pushdown support (default: disabled).

When enabled, DuckDB informs the init callback which columns were requested. Use duckdb_init_get_column_count and duckdb_init_get_column_index in your init callback to skip producing unrequested columns.

Source

pub unsafe fn extra_info( self, data: *mut c_void, destroy: ExtraDestroyFn, ) -> Self

Sets function-level extra info shared across all callbacks.

This data is available via duckdb_function_get_extra_info and duckdb_bind_get_extra_info in all callbacks. The destroy callback is called by DuckDB when the function is dropped.

§Safety

data must remain valid until DuckDB calls destroy. The typical pattern is to box your data: Box::into_raw(Box::new(my_data)).cast().

Source

pub unsafe fn register( self, con: duckdb_connection, ) -> Result<(), ExtensionError>

Registers the table function on the given connection.

§Errors

Returns ExtensionError if:

  • The bind, init, or scan callback was not set.
  • DuckDB reports a registration failure.
§Safety

con must be a valid, open duckdb_connection.

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.