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
param: positional parameters.named_param: named parameters (name := value).local_init: per-thread init (enables parallel scan).projection_pushdown: hint projection info toDuckDB.extra_info: function-level data available in all callbacks.
Implementations§
Source§impl TableFunctionBuilder
impl TableFunctionBuilder
Sourcepub fn new(name: &str) -> Self
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.
Sourcepub fn try_new(name: &str) -> Result<Self, ExtensionError>
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.
Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Returns the function name.
Useful for introspection and for MockRegistrar.
Sourcepub fn param_logical(self, logical_type: LogicalType) -> Self
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(...).
Sourcepub fn named_param(self, name: &str, type_id: TypeId) -> Self
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.
Sourcepub fn named_param_logical(self, name: &str, logical_type: LogicalType) -> Self
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.
Sourcepub fn bind(self, f: BindFn) -> Self
pub fn bind(self, f: BindFn) -> Self
Sets the bind callback.
The bind callback is called once at query-parse time. It must:
- Declare all output columns via
crate::table::BindInfo::add_result_column. - Optionally read parameters and store bind data via
crate::table::FfiBindData::set.
Sourcepub fn init(self, f: InitFn) -> Self
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.
Sourcepub fn local_init(self, f: InitFn) -> Self
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.
Sourcepub fn scan(self, f: ScanFn) -> Self
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.
Sourcepub const fn projection_pushdown(self, enable: bool) -> Self
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.
Sourcepub unsafe fn extra_info(
self,
data: *mut c_void,
destroy: ExtraDestroyFn,
) -> Self
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().