Expand description
A wrapper crate to make writing SQL user-defined functions (UDFs) easy
This crate provides bindings for easy creation of SQL user-defined functions in Rust. See the readme for more background information.
Usage
Using this crate is fairly simple: create a struct that will be used to
share data among UDF functions (which can be zero-sized), then implement
needed traits for it. BasicUdf
provides function signatures for standard
UDFs, and AggregateUdf
provides signatures for aggregate (and window)
UDFs. See the documentation there for a step-by-step guide.
use udf::prelude::*;
// Our struct that will produce a UDF of name `my_udf`
struct MyUdf {}
#[register]
impl BasicUdf for MyUdf {
// Specify return type of this UDF to be a nullable integer
type Returns<'a> = Option<i64>;
// Perform initialization steps here
fn init<'a>(
cfg: &UdfCfg<Init>,
args: &'a ArgList<'a, Init>
) -> Result<Self, String> {
todo!();
}
// Create a result here
fn process<'a>(
&'a mut self,
cfg: &UdfCfg<Process>,
args: &ArgList<Process>,
error: Option<NonZeroU8>,
) -> Result<Self::Returns<'a>, ProcessError> {
todo!();
}
}
Version Note
Because of reliance on a feature called GATs, this library requires Rust
version >= 1.65 which is currently in beta. If rustup show
does not show
1.65 or greater under active toolchain, you will need to update:
rustup default beta
rustup update beta
1.65 is scheduled to become stable on 2022-11-03, so this message may become irrelevant not long after time of writing.
Re-exports
pub extern crate udf_sys;
Modules
use udf::prelude::*;
to quickly get the
most often used imports.Macros
stderr
to display in server logsStructs
Enums
max_length
parameter