Function Extension
Note
Go C-shared native .so dynamic plugins are unsupported in rekuiper. High-performance connectors are compiled directly into the rekuiper Rust binary. Custom function extensions run through WebAssembly (Wasm) or External Services. This guide is preserved as a technical reference for legacy eKuiper installations.
rekuiper provides built-in functions for data processing. You can create custom function extensions to implement domain-specific business logic.
Development
Develop a Custom Function
To create a custom function, implement the api.Function interface and export it from a Go plugin.
Before developing, configure the plugin development environment.
Implement
Validate:goValidate(args []interface{}) errorThe engine calls
Validateduring SQL plan verification. The parameter is a slice of AST expressions. Check argument counts and types. Returnnilif validation succeeds; otherwise, return an error.Implement
IsAggregate:goIsAggregate() boolReturn
trueif the function operates as an aggregate function over grouped window slices; otherwise, returnfalse.Implement
Exec:goExec(args []interface{}) (interface{}, bool)The engine calls
Execto compute the function result. Theargsparameter contains the runtime argument values. Return the result andtrueon success, or returnnilandfalseon failure.Export the Symbol:
The plugin must reside in the
mainpackage. Export the function as a variable symbol:govar MyFunction myFunction
Refer to the Echo Function implementation for a complete reference.
Export Multiple Functions
A single plugin can export multiple functions:
var (
Function1 function1
Function2 function2
FunctionN functionN
)Combining related functions into one plugin simplifies distribution and deployment.
Package the Plugin
Compile the function into a Go plugin .so file in the plugins/functions directory:
go build -trimpath --buildmode=plugin -o plugins/functions/MyFunction.so extensions/functions/my_function.goRegister Functions
The engine automatically loads plugins in the plugin directory. If a plugin exports multiple functions, register them explicitly:
- Development: Place the compiled
.sofile intoplugins/functions, then invoke the CLI register command or the REST register API. - Production: Package the plugin into a zip archive, then invoke the CLI create command or the REST create API with the function list.
Usage in SQL Rules
Invoke the custom function directly in SQL:
{
"id": "rule1",
"sql": "SELECT myFunction(name) FROM demo",
"actions": [
{
"log": {}
}
]
}