Example WASM User Defined Function (UDF) for Seafowl in Rust.
First install Rust and Cargo, then install cargo-wasi by running:
cargo install cargo-wasi
cargo wasi build --release
Just like the add_i64
example function, for Seafowl to successfully invoke your UDF, it must:
- Use the
#[no_mangle]
attribute, otherwise the exported function will be renamed and Seafowl will not be able to load it. - Accept and return pointers to msgpack-serialized buffers. The
wrap_udf
function takes care of (de)serialization, as shown by the demo function.
Messages sent to stderr
via eprintln!()
will be visible in the Seafowl console.
A WASM module may include multiple user-defined functions, but each one must be loaded with a separate CREATE FUNCTION ...
statement.
This repository includes the create_udf.sh
shell script which creates the Seafowl function wrapping the Rust WASM logic.
Be sure to update the parameters within this file to match your own UDFs' name and signature.
To use the script as-is, start a local Seafowl instance with HTTP write access enabled, eg:
SEAFOWL__FRONTEND__HTTP__WRITE_ACCESS=any ./target/release/seafowl
To load the example add_i64()
function into a locally running Seafowl, just run:
./create_udf.sh
Invoking the newly created UDF:
./query_udf.sh
Edit query_udf.sh
to change the function's arguments or run more complex queries.
cargo test