Arrow UDF Python Server
Installation
pip install arrow-udf
Usage
Define functions in a Python file:
# udf.py
from arrow_udf import udf, udtf, UdfServer
import struct
import socket
# Define a scalar function
@udf(input_types=['INT', 'INT'], result_type='INT')
def gcd(x, y):
while y != 0:
(x, y) = (y, x % y)
return x
# Define a scalar function that returns multiple values (within a struct)
@udf(input_types=['BINARY'], result_type='STRUCT<src_addr: STRING, dst_addr: STRING, src_port: INT16, dst_port: INT16>')
def extract_tcp_info(tcp_packet: bytes):
src_addr, dst_addr = struct.unpack('!4s4s', tcp_packet[12:20])
src_port, dst_port = struct.unpack('!HH', tcp_packet[20:24])
src_addr = socket.inet_ntoa(src_addr)
dst_addr = socket.inet_ntoa(dst_addr)
return {
'src_addr': src_addr,
'dst_addr': dst_addr,
'src_port': src_port,
'dst_port': dst_port,
}
# Define a table function
@udtf(input_types='INT', result_types='INT')
def series(n):
for i in range(n):
yield i
# Start a UDF server
if __name__ == '__main__':
server = UdfServer(location="0.0.0.0:8815")
server.add_function(gcd)
server.add_function(extract_tcp_info)
server.add_function(series)
server.serve()
Start the UDF server:
python3 udf.py
Data Types
| Arrow Type | Python Type |
|---|---|
boolean |
bool |
int8 |
int |
int16 |
int |
int32 |
int |
int64 |
int |
uint8 |
int |
uint16 |
int |
uint32 |
int |
uint64 |
int |
float32 |
float |
float32 |
float |
date32 |
datetime.date |
time64 |
datetime.time |
timestamp |
datetime.datetime |
interval |
MonthDayNano / (int, int, int) (fields can be obtained by months(), days() and nanoseconds() from MonthDayNano) |
string |
str |
binary |
bytes |
large_string |
str |
large_binary |
bytes |
Extension types:
| Data type | Metadata | Python Type |
|---|---|---|
decimal |
arrowudf.decimal |
decimal.Decimal |
json |
arrowudf.json |
any |
Metadata
Release files for arrow-udf 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| arrow_udf-0.3.2.tar.gz | 10.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| arrow_udf-0.3.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.0 kB
Release files / arrow_udf-0.3.2.tar.gz
| Download URL | arrow_udf-0.3.2.tar.gz |
|---|---|
| Size | 10.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8f15c46b778918e9092dd3830e4a0f8a12d0e5417f6827e06cbc4c970c53684f
|
|
BLAKE2b-256 checksum How to use checksums |
c0a6e6a63a52ac1084bfbc00b7f8b361a36c66750f7bc0716db9415406d04564
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Release files / arrow_udf-0.3.2-py3-none-any.whl
| Download URL | arrow_udf-0.3.2-py3-none-any.whl |
|---|---|
| Size | 11.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
42497fb7585819d6bf36d3eecfcc9e5f7f49ab4c63196825e66e560a0ed704ec
|
|
BLAKE2b-256 checksum How to use checksums |
36a87dbd453516b811b9454d121dfba32bdc46d3628fbf1557f7f0502fab2d63
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|