Another update from my side
I opened a pull request at the DuckDB repo that implements UDF like it was suggested in the Github Discussion.
Implementing the creation of the function pointer for C was more difficult than I thought, so there might be a better way to do this. If I have any suggestions, improvement ideas, I’m happy for any “pointers”
Usage will look like this:
using DuckDB, DataFrames
f_add = (a, b) -> a + b
db = DuckDB.DB()
con = DuckDB.connect(db)
# Create the scalar function
# the second argument can be omitted if the function name is identical to a global symbol
fun = DuckDB.@create_scalar_function f_add(a::Int, b::Int)::Int f_add
DuckDB.register_scalar_function(con, fun)
df = DataFrame(a = [1, 2, 3], b = [1, 2, 3])
DuckDB.register_table(con, df, "test1")
result = DuckDB.execute(con, "SELECT f_add(a, b) as result FROM test1") |> DataFrame
Feedback of course welcome