pub trait VScalar: Sized {
type State: Send + Sync + 'static;
type BindData: Send + Sync + 'static;
// Required methods
fn signatures() -> Result<Vec<ScalarSignature>>;
fn bind(bind: &ScalarBindInfo) -> UdfResult<Self::BindData>;
fn invoke(
state: &Self::State,
bind_data: &Self::BindData,
input: &DataChunkHandle,
output: &mut VectorMut<'_>,
) -> UdfResult<()>;
// Provided methods
fn volatile() -> bool { ... }
fn special_handling() -> bool { ... }
}Expand description
A DuckDB scalar function: computes one value per row.
See the callback containment contract in crate::udf.
Required Associated Types§
Sourcetype State: Send + Sync + 'static
type State: Send + Sync + 'static
State set at registration time, shared across every invocation and every
worker thread. Persists for the lifetime of the catalog entry, so it must
be 'static; any interior mutation must be synchronized.
Sourcetype BindData: Send + Sync + 'static
type BindData: Send + Sync + 'static
Per-query data produced by VScalar::bind and shared, read-only, by every
VScalar::invoke call for that query. Use () if the function needs none.
Required Methods§
Sourcefn signatures() -> Result<Vec<ScalarSignature>>
fn signatures() -> Result<Vec<ScalarSignature>>
The possible signatures of this function. Each becomes a DuckDB overload;
VScalar::invoke must be able to handle every one of them.
§Errors
Returns an error if a signature’s logical type cannot be built.
Sourcefn bind(bind: &ScalarBindInfo) -> UdfResult<Self::BindData>
fn bind(bind: &ScalarBindInfo) -> UdfResult<Self::BindData>
Runs once per query that references this function, before any invoke.
Inspects the call’s argument expressions (via ScalarBindInfo — e.g. to
fold a constant argument or reject an unsupported one) and produces the
per-query BindData. Functions needing no bind data
return Ok(()) (with type BindData = ()).
§Errors
Returns an error to reject the query at bind time with that message.
Provided Methods§
Sourcefn volatile() -> bool
fn volatile() -> bool
Whether this function is volatile — re-evaluated for every row even with no parameters, rather than optimized to a constant. Needed for functions like random-number or UUID generators.
Sourcefn special_handling() -> bool
fn special_handling() -> bool
Whether this function should be invoked for rows containing NULL
parameters. By default DuckDB substitutes NULL as the result for any
row with a NULL argument without calling VScalar::invoke at all;
returning true here disables that shortcut.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".