Ask or search…
K
Links

Fixed-length Attributes

Writing fixed-length attribute cells to an array involves populating a single buffer and serializing all values in that buffer according to the layout you are writing into (see Writing Dense Subarrays and Writing Sparse Cells). The same holds even if you defined the attribute to store any fixed number of values (>1) per cell. This is illustrated in the code block below with a sparse write, but it is applicable to dense writes as well.
C
C++
Python
R
Java
Go
C#
#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);
float a[] = {1.1f, 1.2f, 2.1f, 2.2f, 3.1f, 3.2f, 4.1f, 4.2f};
unsigned long long a_size = sizeof(a);
// 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);
// 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);
#include <tiledb/tiledb>
using namespace tiledb;
// Create context
Context ctx;
// Create Array
Domain domain(ctx);
auto d1 = Dimension::create<int64_t>(ctx, "d1", {{1, 10}}, 5);
auto d2 = Dimension::create<int64_t>(ctx, "d2", {{1, 10}}, 5);
domain.add_dimension(d1).add_dimension(d2);
auto a = Attribute::create<double>(ctx, "a");
a.set_cell_val_num(2); // two values per cell
ArraySchema schema(ctx, TILEDB_SPARSE);
schema.set_domain(domain);
schema.set_order({{TILEDB_COL_MAJOR, TILEDB_COL_MAJOR}});
schema.add_attributes(a);
Array::create(array_name, schema);
// Prepare some data for the array
std::vector<int64_t> d1 = {1, 2, 3, 4};
std::vector<int64_t> d2 = {2, 1, 3, 4};
std::vector<double> a = {1.1f, 1.2f, 2.1f, 2.2f, 3.1f, 3.2f, 4.1f, 4.2f};
// Open array for writing
Array array(ctx, array_name, TILEDB_WRITE);
// Create the query
Query query(ctx, array);
query.set_layout(TILEDB_UNORDERED)
.set_buffer("d1", d1)
.set_buffer("d2", d2)
.set_buffer("a", a);
// Submit query
query.submit();
// Close the array
array.close();
# The Python API treats homogenous NumPy record arrays
# as fixed-length cells.
d1 = np.array([1,2,3,4])
d2 = np.array([2,1,3,2])
a = np.array([(1.1,1.2),(2.1,2.2),(3.1,3.2),(4.1,4.2)], dtype='f4,f4')
with tiledb.open(array_name, 'w') as A:
A[d1, d2] = a
## Prepare some data for the array
a <- c(1.1, 1.2, 2.1, 2.2, 3.1, 3.2, 4.1, 4.2)
d1 <- c(1L, 2L, 3L, 4L)
d2 <- c(2L, 1L, 3L, 4L)
arrptr <- tiledb:::libtiledb_array_open(ctx@ptr, tmp, "WRITE")
qryptr <- tiledb:::libtiledb_query(ctx@ptr, arrptr, "WRITE")
qryptr <- tiledb:::libtiledb_query_set_layout(qryptr, "UNORDERED")
qryptr <- tiledb:::libtiledb_query_set_buffer(qryptr, "a", a)
qryptr <- tiledb:::libtiledb_query_set_buffer(qryptr, "d1", d1)
qryptr <- tiledb:::libtiledb_query_set_buffer(qryptr, "d2", d2)
qryptr <- tiledb:::libtiledb_query_submit(qryptr)
res <- tiledb:::libtiledb_array_close(arrptr)
#TODO Higher-level R support
// Create context, array and query
try(Context ctx = new Context(),
Array array = new Array(ctx, array_name, TILEDB_WRITE),
Query query = new Query(ctx, array);) {
// Prepare some data for the array
NativeArray d1 = new NativeArray(ctx, new long[] {1l, 2l, 3l, 4l}, Long.class);
NativeArray d2 = new NativeArray(ctx, new long[] {2l, 1l, 3l, 4l}, Long.class);
NativeArray a = new NativeArray(ctx, new float[] {1.1f, 1.2f, 2.1f, 2.2f, 3.1f, 3.2f, 4.1f, 4.2f}, Float.class);
// Create the query
query.setLayout(TILEDB_ROW_MAJOR)
.setBuffer("d1", d1)
.setBuffer("d2", d2)
.setBuffer("a", a);
// Submit query
query.submit();
}
import "github.com/TileDB-Inc/TileDB-Go"
// Create context
ctx, _ := tiledb.NewContext(nil)
// Prepare some data for the array
d1 := []int32{1, 2, 3, 4}
d2 := []int32{2, 1, 3, 4}
a := []float32{1.1, 1.2, 2.1, 2.2, 3.1, 3.2, 4.1, 4.2}
// Open array for writing
array, _ := tiledb.NewArray(ctx, array_name)
array.Open(tiledb.TILEDB_WRITE)
// Create the query
query, _ := 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 query
query.Submit();
// Close the array
array.Close();
using TileDB.CSharp;
// Create TileDB context
using Context ctx = new Context();
// Open array for writing
using Array array = new Array(ctx, array_name);
array.Open(QueryType.Write);
// Prepare some data for the array
long[] d1 = new long[] { 1, 2, 3, 4 };
long[] d2 = new long[] { 2, 1, 3, 4 };
float[] a = new float[] { 1.1f, 1.2f, 2.1f, 2.2f, 3.1f, 3.2f, 4.1f, 4.2f };
// Create the query
using Query query = new Query(ctx, array, QueryType.Write);
query.SetLayout(LayoutType.Unordered);
query.SetDataBuffer("d1", d1);
query.SetDataBuffer("d2", d2);
query.SetDataBuffer("a", a);
// Submit query
query.Submit();
// Close array
array.Close();
The code snippet above produces the following sparse fragment.