Skip to main content

VTab

Trait VTab 

Source
pub trait VTab: Sized {
    type BindData: Send + Sync;
    type InitData: Send + Sync;

    // Required methods
    fn bind(bind: &BindInfo) -> UdfResult<Self::BindData>;
    fn init(init: &InitInfo<Self>) -> UdfResult<Self::InitData>;
    fn func(
        func: &TableFunctionInfo<Self>,
        output: &mut DataChunkHandle,
    ) -> UdfResult<()>;

    // Provided methods
    fn parameters() -> Result<Vec<LogicalType>> { ... }
    fn named_parameters() -> Result<Vec<(String, LogicalType)>> { ... }
    fn supports_projection_pushdown() -> bool { ... }
}
Expand description

A DuckDB table function: produces rows and columns for use in a FROM clause, e.g. SELECT * FROM my_func(1, 2).

See the callback containment contract in crate::udf.

Required Associated Types§

Source

type BindData: Send + Sync

Data produced once by VTab::bind and shared, read-only, by every later call to VTab::init and VTab::func for this query.

Source

type InitData: Send + Sync

Data produced once by VTab::init, shared across every worker thread executing this query. Any interior mutation must be synchronized.

Required Methods§

Source

fn bind(bind: &BindInfo) -> UdfResult<Self::BindData>

Determines the function’s output schema (via BindInfo::add_result_column) and produces the data shared by every later call for this query.

§Errors

Returns an error to fail the query with that message.

Source

fn init(init: &InitInfo<Self>) -> UdfResult<Self::InitData>

Produces data shared across every worker thread executing this query, e.g. the initial position of a cursor.

§Errors

Returns an error to fail the query with that message.

Source

fn func( func: &TableFunctionInfo<Self>, output: &mut DataChunkHandle, ) -> UdfResult<()>

Writes up to output.capacity() rows into output, then calls output.set_len(k) with the number actually written. Called repeatedly until set_len(0) (or output.len() == 0 on entry, if untouched) signals the scan is complete.

§Errors

Returns an error to fail the query with that message.

Provided Methods§

Source

fn parameters() -> Result<Vec<LogicalType>>

The positional parameter types this function accepts, in order. Empty by default (no positional parameters).

§Errors

Returns an error if a parameter’s logical type cannot be built.

Source

fn named_parameters() -> Result<Vec<(String, LogicalType)>>

The named (keyword) parameters this function accepts, as (name, type) pairs. Empty by default (no named parameters). Read back during VTab::bind via BindInfo::get_named_parameter.

§Errors

Returns an error if a parameter’s logical type cannot be built.

Source

fn supports_projection_pushdown() -> bool

Whether this function can consume a projected column list — i.e. honors InitInfo::column_indices in VTab::init/VTab::func to skip producing columns the query doesn’t need. false by default (every column is always written).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§