duckdb / duckdb-rs

Ergonomic bindings to duckdb for Rust
MIT License
511 stars 113 forks source link

`DataStruct.struct_vector(i).child(j)` leads to assertion failure #272

Open solidsnack opened 8 months ago

solidsnack commented 8 months ago

This project has brought me quite close to realizing a new extension of DuckDB.

I'm using duckdb-rs@919f145 with features = ["bundled", "vtab-loadable"] on a 2022 M2 Mac.

In a VTab::func implementation, I would like to update a structured column. That's easy enough -- get the column and then get its subcolumns and update each one. However, something goes wrong when calling StructVector.child()

Assertion failed: (dynamic_cast<TARGET *>(this)), function Cast, file vector_buffer.hpp, line 132.
Abort trap: 6

This function just calls duckdb_struct_vector_get_child, though, so it's hard to see how there could be anything wrong with it. That function ultimately delegates to StructVector::GetEntries (in C++). Inserting std::cout << ... lines indicates that all the types are as expected:

However, the call to vector.auxiliary->Cast<VectorStructBuffer>() fails. It turns out there is a dynamic cast in that function, as a kind of assert:

D_ASSERT(dynamic_cast<TARGET *>(this));

This is what is failing. Commenting it out seems to lead to no problems. Then I am able to get the flat buffers and add data to them (with Inserter or using .set_null(), &c) and query the results in DuckDB.

This recent commit may be related: https://github.com/duckdb/duckdb/commit/837211d985ae485d09b8df18f58bf794a6857219