This is applicable to sparse arrays(see Sparse Writes for more details). You can write sparse cells in an array 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 arraylonglong d1[]= {3,4,1,2};unsignedlonglong d1_size =sizeof(d1);longlong d2[]= {3,4,2,1};unsignedlonglong d2_size =sizeof(d2);int a[]= {3,4,1,2};unsignedlonglong a_size =sizeof(a);// Create the querytiledb_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);// 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>usingnamespace tiledb;// Create contextContext ctx;// Prepare some data for the arraystd::vector<int64_t> d1 = {3,4,1,2};std::vector<int64_t> d2 = {3,4,2,1};std::vector<int> a = {3,4,1,2};// Open array for writingArrayarray(ctx,array_name,TILEDB_WRITE);// Create the queryQueryquery(ctx,array);query.set_layout(TILEDB_UNORDERED) .set_data_buffer("d1", d1) .set_data_buffer("d2", d2) .set_data_buffer("a", a);// Submit queryquery.submit();// Close the array array.close();
import tiledbimport numpy as npd1 = np.array([3,4,1,2])d2 = np.array([3,4,2,1])a = np.array([3,4,1,2])with tiledb.open(array_name, 'w')as A: A[d1, d2]= a
# Prepare some dataa <-c(3L, 4L, 1L, 2L)d1 <-c(3, 4, 1, 2)d2 <-c(3, 4, 2, 1)# Open the array and write the data to itA <-tiledb_array(uri = array_name, is.sparse =TRUE)A[d1, d2] <- a
// Create context, array and querytry(Context ctx =newContext(),Array array =newArray(ctx, array_name, TILEDB_WRITE),Query query =newQuery(ctx, array);) {// Prepare some data for the arrayNativeArray d1 =newNativeArray(ctx,newlong[] {3l,4l,1l,2l},Long.class);NativeArray d2 =newNativeArray(ctx,newlong[] {3l,4l,2l,1l},Long.class);NativeArray a =newNativeArray(ctx,newint[] {3,4,1,2},Integer.class);// Create the queryquery.setLayout(TILEDB_ROW_MAJOR).setBuffer("d1", d1).setBuffer("d2", d2).setBuffer("a", a);// Submit queryquery.submit();}
import tiledb "github.com/TileDB-Inc/TileDB-Go"// Create contextContext ctx;// Prepare some data for the arrayd1 := []int64{3, 4, 1, 2}d2 := []int64{3, 4, 2, 1}a := []int32{3, 4, 1, 2}// 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_UNORDERED)_, err = query.SetBuffer("d1", d1)_, err = query.SetBuffer("d2", d2)_, err = query.SetBuffer("a", a)// Submit queryquery.Submit()// Close the array array.Close();
usingTileDB.CSharp;// Create TileDB contextusingContextctx=newContext();// Open array for writingusingArrayarray=newArray(ctx, array_name);array.Open(QueryType.Write);// Prepare some data for the arraylong[] d1 =newlong[] { 3,1,4,2 };long[] d2 =newlong[] { 3,4,2,1 };int[] a =newint[] { 3,4,1,2 };// Create the queryusingQueryquery=newQuery(ctx, array, QueryType.Write);query.SetLayout(LayoutType.Unordered);query.SetDataBuffer("d1", d1);query.SetDataBuffer("d2", d2);query.SetDataBuffer("a", a);// Submit queryquery.Submit();// Close arrayarray.Close();
The code snippets above write the sparse cells shown in the figure below, assuming a 2D array with a int64 domain [1, 4] x [1, 4] , 2x2 space tiling, row-major tile and cell order, and a single int32 attribute called a. The unordered layout means that you do no have to worry about the order of the values when writing them. Since you must explicitly set the coordinates, TileDB knows how to properly sort on the global order before writing them cells to persistent storage. If you switch to 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.