Array Metadata

Writing Array Metadata

You can write metadata to an array as follows.
C
C++
Python
R
Java
Go
1
// Create TileDB context
2
tiledb_ctx_t* ctx;
3
tiledb_ctx_alloc(NULL, &ctx);
4
5
// Open array for writing
6
tiledb_array_t* array;
7
tiledb_array_alloc(ctx, array_name, &array);
8
tiledb_array_open(ctx, array, TILEDB_WRITE);
9
10
// Write some metadata
11
int v = 100;
12
tiledb_array_put_metadata(ctx, array, "aaa", TILEDB_INT32, 1, &v);
13
float f[] = {1.1f, 1.2f};
14
tiledb_array_put_metadata(ctx, array, "bb", TILEDB_FLOAT32, 2, f);
15
16
// Close array - Important so that the metadata get flushed
17
tiledb_array_close(ctx, array);
18
19
// Clean up
20
tiledb_array_free(&array);
21
tiledb_ctx_free(&ctx);
Copied!
1
// Create TileDB context
2
Context ctx;
3
4
// Open array for writing
5
Array array(ctx, array_name, TILEDB_WRITE);
6
7
// Write some metadata
8
int v = 100;
9
array.put_metadata("aaa", TILEDB_INT32, 1, &v);
10
float f[] = {1.1f, 1.2f};
11
array.put_metadata("bb", TILEDB_FLOAT32, 2, f);
12
13
// Close array - Important so that the metadata get flushed
14
array.close();
Copied!
1
# the array must be opened in write mode
2
with tiledb.Array(array_name, "w") as A:
3
A.meta["aaa"] = 1.1
4
A.meta["bbb"] = 2
5
A.meta["ccc"] = "hello!"
6
# multiple values of the same type
7
# may be written as a tuple:
8
A.meta["tuple_int"] = (1,2,3,4)
9
# or list:
10
A.meta["list_float"] = (1.0,2.1,3.2,4.3)
Copied!
1
# 'array' can be a URI, or an array opened for writing
2
tiledb_put_metadata(array, "aaa", 100L)
3
tiledb_put_metadata(array, "bb", c(1.1, 2.2))
Copied!
1
// Create TileDB context
2
Context ctx = new Context();
3
4
// Open array for writing
5
Array array = new Array(ctx, "<array-uri>", TILEDB_WRITE);
6
7
// Write some metadata
8
int v = 100;
9
array.putMetadata("aaa", new int[]{v});
10
float f[] = {1.1f, 1.2f};
11
array.putMetadata("bb", new NativeArray(ctx, f, TILEDB_FLOAT32));
12
13
// Close array - Important so that the metadata get flushed
14
array.close();
Copied!
1
// Create TileDB context
2
ctx, _ := tiledb.NewContext(nil)
3
4
// Open array for writing
5
array, _ := tiledb.NewArray(ctx, array_name)
6
array.Open(tiledb.TILEDB_WRITE)
7
8
// Write some metadata
9
err = array.PutMetadata("aaa", int32(100))
10
err = array.PutMetadata("bb", []float32{1.1, 1.2})
11
12
// Close array - Important so that the metadata get flushed
13
array.Close()
14
15
// Clean up
16
array.Free()
17
ctx.Free()
Copied!

Reading Array Metadata

