I took a shot pulling together the custom aggregate functions api, but havent quite made it work.
I also tried multiple iterations of an easier function call but was unable to get it.
I think for now I may submit the PR and see if it becomes clearer in the mean time
here is the api i put together so far
# ctypes.jl
const duckdb_aggregate_function = Ptr{Cvoid}
# api.jl aggregate functions
function duckdb_create_aggregate_function()
return ccall((:duckdb_create_aggregate_function, libduckdb), duckdb_aggregate_function, ())
end
function duckdb_destroy_aggregate_function(func)
return ccall((:duckdb_destroy_aggregate_function, libduckdb), Cvoid, (Ref{duckdb_aggregate_function},), func)
end
function duckdb_aggregate_function_set_name(func, name)
return ccall((:duckdb_aggregate_function_set_name, libduckdb), Cvoid, (duckdb_aggregate_function, Ptr{UInt8}), func, name)
end
function duckdb_aggregate_function_add_parameter(func, type)
return ccall(
(:duckdb_aggregate_function_add_parameter, libduckdb),
Cvoid,
(duckdb_aggregate_function, duckdb_logical_type),
func,
type
)
end
function duckdb_aggregate_function_set_return_type(func, type)
return ccall(
(:duckdb_aggregate_function_set_return_type, libduckdb),
Cvoid,
(duckdb_aggregate_function, duckdb_logical_type),
func,
type
)
end
function duckdb_aggregate_function_set_state_size(func, size::UInt64)
return ccall(
(:duckdb_aggregate_function_set_state_size, libduckdb),
Cvoid,
(duckdb_aggregate_function, UInt64),
func,
size
)
end
function duckdb_aggregate_function_set_init(func, init_func)
return ccall(
(:duckdb_aggregate_function_set_init, libduckdb),
Cvoid,
(duckdb_aggregate_function, Ptr{Cvoid}),
func,
init_func
)
end
function duckdb_aggregate_function_set_update(func, update_func)
return ccall(
(:duckdb_aggregate_function_set_update, libduckdb),
Cvoid,
(duckdb_aggregate_function, Ptr{Cvoid}),
func,
update_func
)
end
function duckdb_aggregate_function_set_combine(func, combine_func)
return ccall(
(:duckdb_aggregate_function_set_combine, libduckdb),
Cvoid,
(duckdb_aggregate_function, Ptr{Cvoid}),
func,
combine_func
)
end
function duckdb_aggregate_function_set_finalize(func, finalize_func)
return ccall(
(:duckdb_aggregate_function_set_finalize, libduckdb),
Cvoid,
(duckdb_aggregate_function, Ptr{Cvoid}),
func,
finalize_func
)
end
function duckdb_register_aggregate_function(con, func)
return ccall(
(:duckdb_register_aggregate_function, libduckdb),
Int32,
(duckdb_connection, duckdb_aggregate_function),
con,
func
)
end