chdb-io / chdb

chDB is an in-process OLAP SQL Engine 🚀 powered by ClickHouse
https://clickhouse.com/docs/en/chdb
Apache License 2.0
1.93k stars 70 forks source link

Support for executable UDF #237

Open arnaudbriche opened 1 month ago

arnaudbriche commented 1 month ago

Does chdb support executable UDF functions ? If so, how do we configure chdb ?

auxten commented 1 month ago

chDB is ClickHouse, so all things would be like executable UDF functions

Here is an example:

root@0a8b55995b6e:/auxten/chdb/tests# python3 udf3.py 
"Value 2"

udf3.py

import chdb

ret = chdb.query(
    "SELECT test_function_python(toUInt64(2));",
    udf_path="/auxten/chdb/tests/.udf",
)
print(ret)

.udf/udf.xml

<functions>
    <function>
        <type>executable</type>
        <name>test_function_python</name>
        <return_type>String</return_type>
        <argument>
            <type>UInt64</type>
            <name>value</name>
        </argument>
        <format>TabSeparated</format>
        <command>test_function.py</command>
    </function>
</functions>

DO NOT forget chmod +x .udf/test_function.py .udf/test_function.py

#!/usr/bin/python3

import sys

if __name__ == '__main__':
    for line in sys.stdin:
        print("Value " + line, end='')
        sys.stdout.flush()