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§
Required Methods§
sourceunsafe fn bind(
bind: &BindInfo,
data: *mut Self::BindData
) -> Result<(), Box<dyn Error>>
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 initializedBindData
instance. - The lifetime of
data
must outlive the execution ofbind
to avoid dangling pointers, especially sincebind
does not take ownership ofdata
. - Concurrent access to
data
(if applicable) must be properly synchronized. - The
bind
object must be valid and correctly initialized.
sourceunsafe fn init(
init: &InitInfo,
data: *mut Self::InitData
) -> Result<(), Box<dyn Error>>
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 validInitData
instance. - There is no data race when accessing
data
, meaning ifdata
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.
sourceunsafe fn func(
func: &FunctionInfo,
output: &mut DataChunk
) -> Result<(), Box<dyn Error>>
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 accessinit_info
andbind_info
).
The caller must ensure that:
- All pointers (
func
,output
, internalinit_info
, andbind_info
) are valid and point to the expected types of data structures. - The
init_info
andbind_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
andbind_info
without proper synchronization. - The
output
parameter is correctly initialized and can safely be written to.
Provided Methods§
sourcefn supports_pushdown() -> bool
fn supports_pushdown() -> bool
Does the table function support pushdown default is false
sourcefn parameters() -> Option<Vec<LogicalType>>
fn parameters() -> Option<Vec<LogicalType>>
The parameters of the table function default is None
sourcefn named_parameters() -> Option<Vec<(String, LogicalType)>>
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.