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 contexttiledb_ctx_t* ctx;tiledb_ctx_alloc(NULL, &ctx);​// Open array for writingtiledb_array_t* array;tiledb_array_alloc(ctx, array_name, &array);tiledb_array_open(ctx, array, TILEDB_WRITE);​// Prepare some data for the arrayint data[] = {1, 2, 3, 4, 5, 6};unsigned long long data_size = sizeof(data);​// Set the subarray to write intoint subarray[] = {1, 2, 2, 4};​// Create the querytiledb_query_t* query;tiledb_query_alloc(ctx, array, TILEDB_WRITE, &query);tiledb_query_set_layout(ctx, query, TILEDB_ROW_MAJOR);tiledb_query_set_subarray(ctx, query, subarray);tiledb_query_set_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_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 querytiledb_query_submit(ctx, query);​// Close arraytiledb_array_close(ctx, array);​// Clean uptiledb_array_free(&array);tiledb_query_free(&query);tiledb_ctx_free(&ctx);
#include <tiledb/tiledb>using namespace tiledb;​// Create contextContext ctx;​// Prepare some data for the arraystd::vector<int> data = {1, 2, 3, 4, 5, 6};​// Set the subarray to write intostd::vector<int> subarray = {1, 2, 2, 4};​// Open array for writingArray array(ctx, array_name, TILEDB_WRITE);​// Create the queryQuery query(ctx, array);query.set_layout(TILEDB_ROW_MAJOR).set_buffer("a", data).set_subarray(subarray);​// NOTE: If the array has more than one attributes, you should// set the a buffer for every attribute with set_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 queryquery.submit();// Close the arrayarray.close();
import tiledbimport numpy as np​data = np.array([[1,2],[3,4],[5,6]])​with tiledb.open(array_name, 'w') as A:A[1:3,2:5] = data
# Prepare a 4x3 dense array# Contrary to Python, R by default stores arrays in col-major orderdata <- array(c(1L, 4L, 2L, 5L, 3L, 6L), dim=c(2,3))​# Prepare the [1,2] x [2,4] subarray to write toI <- c(1:2)J <- c(2:4)​# Open the array and write the data to itA <- tiledb_array(uri = array_name)A[I, J] <- data
// Create context, array and querytry(Context ctx = new Context(),Array array = new Array(ctx, array_name, TILEDB_WRITE),Query query = new Query(ctx, array);) {​// Prepare some data for the arrayNativeArray subarray = new NativeArray(ctx, new int[] {1, 2, 2, 4}, Integer.class);NativeArray data = new NativeArray(ctx, new int[] {1, 2, 3, 4, 5, 6}, Integer.class);// Create the queryquery.setLayout(TILEDB_ROW_MAJOR).setSubarray(subarray).setBuffer("a", data);​​// NOTE: If the array has more than one attributes, you should// set the a buffer for every attribute with set_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 queryquery.submit();}
import "github.com/TileDB-Inc/TileDB-Go"​// Create contextctx, _ := tiledb.NewContext(nil)​// Prepare some data for the arraydata := []int32{1, 2, 3, 4, 5, 6}​// Set the subarray to write intosubarray := []int32{1, 2, 2, 4}​// Open array for writingarray, _ := tiledb.NewArray(ctx, array_name)_ = array.Open(tiledb.TILEDB_WRITE)​// Create the queryquery, _ := tiledb.NewQuery(ctx, array)query.SetLayout(tiledb.TILEDB_ROW_MAJOR)query.SetBuffer("a", data)query.SetSubArray(subarray)​// NOTE: If the array has more than one attributes, you should// set the a buffer for every attribute with set_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 queryquery.Submit()// Close the arrayquery.Finalize()array.Close()
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.