-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Drivers for User-Defined Functions #71172
Description
Use case
Allow a user to write code or configuration for a function in an arbitrary language directly in the CREATE FUNCTION statement.
So, instead of configuring a fixed, predefined UDF as in https://clickhouse.com/docs/en/sql-reference/functions/udf, the user will rely on a driver, that generates them from a provided code snippet.
Describe the solution you'd like
The user provides the code in the form of an inline snippet. It can look as follows:
CREATE FUNCTION my_function (arg1 Type1, arg2 Type2) RETURNS Type3
ENGINE = DriverName AS
$$
code is here
...
$$
Drivers are defined in the server configuration. A driver is responsible for the interpretation of the code (how to transform a snippet into an executable file), its security (it could place the code inside Docker, nsjail, gvisor, or even on a separate machine).
The interface and configuration of the driver can be opaque and represented by:
- a command to run to create a new UDF, which accepts the code snippet in stdin and prints to stdout a command to run the created actual UDF;
- a command to delete a UDF;
The user-provided code snippet is untrusted, but the driver itself is the trusted part of the infrastructure. Its responsibility is to create necessary files and provide a command to run the user code in a secure way. The rest works with the existing mechanism of executable UDFs: https://clickhouse.com/docs/en/sql-reference/functions/udf
Additional context
This solution is very generic, but it should be provided with examples, e.g., how to build a UDF driver to run JavaScript functions using Node.js inside Docker.