Array Access
For reads, writes, embedded SQL, any integration and any API, you can simply use TileDB Embedded with only two changes:
  • Set the TileDB configuration parameters rest.username and rest.passwordwith your TileDB Cloud username and password, or alternatively rest.tokenwith the API token you created.
  • Every array registered with TileDB Cloud must be accessed using a URI of the form tiledb://<namespace>/<array-name>, where<namespace> is the user or organization who owns the array and <array-name> is the array name set by the owner upon array registration. This URI is displayed on the console when viewing the array details.
Accessing arrays by setting an API token is typically faster than using your username and password.
Here are some Python/R examples, although the above changes will work with any TileDB API or integration:
Python
R
1
import tiledb, tiledb.sql
2
import pandas
3
4
# Create the configuration parameters
5
config = tiledb.Config()
6
config["rest.username"] = "xxx"
7
config["rest.password"] = "yyy"
8
# or, more preferably, config["rest.token"] = "ttt"
9
10
# This is the array URI format in TileDB Cloud
11
array_name = "tiledb://TileDB-Inc/quickstart_sparse"
12
13
# Write code exactly as in TileDB Developer
14
with tiledb.open(array_name, 'r', ctx=tiledb.Ctx(config)) as A:
15
print (A.df[:])
16
17
# A helper function tiledb.cloud.Ctx() exists to create a context
18
# automatically based on a previous call to tiledb.cloud.login()
19
with tiledb.open(array_name, 'r', ctx=tiledb.cloud.Ctx()) as A:
20
print (A.df[:])
21
22
# Using embedded SQL, you need to pass the username/password or token
23
# as config parameters in `init_command`
24
db = tiledb.sql.connect(db="test",
25
init_command="set mytile_tiledb_config='rest.username=xxx,rest.password=yyy'")
26
pandas.read_sql(sql="select * from `tiledb://TileDB-Inc/quickstart_sparse`", con=db)
Copied!
1
library(tiledb)
2
3
# Create the configuration parameters
4
config <- tiledb_config()
5
config["rest.username"] <- "xxx"
6
config["rest.password"] <- "yyy"
7
# or, more preferably, config["rest.token"] <- "ttt"
8
ctx <- tiledb_ctx(config)
9
10
# This is the array URI format in TileDB Cloud
11
array_name <- "tiledb://TileDB-Inc/quickstart_sparse"
12
13
# Write code exactly as in TileDB Developer
14
arr <- tiledb_array(array_name, query_type="READ", ctx=ctx, return_as='data.frame')
15
df <- arr[]
16
str(df)
Copied!
You can create an array inside or outside TileDB Cloud. The benefit of creating an array with TileDB Cloud is that it will be logged for auditing purposes. Moreover, it will be registered automatically with your account upon creation.

Create New Arrays

To instruct TileDB Embedded that you are creating an array through the TileDB Cloud service, you just need a single change:
  • Instead of using <array-uri> as you would typically in TileDB Embedded, you must use tiledb://<username>/<array-uri>. For example, if you wish to create an array at s3://my_bucket/my_array, you need to set the array URI to tiledb://my_username/s3://my_bucket/my_array.
Python
R
1
import tiledb
2
import numpy as np
3
4
#####################
5
# Define the Schema #
6
#####################
7
# The array will be 4x4 with dimensions "rows" and "cols", with domain [1,4].
8
dom = tiledb.Domain(
9
tiledb.Dim(name="rows", domain=(1, 4), tile=4, dtype=np.int32),
10
tiledb.Dim(name="cols", domain=(1, 4), tile=4, dtype=np.int32),
11
)
12
13
# The array will be sparse with a single attribute "a" so each (i,j) cell can store an integer.
14
schema = tiledb.ArraySchema(
15
domain=dom, sparse=True, attrs=[tiledb.Attr(name="a", dtype=np.int32)]
16
)
17
18
####################
19
# Create the Array #
20
####################
21
array_uri = "tiledb://my_username/s3://my_bucket/my_array"
22
# Create the (empty) array on disk.
23
tiledb.SparseArray.create(array_uri, schema)
Copied!
1
library(tiledb)
2
3
#####################
4
# Define the Schema #
5
#####################
6
dom <- tiledb_domain(dims = c(
7
tiledb_dim("rows", c(1L, 4L), type = "INT32"),
8
tiledb_dim("cols", c(1L, 4L), type = "INT32")
9
))
10
attrs <- c(
11
tiledb_attr("a", type = "INT32")
12
)
13
schema <- tiledb_array_schema(domain=dom, sparse=TRUE, attrs=attrs)
14
15
####################
16
# Create the Array #
17
####################
18
array_uri <- "tiledb://my_username/s3://my_bucket/my_array"
19
# Create the (empty) array on disk.
20
tiledb_array_create(array_uri, schema)
Copied!

Register Existing Array

It is possible to programmatically register an existing array.
Python
R
1
tiledb.cloud.array.register_array(
2
uri="s3://my_bucket/my_array",
3
namespace="my_organization",
4
array_name="my_array",
5
description=None, # Optional string for markdown description
6
access_credentials_name=None, # Optional access credential name. Use this to specify a credential that is not the namespace default
7
)
Copied!
1
tiledbcloud::register_array(
2
uri="s3://my_bucket/my_array",
3
namespace="my_organization",
4
array_name="my_array",
5
description="my array", # Optional string for markdown description
6
access_credentials_name="my creds" # Optional access credential name. Use this to specify a credential that is not the namespace default
7
)
Copied!
Export as PDF
Copy link