Learn how to manage your array and group objects, including adding, modifying, and removing objects.
How to run this tutorial
You can run this tutorial in two ways:
Locally on your machine.
On TileDB Cloud.
However, since TileDB Cloud has a free tier, we strongly recommend that you sign up and run everything there, as that requires no installations or deployment.
This tutorial explains functionality around managing TileDB objects, mainly groups and arrays.
First, import the necessary libraries, set group and array URIs (that is, their paths, which in this tutorial will be on local storage), and delete any previously created groups and arrays with the same name.
# Create the two dimensionsd1 = tiledb.Dim(name="d1", domain=(1, 4), tile=2, dtype=np.int32)d2 = tiledb.Dim(name="d2", domain=(1, 4), tile=2, dtype=np.int32)# Create a domain using the two dimensionsdom = tiledb.Domain(d1, d2)# Order of the dimensions matters when slicing subarrays.# Remember to give priority to more selective dimensions to# maximize the pruning power during slicing.# Create an attributea = tiledb.Attr(name="a", dtype=np.int32)# Create the array schema, setting `sparse=False` to indicate a dense arraysch = tiledb.ArraySchema(domain=dom, sparse=False, attrs=[a])# Create the array on disk (it will initially be empty)tiledb.Array.create(array_uri, sch)
# Create the two dimensionsd1 <-tiledb_dim("d1", c(1L, 4L), 2L, "INT32")d2 <-tiledb_dim("d2", c(1L, 4L), 2L, "INT32")# Create a domain using the two dimensionsdom <-tiledb_domain(dims =c(d1, d2))# Create an attributea <-tiledb_attr("a", type ="INT32")# Create the array schema, setting `sparse = FALSE` to indicate a dense arraysch <-tiledb_array_schema(dom, a, sparse =FALSE)# Create the array on disk (it will initially be empty)arr <-tiledb_array_create(array_uri, sch)
Create an object hierarchy, which sets the foundation for the rest of the examples.
# The group hierarchy looks as follows# NOTE: Removing the physical path of an object does not# automatically remove it from the group memberswith tiledb.Group(grp_root_uri, "r") as grp_root:print(grp_root)
object_mgmt_grp_root GROUP
|-- grp1 GROUP (does not exist)
|-- grp2 GROUP
# The group hierarchy looks as follows# NOTE: Removing the physical path of an object does not# automatically remove it from the group memberswriteLines(tiledb_group_member_dump(grp_root, recursive =TRUE))
object_mgmt_grp_root_r GROUP
|-- grp1 GROUP (does not exist)
|-- grp2 GROUP
Warning
Deleting the physical storage path of an object doesn’t automatically delete any member created for this storage path in another group.
To mitigate this issue, you need to manually remove the corresponding member from the group.
# Manually remove the deleted member from the groupwith tiledb.Group(grp_root_uri, "w") as grp_root: grp_root.remove(grp1_name)
# Manually remove the deleted member from the groupgrp_root <-tiledb_group_close(grp_root)grp_root <-tiledb_group_open(grp_root, "WRITE")tiledb_group_remove_member(grp_root, grp1_uri)grp_root <-tiledb_group_close(grp_root)
After the preceding operation, the group hierarchy looks clean.
# Now the group contains only valid memberswith tiledb.Group(grp_root_uri, "r") as grp_root:print(grp_root)
object_mgmt_grp_root GROUP
|-- grp2 GROUP
grp_root <-tiledb_group_open(grp_root, "READ")# Now the group contains only valid memberswriteLines(tiledb_group_member_dump(grp_root, recursive =TRUE))# Close the groupgrp_root <-tiledb_group_close(grp_root)