Creating Attributes

Creating an attribute requires specifying a datatype, and optionally an attribute name (must be unique, and attribute names starting with __ are reserved). In the example below we create an int32 attribute called attr.

#include <tiledb/tiledb.h>

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

// Create attribute
tiledb_attribute_t* attr;
tiledb_attribute_alloc(ctx, "attr", TILEDB_INT32, &attr);

// ... 

// Make sure to free the attribute and context
tiledb_attribute_free(&attr);
tiledb_ctx_free(&ctx);

An attribute can also store a fixed number of values (of the same datatype) in a single cell, or a variable number of values. You can specify this as follows:

// Setting a fixed number of values
tiledb_attribute_set_cell_val_num(ctx, attr, 3);

// Setting a variable number of values
tiledb_attribute_set_cell_val_num(ctx, attr, TILEDB_VAR_NUM);

An attribute may also be nullable. This allows designating each cell as valid or null. Applicable to both fixed-sized and var-sized attributes.

// Setting a nullable attribute
tiledb_attribute_set_nullable(ctx, attr, 1);

Supported Attribute Datatypes:

Crossed data types are deprecated.

DatatypeDescription

TILEDB_BLOB

Opaque bytes. Note: the TILEDB_BLOB datatype does not support query conditions.

TILEDB_INT8

8-bit integer

TILEDB_UINT8

8-bit unsigned integer

TILEDB_INT16

16-bit integer

TILEDB_UINT16

16-bit unsigned integer

TILEDB_INT32

32-bit integer

TILEDB_UINT32

32-bit unsigned integer

TILEDB_INT64

64-bit integer

TILEDB_UINT64

64-bit unsigned integer

TILEDB_FLOAT32

32-bit floating point

TILEDB_FLOAT64

64-bit floating point

TILEDB_DATETIME_YEAR

Years

TILEDB_DATETIME_MONTH

Months

TILEDB_DATETIME_WEEK

Weeks

TILEDB_DATETIME_DAY

Days

TILEDB_DATETIME_HR

Hours

TILEDB_DATETIME_MIN

Minutes

TILEDB_DATETIME_SEC

Seconds

TILEDB_DATETIME_MS

Milliseconds

TILEDB_DATETIME_US

Microseconds

TILEDB_DATETIME_NS

Nanoseconds

TILEDB_DATETIME_PS

Picoseconds

TILEDB_DATETIME_FS

Femtoseconds

TILEDB_DATETIME_AS

Attoseconds

TILEDB_CHAR

Single character

TILEDB_STRING_ASCII

ASCII string

TILEDB_STRING_UTF8

UTF-8 string

TILEDB_STRING_UTF16

UTF-16 string

TILEDB_STRING_UTF32

UTF-32 string

TILEDB_STRING_UCS2

UCS-2 string

TILEDB_STRING_UCS4

UCS-4 string

TILEDB_ANY

(datatype, bytelength, value)

Setting Filters

Attributes accept filters such as compressors. This is described in detail here.

Setting Fill Values

There are situations where you may read "empty spaces" from TileDB arrays. For those empty spaces, a read query will return some default fill values for the selected attributes. You can set your own fill values for these cases as follows:

// Assumming a int32 attribute
int value = 0;
unsigned long long size = sizeof(value);
tiledb_attribute_set_fill_value(ctx, attr, &value, size);
 
// Assumming a var-sized attribute
const char* value = "null";
unsigned long long size = strlen(value);
tiledb_attribute_set_fill_value(ctx, attr, value, size);

A call to setting the number of cells for an attribute (see above) sets the fill value of the attribute to its default. Therefore, make sure you set the fill values after deciding on the number of values this attribute will hold in each cell.

For fixed-sized attributes, the input fill value size should be equal to the cell size.

Last updated