Trait duckdb::vtab::VTab

source ·
pub trait VTab: Sized {
    type InitData: Sized + Free;
    type BindData: Sized + Free;

    // Required methods
    unsafe fn bind(
        bind: &BindInfo,
        data: *mut Self::BindData
    ) -> Result<(), Box<dyn Error>>;
    unsafe fn init(
        init: &InitInfo,
        data: *mut Self::InitData
    ) -> Result<(), Box<dyn Error>>;
    unsafe fn func(
        func: &FunctionInfo,
        output: &mut DataChunk
    ) -> Result<(), Box<dyn Error>>;

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

Duckdb table function trait

See to the HelloVTab example for more details https://duckdb.org/docs/api/c/table_functions

Required Associated Types§

source

type InitData: Sized + Free

The data type of the bind data

source

type BindData: Sized + Free

The data type of the init data

Required Methods§

source

unsafe fn bind( bind: &BindInfo, data: *mut Self::BindData ) -> Result<(), Box<dyn Error>>

Bind data to the table function

§Safety

This function is unsafe because it dereferences raw pointers (data) and manipulates the memory directly. The caller must ensure that:

  • The data pointer is valid and points to a properly initialized BindData instance.
  • The lifetime of data must outlive the execution of bind to avoid dangling pointers, especially since bind does not take ownership of data.
  • Concurrent access to data (if applicable) must be properly synchronized.
  • The bind object must be valid and correctly initialized.
source

unsafe fn init( init: &InitInfo, data: *mut Self::InitData ) -> Result<(), Box<dyn Error>>

Initialize the table function

§Safety

This function is unsafe because it performs raw pointer dereferencing on the data argument. The caller is responsible for ensuring that:

  • The data pointer is non-null and points to a valid InitData instance.
  • There is no data race when accessing data, meaning if data is accessed from multiple threads, proper synchronization is required.
  • The lifetime of data extends beyond the scope of this call to avoid use-after-free errors.
source

unsafe fn func( func: &FunctionInfo, output: &mut DataChunk ) -> Result<(), Box<dyn Error>>

The actual function

§Safety

This function is unsafe because it:

  • Dereferences multiple raw pointers (func to access init_info and bind_info).

The caller must ensure that:

  • All pointers (func, output, internal init_info, and bind_info) are valid and point to the expected types of data structures.
  • The init_info and bind_info data pointed to remains valid and is not freed until after this function completes.
  • No other threads are concurrently mutating the data pointed to by init_info and bind_info without proper synchronization.
  • The output parameter is correctly initialized and can safely be written to.

Provided Methods§

source

fn supports_pushdown() -> bool

Does the table function support pushdown default is false

source

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

The parameters of the table function default is None

source

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

The named parameters of the table function default is None

Object Safety§

This trait is not object safe.

Implementors§