Writing in Dense Subarrays

This is applicable only to dense arrays (see Dense Writes for more details). You can write into a subarray of the array domain as follows:

#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
int data[] = {1, 2, 3, 4, 5, 6};
unsigned long long data_size = sizeof(data);

// Set the subarray to write into
tiledb_subarray_t* subarray;
tiledb_subarray_alloc(ctx, array, &subarray);
int subarrayData[] = {1, 2, 2, 4};
tiledb_subarray_set_subarray(subarray, subarrayData);

// Create the query
tiledb_query_t* query;
tiledb_query_alloc(ctx, array, TILEDB_WRITE, &query);
tiledb_query_set_layout(ctx, query, TILEDB_ROW_MAJOR);
tiledb_query_set_subarray_t(ctx, query, subarray);
tiledb_query_set_data_buffer(ctx, query, "a", data, &data_size);

// NOTE: If the array has more than one attributes, you should
// set the a buffer for every attribute with tiledb_query_set_data_buffer.

// You could have set the query layout to TILEDB_COL_MAJOR, 
// and set the data vector to {1, 4, 2, 5, 3, 6}, 
// and the result would be the same

// You could have set the query layout to TILEDB_GLOBAL_ORDER, 
// and set the data vector to {INT_MIN, 1, INT_MIN, 4, 2, 3, 5, 6}, 
// and the result would be the same

// Submit query
tiledb_query_submit(ctx, query);

// Close array
tiledb_array_close(ctx, array);

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

The code snippets above create the dense fragment shown in the figure below, assuming a 2D array with domain [1, 4] x [1, 4] , 2x2 space tiling, row-major tile and cell order, and a single int32 attribute called a. Observe that you can select the layout in which you can write the cells into. If you switch to column-major or global order, make sure to organize your cells properly before writing (see figure below).

Currently, if your array consists of more than one attributes, TileDB requires you to provide values for all the attributes in each write operation.

Last updated