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);
// 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();
# the array must be opened in write mode
with tiledb.Array(array_name, "w") as A:
A.meta["aaa"] = 1.1
A.meta["bbb"] = 2
A.meta["ccc"] = "hello!"
# multiple values of the same type
# may be written as a tuple:
A.meta["tuple_int"] = (1,2,3,4)
# or list:
A.meta["list_float"] = (1.0,2.1,3.2,4.3)
# 'array' can be a URI, or an array opened for writing
tiledb_put_metadata(array, "aaa", 100L)
tiledb_put_metadata(array, "bb", c(1.1, 2.2))
// Create TileDB context
Context ctx = new Context();
// Open array for writing
Array array = new Array(ctx, "<array-uri>", TILEDB_WRITE);
// Write some metadata
int v = 100;
array.putMetadata("aaa", new int[]{v});
float f[] = {1.1f, 1.2f};
array.putMetadata("bb", new NativeArray(ctx, f, TILEDB_FLOAT32));
// Close array - Important so that the metadata get flushed
array.close();
// 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.
// 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())
# Read the "tuple_int" key
print(A.meta["tuple_int"]) # -> (1, 2, 3, 4)
# Read the "list_float" key
print(A.meta["list_float"]) # -> (1.0, 2.1, 3.2, 4.3)
# 'array' can be a URI, or an array opened for reading
tiledb_get_metadata(array, "aaa")
// Create TileDB context
Context ctx = new Context();
// Open array for reading
Array array = new Array(ctx, "<array-uri>", TILEDB_READ);
// Read with key
Datatype vType;
int vNum;
array.getMetadata("aaa");
// Close array
array.close();
// 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.
// 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}'")
# 'array' can be a URI, or an array opened for reading
md <- tiledb_get_all_metadata(array)
# prints all keys and (formatted) values
print(md)
// Create TileDB context
Context ctx = new Context();
// Open array for reading
Array array = new Array(ctx, "<array-uri>", TILEDB_READ);
// Enumerate all metadata items
Datatype v_type;
int v_num;
int num = array.getMetadataNum().intValue();
for (int i = 0; i < num; ++i) {
array.getMetadataFromIndex(i);
// ... do something with the retrieved key-value pair
}
// Close array
array.close();
// 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.
// 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"]
# 'array' can be a URI, or an array opened for writing
tiledb_delete_metadata(array, "aaa")
// Create TileDB context
Context ctx = new Context();
Array array = new Array(ctx, "<array-uri>", TILEDB_READ);
// Delete metadata
array.deleteMetadata("bb");
// Close array
array.close();
// 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()
Last updated