How to store a vector of struct

Based on the reading of the source code, Attribute can be type of any trivially copyable classes. So here is my vector of cytoParam, which is a struct.


Currently I am splitting and storing each element of the struct separately, which seems to be a little more complicated than it should be.

Ideally I’d like to store them as a single attribute, e.g.
schema.add_attribute(tiledb::Attribute::create(ctx, “params”));

query.set_buffer(“params”, params);

And it doesn’t seem to work,

/usr/local/include/tiledb/attribute.h:306:15: error: ‘tiledb_type’ is not a member of ‘DataT {aka tiledb::impl::TypeHandler<cytolib::cytoParam, void>}’
Attribute a(ctx, name, DataT::tiledb_type);
^
/usr/local/include/tiledb/attribute.h:307:5: error: ‘tiledb_num’ is not a member of ‘DataT {aka tiledb::impl::TypeHandler<cytolib::cytoParam, void>}’
a.set_cell_val_num(DataT::tiledb_num);

I’d like to know if I am not doing things correctly or simply it is not supported yet (since I don’t see it is documented besides the source code).

Or someone can point me to more concise and efficient way of storing such meta data.

Hi Mike, apologies for responding late to that.

What you are asking essentially is a way for TileDB to handle arbitrary structs, i.e., user-defined data types. This is definitely a feature we are interested in adding. Do you mind posting a feature request here: https://feedback.tiledb.com/tiledb-core

In the meantime, you will have to do this rather manually:

  1. Define the attribute as a “byte vector” (i.e., as TILEDB_CHAR or TILEDB_UINT8 and set cell_val_num to TILEDB_VAR_NUM)
  2. Serialize all struct values in a byte vector to be passed as the cell value upon writes.
  3. Add the struct members as array metadata so that you know which struct this attribute corresponds to and what the member data types are, so that anyone can (manually) deserialize the byte vectors of those cells upon reading.

I hope this helps.