Description
Is your feature request related to a problem? Please describe.
After seeing some issues #3946 in the community about UDF, I tried to submit a Wasm-based UDF system. I submitted an RFC during the Nebula Hackathon 2021, which is some initial thoughts. This #3566 is the initial code.
I think Wasm-based UDF is a more radical route and needs more guidance and advice.
Describe the solution you'd like
The overall module design is as follows.
Compilation Toolchain: The compiler toolchain is provided for user use and contains a series of initial templates. Users must embed their own code into the initial templates
Parsing: Create functions based on Flex and Bison implementations, and delete SQL statements for functions. The implementation syntax is in the figure below. We consider the two mainstream formats of WebAssembly text format (wat) and Wasm binary files. And its loading methods have two types. The first one is wat base64 encoding and Wasm binary file base64 encoding, which is convenient for direct input in the terminal, the program with the running size at the KB level can be directly imported. The second is the MB level Wasm Program binary files, which support importing by HTTP address and by local file address.
Function Management: Responsible for unified management of Wasm virtual machines, providing dynamic update, loading, and unloading of functions. It can also be said to be the glue for Nebula's other systems and the Wasm extension components.
Runtime: Here we introduce the C++ SDK of Wasm virtual machine,like Wasmtime, and WasmEdge. Calling SDK to compile wat code, compile and execute Wasm binary file, manage sandbox instances and WASI features, etc.
The project will face some known difficulties
- Embedding the whole Wasm runtime into C++ has many compatibility issues.
- Large differences in UDF design with other database systems. There are some learning costs for users.
- Other language communities are not very mature in Wasm related, and although we aim to support all languages, only UDFs for Rust languages can be more easily compiled into Wasm for execution.
Describe alternatives you've considered
Additional context
Does the official team have some initial thoughts on the UDF system design. If the official thinks the Wasm-based UDF system is in line with the project's future plans, I can do this PR.
Activity