Custom Functions

Hydrolix provides the ability to create user-defined functions.

Custom Functions

Hydrolix custom functions are created using the API and are scoped to specific projects to avoid namespace collision.

Custom function configuration follows a similar method as can be found here - https://clickhouse.com/docs/en/sql-reference/statements/create/function/.

Defining Functions

To specify your function with the API you should define it as follows:

POST https://{hostname}.hydrolix.live/config/v1/orgs/{org_id}/projects/{project_id}/functions/
Authorization: Bearer {{access_token}}
Content-Type: application/json

{
     "sql": "(x, k, b) -> k*x + b;",
     "name": "linear_equation"
}

Alternatively, you can define multiple functions with one API call:

POST https://{hostname}.hydrolix.live/config/v1/orgs/{org_id}/projects/{project_id}/functions/bulk_function/
Authorization: Bearer {{access_token}}
Content-Type: application/json

[
    {
        "name": "sample_function1",
        "description": "sample function 1",
        "sql": "SELECT * FROM sample_project.sample_table_1 FORMAT JSON"
    },
    {
        "name": "sample_function2",
        "description": "sample function 2",
        "sql": "SELECT * FROM sample_project.sample_table_2 FORMAT JSON"
    }
]

📘

The SQL is just the function definition

The sql section of the function config corresponds to the expression which immediately follows:
CREATE FUNCTION <function name> AS ...

NameDefinition
sqlThe function's specification
nameThe name of the function

Example Custom Function Usage

SELECT
    number,
    {{projectname}}_linear_equation(number, 2, 1)
FROM numbers(3)

┌─number─┬─plus(multiply(2, number), 1)─┐
│      0 │                            1 │
│      1 │                            3 │
│      2 │                            5 │
└────────┴──────────────────────────────┘