Array Metadata

Writing Array Metadata

You can write metadata to an array as follows.

C
C++
Python
R
Java
Go
// 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);
// Create TileDB context
Context ctx;
// Open array for writing
Array array(ctx, array_name, TILEDB_WRITE);
// Write some metadata
int v = 100;
array.put_metadata("aaa", TILEDB_INT32, 1, &v);
float f[] = {1.1f, 1.2f};
array.put_metadata("bb", TILEDB_FLOAT32, 2, f);
// Close array - Important so that the metadata get flushed
array.close();
with tiledb.Array(array_name) as A:
A.meta["aaa"] = 1.1
A.meta["bbb"] = 2
A.meta["ccc"] = "hello!"
# TODO: Array metadata is not currently supported in R
// TODO: Array metadata is not currently supported in Java
// Create TileDB context
ctx, _ := tiledb.NewContext(nil)
// Open array for writing
array, _ := tiledb.NewArray(ctx, array_name)
array.Open(tiledb.TILEDB_WRITE)
// Write some metadata
err = array.PutMetadata("aaa", int32(100))
err = array.PutMetadata("bb", []float32{1.1, 1.2})
// Close array - Important so that the metadata get flushed
array.Close()
// Clean up
array.Free()
ctx.Free()

Reading Array Metadata

You can read array metadata as follows.

C
C++
Python
R
Java
Go
// 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);
// Create TileDB context
Context ctx;
// Open array for reading
Array array(ctx, array_name, TILEDB_READ);
// Read with key
tiledb_datatype_t v_type;
uint32_t v_num;
const void* v;
array.get_metadata("aaa", &v_type, &v_num, &v);
// Close array
array.close();
# Open array for reading
with tiledb.Array(array_name) as A:
# Read "aaa" key
aaa = A.meta["aaa"]
# print all keys:
print(A.meta.keys())
# TODO: Array metadata is not currently supported in R
// TODO: Array metadata is not currently supported in Java
// Create TileDB context
ctx, _ := tiledb.NewContext(nil)
// Open array for reading
array, _ := tiledb.NewArray(ctx, array_name)
array.Open(tiledb.TILEDB_READ)
// Read with key
var dataType tiledb.Datatype
var valueNum uint32
var value interface{}
dataType, valueNum, value, _ = array.GetMetadata("aaa")
// Close array
array.Close()
array.Free()
ctx.Free()

You can also enumerate all read array metadata as follows.

C
C++
Python
R
Java
Go
// 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);
// Create TileDB context
Context ctx;
// Open array for reading
Array array(ctx, array_name, TILEDB_READ);
// Enumerate all metadata items
tiledb_datatype_t v_type;
uint32_t v_num;
const void* v;
std::string key;
uint64_t num = array.metadata_num();
for (uint64_t i = 0; i < num; ++i) {
array.get_metadata_from_index(i, &key, &v_type, &v_num, &v);
// ... do something with the retrieved key-value pair
}
// Close array
array.close();
# Open the array for reading
with tiledb.Array(array_name) as A:
# print the keys
print(A.meta.keys())
# iterate over all key-value pairs:
for (key,value) in A.meta.items():
print(f"found '{key}':'{value}'")
# TODO: Array metadata is not currently supported in R
// TODO: Array metadata is not currently supported in Java
// Create TileDB context
ctx, _ := tiledb.NewContext(nil)
// Open array for reading
array, _ := tiledb.NewArray(ctx, array_name)
array.Open(tiledb.TILEDB_READ)
// type ArrayMetadata struct {
// Key string
// KeyLen uint32
// Datatype Datatype
// ValueNum uint
// Value interface{}
// }
// Enumerate all metadata items
num, _ := array.GetMetadataNum()
var i uint64
for i = 0; i < num; i++ {
var arrayMetadata ArrayMetadata
arrayMetadata, _ := array.GetMetadataFromIndex(i)
// ... do something with the retrieved ArrayMetadata
}
// Close array
array.Close()
array.Free()
ctx.Free()

Deleting Array Metadata

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

C
C++
Python
R
Java
Go
// 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);
// Open array in write mode
Context ctx;
Array array(ctx, "my_array", TILEDB_WRITE);
// Delete metadata
array.delete_metadata("bb");
// Close array - Important so that the deleted metadata get flushed
array.close()
with tiledb.Array(array_name) as A:
del A.meta["bb"]
# TODO: Array metadata is not currently supported in R
// TODO: Array metadata is not currently supported in Java
// Create TileDB context
ctx, _ := tiledb.NewContext(nil)
// Open array for writing
array, _ := tiledb.NewArray(ctx, array_name)
array.Open(tiledb.TILEDB_WRITE)
// Delete metadata
array.DeleteMetadata("bb")
// Close array - Important so that the deleted metadata get flushed
array.Close()
// Clean up
array.Free()
ctx.Free()