Hi all, following up from How to insert nested/composite types into DuckDB from a DataFrame? - #3 by slwu89 I’m peeking into what it would take to support inserting, say Vector{Int} into a DuckDB database using the appender API.
It appears that even supporting this feature in the DuckDB C API is a relatively recent addition, see add duckdb_append_value to C API by jraymakers · Pull Request #15065 · duckdb/duckdb · GitHub which added duckdb_append_value to the C API. Luckily because the Julia interface to the C API is programatically generated, it is there, waiting to be used.
I want to start thinking about how to do the simple case of inserting a vector of primitive types into the DB. Looking at the tests for duckdb_append_value, the relevant example is here: public-duckdb/test/api/capi/test_capi_appender.cpp at 5fb7d105c5bc3806921cb596db98b46f6166df5b · motherduckdb/public-duckdb · GitHub. Peeking at the test, the basic thing is:
- use
duckdb_create_list_value(see Values – DuckDB) to create an instance ofduckdb_value, which stores the element type, the pointer to values, and the length of the list. - use
duckdb_append_value(see Appender – DuckDB) to append thatduckdb_valuefrom 1.
My main question at this point revolves around step 1. Because the values argument for duckdb_create_list_value is a duckdb_value*, it seems I’d have to detect the eltype of the Vector and then use the appropriate duckdb_create_X method from the Julia interface to the C API. Does this approach seem reasonable or have I gotten things wrong (yes, ignoring missings for now)? I’m new to DuckDB and its Julia package, but I’m interested in contributing to expanding the functionality of the Julia interface.