Skip to content

Commit 7b09bb1

Browse files
committed
feat: add comprehensive client library and CI workflow
- Add UDFClient for simplified UDF server testing - Implement professional test suite with isolated server instances - Add comprehensive validation and error handling - Support both positional and batch function calls - Update CI workflow to include linting, formatting, and testing - Test coverage across Python 3.9-3.12 - Fix code formatting and linting issues
1 parent f301c5d commit 7b09bb1

File tree

15 files changed

+788
-5
lines changed

15 files changed

+788
-5
lines changed

.github/workflows/python.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,33 @@ concurrency:
2020
jobs:
2121
test:
2222
runs-on: ubuntu-latest
23+
strategy:
24+
matrix:
25+
python-version: ["3.9", "3.10", "3.11", "3.12"]
2326
steps:
2427
- uses: actions/checkout@v4
25-
- name: Setup Python
28+
- name: Setup Python ${{ matrix.python-version }}
2629
uses: actions/setup-python@v5
2730
with:
28-
python-version: "3.12"
31+
python-version: ${{ matrix.python-version }}
2932
- name: Install dependencies
3033
working-directory: python
31-
run: pip install ruff
34+
run: |
35+
python -m pip install --upgrade pip
36+
pip install -e .[lint,test]
37+
- name: Lint with ruff
38+
working-directory: python
39+
run: |
40+
ruff check .
3241
- name: Check format
3342
working-directory: python
3443
run: |
3544
ruff format --check .
36-
- name: build
45+
- name: Run tests
46+
working-directory: python
47+
run: |
48+
python -m pytest tests/ -v --tb=short
49+
- name: Build package
3750
working-directory: python
3851
run: |
3952
python -m pip install build

python/README_CLIENT.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Databend UDF Client Library
2+
3+
Simple Python client library for testing Databend UDF servers.
4+
5+
## Installation
6+
7+
```bash
8+
pip install databend-udf
9+
```
10+
11+
## Quick Start
12+
13+
```python
14+
from databend_udf import UDFClient, create_client
15+
16+
# Create client (default: localhost:8815)
17+
client = create_client()
18+
19+
# Or specify host/port
20+
client = UDFClient(host="localhost", port=8815)
21+
22+
# Health check
23+
if client.health_check():
24+
print("Server is running!")
25+
26+
# Echo test
27+
result = client.echo("Hello, Databend!")
28+
print(result) # "Hello, Databend!"
29+
30+
# Call UDF function
31+
result = client.call_function("gcd", 48, 18)
32+
print(result[0]) # 6
33+
```
34+
35+
## API Reference
36+
37+
### UDFClient
38+
39+
#### Methods
40+
41+
- `__init__(host="localhost", port=8815)` - Create client
42+
- `health_check() -> bool` - Check server health
43+
- `echo(message: str) -> str` - Echo test message
44+
- `call_function(name, *args) -> List[Any]` - Call UDF with arguments
45+
- `call_function_batch(name, **kwargs) -> List[Any]` - Call UDF with batch data
46+
- `get_function_info(name) -> FlightInfo` - Get function schema
47+
- `list_functions() -> List[str]` - List available functions
48+
49+
### Examples
50+
51+
#### Single Value Calls
52+
53+
```python
54+
client = create_client()
55+
56+
# Numeric functions
57+
result = client.call_function("add_signed", 1, 2, 3, 4)
58+
print(result[0]) # 10
59+
60+
# String functions
61+
result = client.call_function("split_and_join", "a,b,c", ",", "-")
62+
print(result[0]) # "a-b-c"
63+
64+
# Array functions
65+
result = client.call_function("array_access", ["hello", "world"], 1)
66+
print(result[0]) # "hello"
67+
```
68+
69+
#### Batch Calls
70+
71+
```python
72+
client = create_client()
73+
74+
# Process multiple values at once
75+
x_values = [48, 56, 72]
76+
y_values = [18, 21, 24]
77+
results = client.call_function_batch("gcd_batch", a=x_values, b=y_values)
78+
print(results) # [6, 7, 24]
79+
```
80+
81+
## Testing
82+
83+
Run the example server:
84+
85+
```bash
86+
cd python/example
87+
python server.py
88+
```
89+
90+
In another terminal, run tests:
91+
92+
```bash
93+
# Simple test
94+
python simple_test.py
95+
96+
# Comprehensive test suite
97+
python client_test.py
98+
```
99+
100+
## Error Handling
101+
102+
```python
103+
try:
104+
result = client.call_function("my_function", arg1, arg2)
105+
print(result[0])
106+
except Exception as e:
107+
print(f"Function call failed: {e}")
108+
```
109+
110+
## Performance Testing
111+
112+
The client supports testing concurrent I/O operations:
113+
114+
```python
115+
# Sequential calls (slow)
116+
for i in range(10):
117+
client.call_function("slow_function", i)
118+
119+
# Batch call (fast with io_threads)
120+
client.call_function_batch("slow_function", a=list(range(10)))
121+
```

python/databend_udf/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
from .udf import * # noqa
2+
from .client import UDFClient, create_client
3+
4+
__all__ = ["UDFClient", "create_client"]

0 commit comments

Comments
 (0)