You can read array metadata as follows.
C
C++
Python
R
Java
Go
1
// Create TileDB context
2
tiledb_ctx_t* ctx;
3
tiledb_ctx_alloc(NULL, &ctx);
4
5
// Open array for reading
6
tiledb_array_t* array;
7
tiledb_array_alloc(ctx, array_name, &array);
8
tiledb_array_open(ctx, array, TILEDB_READ);
9
10
// Read with key
11
tiledb_datatype_t v_type;
12
uint32_t v_num;
13
const void* v;
14
tiledb_array_get_metadata(ctx, array, "aaa", &v_type, &v_num, &v);
15
16
// Close array
17
tiledb_array_close(ctx, array);
18
tiledb_array_free(&array);
19
tiledb_ctx_free(&ctx);
Copied!
1
// Create TileDB context
2
Context ctx;
3
4
// Open array for reading
5
Array array(ctx, array_name, TILEDB_READ);
6
7
// Read with key
8
tiledb_datatype_t v_type;
9
uint32_t v_num;
10
const void* v;
11
array.get_metadata("aaa", &v_type, &v_num, &v);
12
13
// Close array
14
array.close();
Copied!
1
# Open array for reading
2
with tiledb.Array(array_name) as A:
3
# Read "aaa" key
4
aaa = A.meta["aaa"]
5
6
# print all keys:
7
print(A.meta.keys())
8
9
# Read the "tuple_int" key
10
print(A.meta["tuple_int"]) # -> (1, 2, 3, 4)
11
# Read the "list_float" key
12
print(A.meta["list_float"]) # -> (1.0, 2.1, 3.2, 4.3)
Copied!
1
# 'array' can be a URI, or an array opened for reading
2
tiledb_get_metadata(array, "aaa")
Copied!
1
// Create TileDB context
2
Context ctx = new Context();
3
4
// Open array for reading
5
Array array = new Array(ctx, "<array-uri>", TILEDB_READ);
6
7
// Read with key
8
Datatype vType;
9
int vNum;
10
array.getMetadata("aaa");
11
12
// Close array
13
array.close();
Copied!
1
// Create TileDB context
2
ctx, _ := tiledb.NewContext(nil)
3
4
// Open array for reading
5
array, _ := tiledb.NewArray(ctx, array_name)
6
array.Open(tiledb.TILEDB_READ)
7
8
// Read with key
9
var dataType tiledb.Datatype
10
var valueNum uint32
11
var value interface{}
12
dataType, valueNum, value, _ = array.GetMetadata("aaa")
13
14
// Close array
15
array.Close()
16
array.Free()
17
ctx.Free()
Copied!
You can also enumerate all read array metadata as follows.
C
C++
Python
R
Java
Go
1
// Create TileDB context
2
tiledb_ctx_t* ctx;
3
tiledb_ctx_alloc(NULL, &ctx);
4
5
// Open array for reading
6
tiledb_array_t* array;
7
tiledb_array_alloc(ctx, array_name, &array);
8
tiledb_array_open(ctx, array, TILEDB_READ);
9
10
// Enumerate all metadata items
11
tiledb_datatype_t v_type;
12
uint32_t v_num;
13
const void* v;
14
uint64_t num = 0;
15
const char* key;
16
uint32_t key_len;
17
tiledb_array_get_metadata_num(ctx, array, &num);
18
for (uint64_t i = 0; i < num; ++i) {
19
tiledb_array_get_metadata_from_index(
20
ctx, array, i, &key, &key_len, &v_type, &v_num, &v);
21
// ... do something with the retrieved key-value pair
22
}
23
24
// Close array
25
tiledb_array_close(ctx, array);
26
tiledb_array_free(&array);
27
tiledb_ctx_free(&ctx);
Copied!
1
// Create TileDB context
2
Context ctx;
3
4
// Open array for reading
5
Array array(ctx, array_name, TILEDB_READ);
6
7
// Enumerate all metadata items
8
tiledb_datatype_t v_type;
9
uint32_t v_num;
10
const void* v;
11
std::string key;
12
uint64_t num = array.metadata_num();
13
for (uint64_t i = 0; i < num; ++i) {
14
array.get_metadata_from_index(i, &key, &v_type, &v_num, &v);
15
// ... do something with the retrieved key-value pair
16
}
17
18
// Close array
19
array.close();
Copied!
1
# Open the array for reading
2
with tiledb.Array(array_name) as A:
3
# print the keys
4
print(A.meta.keys())
5
6
# iterate over all key-value pairs:
7
for (key,value) in A.meta.items():
8
print(f"found '{key}':'{value}'")
Copied!
1
# 'array' can be a URI, or an array opened for reading
2
md <- tiledb_get_all_metadata(array)
3
4
# prints all keys and (formatted) values
5
print(md)
Copied!
1
// Create TileDB context
2
Context ctx = new Context();
3
4
// Open array for reading
5
Array array = new Array(ctx, "<array-uri>", TILEDB_READ);
6
7
// Enumerate all metadata items
8
Datatype v_type;
9
int v_num;
10
int num = array.getMetadataNum().intValue();
11
for (int i = 0; i < num; ++i) {
12
array.getMetadataFromIndex(i);
13
// ... do something with the retrieved key-value pair
14
}
15
16
// Close array
17
array.close();
Copied!
1
// Create TileDB context
2
ctx, _ := tiledb.NewContext(nil)
3
4
// Open array for reading
5
array, _ := tiledb.NewArray(ctx, array_name)
6
array.Open(tiledb.TILEDB_READ)
7
8
// type ArrayMetadata struct {
9
// Key string
10
// KeyLen uint32
11
// Datatype Datatype
12
// ValueNum uint
13
// Value interface{}
14
// }
15
16
// Enumerate all metadata items
17
num, _ := array.GetMetadataNum()
18
var i uint64
19
for i = 0; i < num; i++ {
20
var arrayMetadata ArrayMetadata
21
arrayMetadata, _ := array.GetMetadataFromIndex(i)
22
// ... do something with the retrieved ArrayMetadata
23
}
24
25
// Close array
26
array.Close()
27
array.Free()
28
ctx.Free()
Copied!

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
1
// Create TileDB context
2
tiledb_ctx_t* ctx;
3
tiledb_ctx_alloc(NULL, &ctx);
4
5
// Open array for writing
6
tiledb_array_t* array;
7
tiledb_array_alloc(ctx, array_name, &array);
8
tiledb_array_open(ctx, array, TILEDB_WRITE);
9
10
// Delete metadata
11
tiledb_array_delete_metadata(ctx, array, "bb");
12
13
// Close array - Important so that the deleted metadata get flushed
14
tiledb_array_close(ctx, array);
15
16
// Clean up
17
tiledb_array_free(&array);
18
tiledb_ctx_free(&ctx);
Copied!
1
// Open array in write mode
2
Context ctx;
3
Array array(ctx, "my_array", TILEDB_WRITE);
4
5
// Delete metadata
6
array.delete_metadata("bb");
7
8
// Close array - Important so that the deleted metadata get flushed
9
array.close()
Copied!
1
with tiledb.Array(array_name) as A:
2
del A.meta["bb"]
Copied!
1
# 'array' can be a URI, or an array opened for writing
2
tiledb_delete_metadata(array, "aaa")
Copied!
1
// Create TileDB context
2
Context ctx = new Context();
3
Array array = new Array(ctx, "<array-uri>", TILEDB_READ);
4
5
// Delete metadata
6
array.deleteMetadata("bb");
7
8
// Close array
9
array.close();
Copied!
1
// Create TileDB context
2
ctx, _ := tiledb.NewContext(nil)
3
4
// Open array for writing
5
array, _ := tiledb.NewArray(ctx, array_name)
6
array.Open(tiledb.TILEDB_WRITE)
7
8
// Delete metadata
9
array.DeleteMetadata("bb")
10
11
// Close array - Important so that the deleted metadata get flushed
12
array.Close()
13
14
// Clean up
15
array.Free()
16
ctx.Free()
Copied!
Last modified 1yr ago