Skip to content

Commit

Permalink
feat(python): update example in document
Browse files Browse the repository at this point in the history
  • Loading branch information
everpcpc committed Nov 7, 2023
1 parent 00b3f29 commit b17a676
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
31 changes: 17 additions & 14 deletions python/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
## Databend UDF Server Tests

```sh
pip install pyarrow
# start UDF server
python3 udf_test.py
```

```sh
./target/debug/databend-sqllogictests --run_dir udf_server
```

## Databend Python UDF Server API
This library provides a Python API for creating user-defined functions (UDF) server in Databend.
Expand All @@ -20,14 +9,14 @@ Databend supports user-defined functions implemented as external functions. With

#### 1. Define your functions in a Python file
```python
from udf import *
from databend_udf import *

# Define a function
@udf(input_types=["VARCHAR", "VARCHAR", "VARCHAR"], result_type="VARCHAR")
def split_and_join(s: str, split_s: str, join_s: str) -> str:
return join_s.join(s.split(split_s))

# Define a function that accpets nullable values, and set skip_null to True to enable it returns NULL if any argument is NULL.
# Define a function that accepts nullable values, and set skip_null to True to enable it returns NULL if any argument is NULL.
@udf(
input_types=["INT", "INT"],
result_type="INT",
Expand All @@ -38,7 +27,7 @@ def gcd(x: int, y: int) -> int:
(x, y) = (y, x % y)
return x

# Define a function that accpets nullable values, and set skip_null to False to enable it handles NULL values inside the function.
# Define a function that accepts nullable values, and set skip_null to False to enable it handles NULL values inside the function.
@udf(
input_types=["ARRAY(INT64 NULL)", "INT64"],
result_type="INT NOT NULL",
Expand Down Expand Up @@ -125,6 +114,7 @@ mysql> select split_and_join('3,5,7', ',', ':');
+-----------------------------------+
```


### Data Types
The data types supported by the Python UDF API and their corresponding python types are as follows :

Expand All @@ -148,5 +138,18 @@ The data types supported by the Python UDF API and their corresponding python ty

The NULL in sql is represented by None in Python.


## Databend UDF Server Tests

```sh
# start UDF server
python3 udf_test.py
```

```sh
./target/debug/databend-sqllogictests --run_dir udf_server
```


### Acknowledgement
Databend Python UDF Server API is inspired by [RisingWave Python API](https://pypi.org/project/risingwave/).
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ classifiers = [
description = "Databend UDF Server"
license = { text = "Apache-2.0" }
name = "databend-udf"
version = "0.1.0"
version = "0.1.1"
readme = "README.md"
requires-python = ">=3.7"
dependencies = ["pyarrow"]
Expand Down

0 comments on commit b17a676

Please sign in to comment.