Var-length Attributes

Writing variable-length attribute values to an array involves passing two buffers to TileDB, one for the variable-length cell values and one for the starting offset of each value in the first buffer. We illustrate this in the code block below with a sparse write, but it is also applicable to dense writes.

#include <tiledb/tiledb.h>

// Create TileDB context
tiledb_ctx_t* ctx;
tiledb_ctx_alloc(NULL, &ctx);

// Open array for writing
tiledb_array_t* array;
tiledb_array_alloc(ctx, array_name, &array);
tiledb_array_open(ctx, array, TILEDB_WRITE);

// Prepare some data for the array
long long d1[] = {1, 2, 3, 4};
unsigned long long d1_size = sizeof(d1);
long long d2[] = {2, 1, 3, 4};
unsigned long long d2_size = sizeof(d2);
int data[] = {1, 1, 2, 3, 3, 3, 4};
unsigned long long a_size = sizeof(a);
unsigned long long a_off[] = {0, 8, 12, 24};
unsigned long long a_off_size = sizeof(a_off);

// Create the query
tiledb_query_t* query;
tiledb_query_alloc(ctx, array, TILEDB_WRITE, &query);
tiledb_query_set_layout(ctx, query, TILEDB_UNORDERED);
tiledb_query_set_data_buffer(ctx, query, "d1", d1, &d1_size);
tiledb_query_set_data_buffer(ctx, query, "d2", d2, &d2_size);
tiledb_query_set_data_buffer(ctx, query, "a", a, &a_size);
tiledb_query_set_offsets_buffer(ctx, query, "a", a_off, &a_off_size);

// Submit query
tiledb_query_submit(ctx, query);

// Close array
tiledb_array_close(ctx, array);

// Clean up
tiledb_array_free(&array);
tiledb_query_free(&query);
tiledb_ctx_free(&ctx);

The code snippet above produces the following sparse fragment.

Last updated