Array Metadata

Writing Array Metadata

You can write metadata to an array as follows.

// 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);

// Write some metadata
int v = 100;
tiledb_array_put_metadata(ctx, array, "aaa", TILEDB_INT32, 1, &v);
float f[] = {1.1f, 1.2f};
tiledb_array_put_metadata(ctx, array, "bb", TILEDB_FLOAT32, 2, f);

// Close array - Important so that the metadata get flushed
tiledb_array_close(ctx, array);

// Clean up
tiledb_array_free(&array);
tiledb_ctx_free(&ctx);

Reading Array Metadata

You can read array metadata as follows.

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

// Open array for reading
tiledb_array_t* array;
tiledb_array_alloc(ctx, array_name, &array);
tiledb_array_open(ctx, array, TILEDB_READ);

// Read with key
tiledb_datatype_t v_type;
uint32_t v_num;
const void* v;
tiledb_array_get_metadata(ctx, array, "aaa", &v_type, &v_num, &v);

// Close array
tiledb_array_close(ctx, array);
tiledb_array_free(&array);
tiledb_ctx_free(&ctx);

You can also enumerate all read array metadata as follows.

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

// Open array for reading
tiledb_array_t* array;
tiledb_array_alloc(ctx, array_name, &array);
tiledb_array_open(ctx, array, TILEDB_READ);

// Enumerate all metadata items
tiledb_datatype_t v_type;
uint32_t v_num;
const void* v;
uint64_t num = 0;
const char* key;
uint32_t key_len;
tiledb_array_get_metadata_num(ctx, array, &num);
for (uint64_t i = 0; i < num; ++i) {
  tiledb_array_get_metadata_from_index(
      ctx, array, i, &key, &key_len, &v_type, &v_num, &v);
  // ... do something with the retrieved key-value pair
}

// Close array
tiledb_array_close(ctx, array);
tiledb_array_free(&array);
tiledb_ctx_free(&ctx);

Deleting Array Metadata

You can delete array metadata as follows. The array must be opened in write mode to delete metadata.

// 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);

// Delete metadata
tiledb_array_delete_metadata(ctx, array, "bb");

// Close array - Important so that the deleted metadata get flushed
tiledb_array_close(ctx, array);

// Clean up
tiledb_array_free(&array);
tiledb_ctx_free(&ctx);

Last updated