The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.
This document follows the TileDB API usage examples. A shorter introductory vignette is also available.
We will show two initial and basic examples for a dense and sparse array simply to create array data on disk to refer to later in examples that follow.
library(tiledb)
<- tempdir()
tdir <- file.path(tdir, "dense")
uridense <- file.path(tdir, "densefix")
uridensefix <- file.path(tdir, "densevar")
uridensevar <- file.path(tdir, "denseenc")
uridensewkey
<- function(array_name) {
create_array # Check if the array already exists.
if (tiledb_object_type(array_name) == "ARRAY") {
message("Array already exists.")
return(invisible(NULL))
}
# The array will be 4x4 with dimensions "rows" and "cols", with domain [1,4].
<- tiledb_domain(dims = c(tiledb_dim("rows", c(1L, 4L), 4L, "INT32"),
dom tiledb_dim("cols", c(1L, 4L), 4L, "INT32")))
# The array will be dense with a single attribute "a" so each (i,j) cell can store an integer.
<- tiledb_array_schema(dom, attrs = tiledb_attr("a", type = "INT32"))
schema
# Create the (empty) array on disk, and return the path invisibly
invisible(tiledb_array_create(array_name, schema))
}
<- function(array_name) {
write_array <- array(c(c(1L, 5L, 9L, 13L),
data c(2L, 6L, 10L, 14L),
c(3L, 7L, 11L, 15L),
c(4L, 8L, 12L, 16L)), dim = c(4,4))
# Open the array and write to it.
<- tiledb_array(uri = array_name)
A <- data
A[]
}
create_array(uridense)
write_array(uridense)
<- file.path(tdir, "sparse")
urisparse
<- function(array_name) {
create_array # Check if the array already exists.
if (tiledb_object_type(array_name) == "ARRAY") {
message("Array already exists.")
return(invisible(NULL))
}
# The array will be 4x4 with dimensions "rows" and "cols", with domain [1,4].
<- tiledb_domain(dims = c(tiledb_dim("rows", c(1L, 4L), 4L, "INT32"),
dom tiledb_dim("cols", c(1L, 4L), 4L, "INT32")))
# The array will be dense with a single attribute "a" so each (i,j) cell can store an integer.
= tiledb_array_schema(dom, attrs=tiledb_attr("a", type = "INT32"), sparse = TRUE)
schema
# Create the (empty) array on disk, and return the path invisibly.
invisible(tiledb_array_create(array_name, schema))
}
<- function(array_name) {
write_array <- c(1, 2, 2)
I <- c(1, 4, 3)
J <- c(1L, 2L, 3L)
data # Open the array and write to it.
<- tiledb_array(uri = array_name)
A <- data
A[I, J]
}
create_array(urisparse)
write_array(urisparse)
<- function(arr, txt) {
close_and_reopen <- tiledb:::libtiledb_array_close(arr@ptr)
res <- tiledb:::libtiledb_array_open_with_ptr(arr@ptr, txt)
res }
library(tiledb)
# Create dimension
<- tiledb_dim("dim1", c(1L, 4L), 2L, "INT32")
dim
# String dimenions: no values for domain and extent
<- tiledb_dim("dim2", NULL, NULL, "ASCII") strdim
library(tiledb)
# .. create dimensions `dim1`, `dim2`
<- tiledb_dim("dim1", c(1L, 4L), 2L, "INT32")
dim1 <- tiledb_dim("dim2", c(1L, 2L), 2L, "INT32")
dim2
# Create domain with two dimensions
# In C++: domain.add_dimensions(dim1).add_dimension(dim2)
<- tiledb_domain(dims = c(dim1, dim2)) dom
# Create attribute
<- tiledb_attr("attr", type = "INT32")
attr
# Create attribute
<- tiledb_attr("a1", type = "INT32")
attr
# Access cell value via generic or functions
cell_val_num(attr)
tiledb_attribute_get_cell_val_num(attr)
## Attribute value counts can be set via a generic method and a direct method
cell_val_num(attr) <- 3
tiledb_attribute_set_cell_val_num(attr, 3)
## set char attribute to variable length which is encoded as a NA
cell_val_num(attr) <- NA
tiledb_attribute_set_cell_val_num(attr, NA)
# ... create int attribute attr
<- tiledb_attr("a1", type = "INT32")
attr # set fill value to 42L
tiledb_attribute_set_fill_value(attr, 42L)
# ... create variable-sized attributte attr
<- tiledb_attr("attr", type = "CHAR")
attr tiledb_attribute_set_cell_val_num(attr, 3)
# set fill value to "..."
tiledb_attribute_set_fill_value(attr, "...")
<- tiledb_filter("GZIP")
comp tiledb_filter_set_option(comp,"COMPRESSION_LEVEL", 10)
# Create a filter list with the compressor
<- tiledb_filter_list(comp)
filter_list
# Create attribute with the filter list
<- tiledb_attr("attr", "INT32", filter_list = filter_list) attr
# Create filters
<- tiledb_filter("BIT_WIDTH_REDUCTION")
f1 <- tiledb_filter("ZSTD")
f2
# Create a filter list with the two filters
<- tiledb_filter_list(c(f1,f2))
filter_list
# Create attribute with the filter list
<- tiledb_attr("attr", "INT32", filter_list = filter_list) attr
# ... create domain dom
<- tiledb_attr("attr1", "INT32", filter_list = filter_list)
attr1 <- tiledb_attr("attr2", "FLOAT64", filter_list = filter_list)
attr2
# Create a dense array
<- tiledb_array_schema(dom, c(attr1, attr2), sparse = FALSE)
schema # Or, create a sparse array
# schema <- tiledb_array_schema(dom, c(attr1, attr2), sparse = TRUE)
# ... create domain dom
# ... create attributes attr1, attr2
# The tile and order can be "COL_MAJOR" or "ROW_MAJOR"
<- tiledb_array_schema(dom, c(attr1, attr2),
schema cell_order = "COL_MAJOR",
tile_order = "COL_MAJOR")
# set capacity
capacity(schema) <- 100000
tiledb_array_schema_set_capacity(schema, 10000)
# get capacity
capacity(schema)
tiledb_array_schema_get_capacity(schema)
<- schema(urisparse)
sch
# get 'duplicates allowed?' status
allows_dups(sch)
tiledb_array_schema_get_allows_dups(sch)
# set 'duplicates allowed?' status
allows_dups(sch) <- TRUE
tiledb_array_schema_set_allows_dups(sch, TRUE)
check(sch)
tiledb_array_schema_check(sch)
# create a "GZIP" compression filter
<- tiledb_filter("GZIP")
flt # set the option 'COMPRESSION_LEVEL' to 10
tiledb_filter_set_option(flt, "COMPRESSION_LEVEL", 10)
# create a filter list with this filter
<- tiledb_filter_list(flt) fltlst
# create a filter list object with both
<- tiledb_filter_list(c(flt1, flt2)) fltlst
# ... create filter list
set_max_chunk_size(filter_list, 10000)
tiledb_filter_list_set_max_chunk_size(filter_list, 10000)
max_chunk_size(filter_list)
tiledb_filter_list_get_max_chunk_size(filter_list)
# create (or access) an attribute
<- tiledb_attr("a", "INT32")
attr
# create a filter list
<- tiledb_filter("BIT_WIDTH_REDUCTION")
flt1 <- tiledb_filter("ZSTD")
flt2 <- tiledb_filter_list(c(flt1, flt2))
fltlst
# set the filter list
filter_list(attr) <- fltlst
<- tiledb_dim("d", c(1L, 10L), 1L, "INT32")
d
# create a filter list
<- tiledb_filter("BIT_WIDTH_REDUCTION")
flt1 <- tiledb_filter("ZSTD")
flt2 <- tiledb_filter_list(c(flt1, flt2))
fltlst
# assign the filter list
filter_list(d) <- fltlst
# ... create (or retrieve) array schema sch
# ... create filter list fl
# assign filter list to schema
tiledb_array_schema_set_coords_filter_list(sch, fl)
# Alternatively create the schema and set the coordinates filter list
<- tiledb_array_schema(dom, c(attr1, attr2), coords_filter_list = fl) sch
# ... create (or retrieve) array schema sch
# ... create filter list fl
# assign filter list to schema
tiledb_array_schema_set_offsets_filter_list(sch, fl)
# Create the schema setting the offsets filter list
<- tiledb_array_schema(dom, c(attr1, attr2), offsets_filter_list = fl) sch
# ... create domain dom
# ... create attributes attr1, attr2
# ... create filter lists fl1, fl2, similar to attributes
<- tiledb_filter("BIT_WIDTH_REDUCTION")
f1 <- tiledb_filter("ZSTD")
f2 <- tiledb_filter_list(c(f1))
fl1 <- tiledb_filter_list(c(f2))
fl2
# Create the schema setting the coordinates and offsets filter lists
<- tiledb_array_schema(dom, c(attr1, attr2),
schema coords_filter_list = fl1,
offsets_filter_list = fl2)
# ... create array schema
# Create the array
tiledb_array_create(uridense, schema)
# assume previously created schema 'sch'
# use encryption key
<- "0123456789abcdeF0123456789abcdeF"
encryption_key
# create encrypted array at 'uri' with schema 'sch'
tiledb_array_create(uridensewkey, sch, encryption_key)
## prepare a larger 5 x 5 to embed into
<- tempfile()
tmp <- tiledb_dim("d1", domain = c(1L, 5L))
d1 <- tiledb_dim("d2", domain = c(1L, 5L))
d2 <- tiledb_domain(c(d1, d2))
dom <- tiledb_attr(name="val", type = "INT32")
val <- tiledb_array_schema(dom, c(val))
sch tiledb_array_create(tmp, sch)
<- matrix(as.integer(rnorm(25)*100), 5, 5)
dat <- tiledb_array(tmp, return_as = "data.frame")
arr <- dat
arr[]
# Prepare a 2x3 dense array
# Contrary to Python, R by default stores arrays in col-major order
<- array(c(1L, 4L, 2L, 5L, 3L, 6L), dim=c(2,3))
data
# Prepare the [1,2] x [2,4] subarray to write to
<- c(1:2)
I <- c(2:4)
J
# Open the array and write the data to it
<- tiledb_dense(uri = tmp)
A <- data
A[I, J]
unlink(tmp, recursive=TRUE)
<- tiledb_ctx()
ctx <- tiledb:::libtiledb_array_open(ctx@ptr, uridense, "WRITE")
arrptr
## data: simple (integer sequence) of 1:16 times 10
<- 1:16 * 10L
vec <- c(1L,4L, 1L,4L)
subarr
<- tiledb:::libtiledb_query(ctx@ptr, arrptr, "WRITE")
qryptr <- tiledb:::libtiledb_query_set_subarray(qryptr, subarr)
qryptr <- tiledb:::libtiledb_query_set_layout(qryptr, "COL_MAJOR")
qryptr <- tiledb:::libtiledb_query_set_buffer(qryptr, "a", vec)
qryptr <- tiledb:::libtiledb_query_submit(qryptr)
qryptr <- tiledb:::libtiledb_array_close(arrptr) res
<- urisparse
tmp unlink(tmp, recursive=TRUE)
<- tiledb_dim("d1", domain = c(1L, 5L))
d1 <- tiledb_dim("d2", domain = c(1L, 5L))
d2 <- tiledb_domain(c(d1, d2))
dom <- tiledb_attr("val", type = "INT32")
val <- tiledb_array_schema(dom, val, sparse=TRUE)
sch tiledb_array_create(tmp, sch)
# Prepare some data
<- c(3L, 4L, 1L, 2L)
data
<- c(3, 4, 1, 2)
I <- c(3, 4, 2, 1)
J
# Open the array and write the data to it
<- tiledb_array(uri = tmp)
A <- data A[I, J]
# open for writing with corresponding encryption key
<- tiledb_array(uridensewkey, encryption_key = encryption_key)
A # access array as usual
if (dir.exists(uridensefix)) unlink(uridensefix, recursive=TRUE)
<- tiledb_dim("d1", domain = c(1L, 4L))
d1 <- tiledb_dim("d2", domain = c(1L, 4L))
d2 <- tiledb_domain(c(d1, d2))
dom
<- 1:32 * 10L
vec <- tiledb_attr("a", type = r_to_tiledb_type(vec))
attr
## set to two values per cell
:::libtiledb_attribute_set_cell_val_num(attr@ptr, 2)
tiledb<- tiledb_array_schema(dom, attr)
sch tiledb_array_create(uridensefix, sch)
<- tiledb_ctx()
ctx <- tiledb:::libtiledb_array_open(ctx@ptr, uridensefix, "WRITE")
arrptr <- c(1L,4L, 1L,4L)
subarr
<- tiledb:::libtiledb_query(ctx@ptr, arrptr, "WRITE")
qryptr <- tiledb:::libtiledb_query_set_subarray(qryptr, subarr)
qryptr <- tiledb:::libtiledb_query_set_layout(qryptr, "COL_MAJOR")
qryptr <- tiledb:::libtiledb_query_set_buffer(qryptr, "a", vec)
qryptr <- tiledb:::libtiledb_query_submit(qryptr)
qryptr <- tiledb:::libtiledb_array_close(arrptr)
res
#TODO Higher-level R support
if (dir.exists(uridensevar)) unlink(uridensevar, recursive=TRUE)
## Define array
## The array will be 4x4 with dimensions "rows" and "cols", with domain [1,4].
<- tiledb_domain(dims = c(tiledb_dim("rows", c(1L, 4L), 4L, "INT32"),
dom tiledb_dim("cols", c(1L, 4L), 4L, "INT32")))
<- tiledb_attr("a1", type = "CHAR")
attr ## set to variable length
:::libtiledb_attribute_set_cell_val_num(attr@ptr, NA)
tiledb
## now set the schema
<- tiledb_ctx()
ctx <- tiledb:::libtiledb_array_schema_create(ctx@ptr, "DENSE")
schptr :::libtiledb_array_schema_set_domain(schptr, dom@ptr)
tiledb:::libtiledb_array_schema_set_cell_order(schptr, "COL_MAJOR")
tiledb:::libtiledb_array_schema_set_tile_order(schptr, "COL_MAJOR")
tiledb:::libtiledb_array_schema_add_attribute(schptr, attr@ptr)
tiledb
## Create the (empty) array on disk.
:::libtiledb_array_create(uridensevar, schptr)
tiledb
<- "abbcccddeeefghhhijjjkklmnoop";
data <- c(0L, 1L, 3L, 6L, 8L, 11L, 12L, 13L, 16L, 17L, 20L, 22L, 23L, 24L, 25L, 27L)
offsets
<- tiledb_ctx()
ctx <- tiledb:::libtiledb_array_open(ctx@ptr, uridensevar, "WRITE")
arrptr <- tiledb:::libtiledb_query(ctx@ptr, arrptr, "WRITE")
qryptr <- tiledb:::libtiledb_query_set_layout(qryptr, "COL_MAJOR")
qryptr
<- tiledb:::libtiledb_query_buffer_var_char_create(offsets, data)
bufptr <- tiledb:::libtiledb_query_set_buffer_var_char(qryptr, "a1", bufptr)
qryptr <- tiledb:::libtiledb_query_submit(qryptr)
qryptr :::libtiledb_array_close(arrptr)
tiledb
#TODO Higher-level R support
# 'at' uses Sys.time() from R in seconds, and shifts back 10 minutes
<- Sys.time() - 10*60
at
# 'arr' is an already created array, could also be encrypted and carry key
<- tiledb_array_open_at(arr, "WRITE", Sys.time() - 600)
arr
# arr is now open for writing, any suitable content can be written the usual way
# continuing from previous example on dense variable length array
# (but this works of course with any array after a write is needed
# Number of fragments
<- tiledb_query_get_fragment_num(qry)
numfrag
# URI of given fragment, with 0 <= idx < numfrag
<- tiledb_query_get_fragment_uri(qry, idx)
uri
# Timestamp range of given fragment, with 0 <= idx < numfrag
<- tiledb_query_get_fragment_timestamp_range(qry, idx) tsrange
# get a schema directly from storage, uri holds a valid array URI
<- "<array_uri>"
uri <- schema(uri)
sch
# get an encrypted scheme directory from storage, enc_key is the AES-256 key
<- schema(uri, enc_key)
sch
# get a schema from an already openened array
# using a sparse array example, works the same for dense arrays
<- urisparse
array_name <- tiledb_array(uri = array_name, is.sparse = TRUE)
A <- schema(A)
sch
# one can also open encrypted arrays with key for AES-256 encryption
# and all other options (for sparse arrays, data.frame objects...)
<- "0123456789abcdeF0123456789abcdeF"
key <- tiledb_array(uri = array_name, encryption_key = key)
A <- schema(A) sch
# Get array schema, this shows the sparse accessor
# and it is similar for tiledb_dense()
<- tiledb_array(uri = urisparse, is.sparse = TRUE)
A <- schema(A)
schema
# Get array type
<- is.sparse(schema)
sparse
# Get tile capacity
<- capacity(schema)
t_capacity
# Get tile order
<- tile_order(schema)
t_order
# Get cell order
<- cell_order(schema)
c_order
# Get coordinates and offset filter list
<- filter_list(schema)
reslist
# Get the array domain
<- domain(schema)
dom
# Get all attributes as list
<- attrs(schema)
attrs
# Check if given attribute exists
<- has_attribute(schema, "attr")
has_attr
# Get attribute from name
<- attrs(schema, "attr")
attr
# Dump the array schema in ASCII format in the selected output
show(schema)
# ... get array schema
# ... get domain from schema
# Get the domain datatype (i.e., the datatype of all dimensions)
<- datatype(dom)
type
# Get number of dimensions
<- dim(dom)
dim_num
# Get all dimension
<- dimensions(dom)
dims
# Get dimension by index (0 <= i < dim_num)
<- tiledb_domain_get_dimension_from_index(dom, 1)
dim
# Get dimension by name
<- tiledb_domain_get_dimension_from_name(dom, "dimname")
dim
# Check dimension for name
tiledb_domain_has_dimension(dom, "dimname")
# Dump the domain in ASCII format in the selected output
show(dom)
# ... get array schema
# ... get domain
# ... get dimension by index or name
# Get dimension name
<- name(dim)
dim_name
# Get dimension datatype
<- datatype(dim)
dim_type
# Get dimension domain
<- domain(dim)
domain
# Get tile extent
<- tile(dim)
tile_extent
# Dump the dimension in ASCII format in the selected output
show(dim)
# ... get array schema
# ... get attribute by index or name
# Get attribute name
<- name(attr)
attr_name
# Get attribute datatype
<- datatype(attr)
attr_type
# Get filter list
<- filter_list(attr)
filter_list
# Check if attribute is variable-length
<- tiledb_attribute_is_variable_sized(attr)
is_var
# Get number of values per cell
<- ncells(attr)
num
# Get cell size for this attribute
<- tiledb_attribute_get_cell_size(attr)
sz
# Get the fill value (for both fixed and variable sized attributes)
tiledb_attribute_get_fill_value(attr)
# Dump the attribute in ASCII format in the selected output
show(attr)
# dim hold a previously created or load Dimension object
<- filter_list(dim)
fltrlst # or fltrlst <- filter_list(attr) for some attribute `attr`
# get number of filter
<- nfilters(fltrlst)
nb
# get max chunk size
<- max_chunk_size(fltrlst)
mxsz
# get filter by index from filter list (0 <= idx < num_filters)
<- i
idx <- fltrlst[idx]
fltr
# get option (that is filter-dependent) from filter
tiledb_filter_get_option(fltr, "COMPRESSION_LEVEL")
# set option (that is filter-dependent) for filter
tiledb_filter_set_option(fltr, "COMPRESSION_LEVEL", 9)
# get filter type
tiledb_filter_type(fltr)
# Open a dense array
<- tiledb_array(uri = uridense)
A
# Or, open a sparse array
# A <- tiledb_sparse(uri = "<array-uri>", ctx=ctx)
# Slice only rows 1, 2 and cols 2, 3, 4
<- A[1:2, 2:4]
data show(data)
<- tiledb_ctx()
ctx <- tiledb:::libtiledb_array_open(ctx@ptr, uridense, "READ")
arrptr ## subarray of rows 1,2 and cols 2,3,4
<- c(1L,2L, 2L,4L)
subarr
<- tiledb:::libtiledb_query(ctx@ptr, arrptr, "READ")
qryptr <- tiledb:::libtiledb_query_set_subarray(qryptr, subarr)
qryptr <- tiledb:::libtiledb_query_set_layout(qryptr, "COL_MAJOR")
qryptr <- integer(6) # reserve space
v <- tiledb:::libtiledb_query_set_buffer(qryptr, "a", v)
qryptr <- tiledb:::libtiledb_query_submit(qryptr)
qryptr print(v) # unformed array, no coordinates
<- tiledb:::libtiledb_array_close(arrptr) res
<- tiledb_ctx()
ctx <- tiledb:::libtiledb_array_open(ctx@ptr, uridensevar, "READ")
arrptr
<- c(1L,4L, 1L,4L)
subarr <- tiledb:::libtiledb_query_buffer_var_char_alloc(arrptr, subarr, "a1", 16, 100)
bufptr
<- tiledb:::libtiledb_query(ctx@ptr, arrptr, "READ")
qryptr <- tiledb:::libtiledb_query_set_subarray(qryptr, subarr)
qryptr <- tiledb:::libtiledb_query_set_layout(qryptr, "COL_MAJOR")
qryptr
<- tiledb:::libtiledb_query_set_buffer_var_char(qryptr, "a1", bufptr)
qryptr <- tiledb:::libtiledb_query_submit(qryptr)
qryptr :::libtiledb_array_close(arrptr)
tiledb
<- tiledb:::libtiledb_query_get_buffer_var_char(bufptr)
mat print(mat, quote=FALSE)
# example with one fixed- and one variable-sized domain
<- tiledb_domain(dims = c(tiledb_dim("d1", c(1L, 4L), 4L, "INT32"),
dom tiledb_dim("d2", NULL, NULL, "ASCII")))
# ... add attribute(s), write content, ...
# ... arr is the array opened
# retrieve non-empty domain for fixed-sized dimension
tiledb_array_get_non_empty_domain_from_index(arr, 1)
tiledb_array_get_non_empty_domain_from_name(arr, "d1")
# retrieve non-empty domain for variable-sized dimension
tiledb_array_get_non_empty_domain_from_index(arr, 2)
tiledb_array_get_non_empty_domain_from_name(arr, "d2")
# Arrays are reopened automatically for you based on
# read or write being performed. For direct pointer-based
# access you can also explicitly reopen
@ptr <- tiledb:::libtiledb_array_reopen(arr@ptr) arr
# Open the array and read as a data.frame from it.
<- tiledb_array(uri = array_name, return_as = "data.frame",
A encryption_key = encryption_key)
# Slice rows 1 and 2, and cols 2, 3 and 4
1:2, 2:4]
A[
# timestamps for TileDB are milliseconds since epoch, we use
# R Datime object to pass the value
<- as.POSIXct(1577955845.678, origin="1970-01-01")
tstamp
# open the array for reading at the timestamp
<- tiledb_array_open_at(A, "READ", tstamp) A
# create query, allocate result buffer, ...
# add two query range on the first dimension
<- tiledb_query_add_range(qry, schema, "d1", 2L, 4L)
qry <- tiledb_query_add_range(qry, schema, "d1", 6L, 8L)
qry
# add a query range on the second dimension, using variable size
<- tiledb_query_add_range(qry, schema, "d2", "caaa", "gzzz")
qry
# number of ranges given index
<- tiledb_query_get_range_num(qry, idx)
num
# range start, end and stride for range i (1 <= i <= num)
<- tiledb_query_get_range(qry, idx, i)
rng
# range start and end for variable-sized dimension for range i (1 <= i <= num)
<- tiledb_query_get_range_var(qry, idx, i) strrng
<- tiledb_ctx()
ctx <- tiledb:::libtiledb_array_open(ctx@ptr, uridense, "READ")
arrptr <- tiledb:::libtiledb_query(ctx@ptr, arrptr, "READ")
qryptr <- c(1L,4L, 1L,4L)
subarr <- tiledb:::libtiledb_query_set_subarray(qryptr, subarr)
qryptr <- integer(4) # reserve (insufficient) space
vec <- tiledb:::libtiledb_query_set_buffer(qryptr, "a", vec)
qryptr <- FALSE
finished while (!finished) {
<- tiledb:::libtiledb_query_submit(qryptr)
qryptr print(vec)
<- tiledb:::libtiledb_query_status(qryptr) == "COMPLETE"
finished
}<- tiledb:::libtiledb_array_close(arrptr) res
# ...create query object
# estimated size of a fixed-length attribute in sparse array
<- tiledb_query_get_est_result_size(qry, "a")
sz
# estimated size of a variable-length attribute in dense or sparse array
<- tiledb_query_get_est_result_size_var(qry, "b") sz
# time traveling is currently only accessible via the lower-level API
# we use the R Datetime type; internally TileDB uses milliseconds since epoch
<- Sys.time() - 60*60 # one hour ago
tstamp
<- tiledb_ctx()
ctx <- tiledb:::libtiledb_array_open_at(ctx@ptr, uridense, "READ", tstamp)
arrptr <- c(1L,2L, 2L,4L)
subarr <- tiledb:::libtiledb_query(ctx@ptr, arrptr, "READ")
qryptr <- tiledb:::libtiledb_query_set_subarray(qryptr, subarr)
qryptr <- tiledb:::libtiledb_query_set_layout(qryptr, "COL_MAJOR")
qryptr <- integer(6) # reserve space
a <- tiledb:::libtiledb_query_set_buffer(qryptr, "a", a)
qryptr <- tiledb:::libtiledb_query_submit(qryptr)
qryptr <- tiledb:::libtiledb_array_close(arrptr)
res
a
# we can do the same with encrypted arrays
<- "0123456789abcdeF0123456789abcdeF"
encryption_key <- tiledb:::libtiledb_array_open_at_with_key(ctx@ptr, uridensewkey, "READ",
arrptr encryption_key, tstamp)
# ... create read or write query
# Instead of using tiledb_query_submit(), use tiledb_query_submit_async()
# There is an alternate form with a callback function which is not yet supported
tiledb_query_submit_async(qry)
# Create a configuration object
<- tiledb_config()
config
# Set a configuration parameter
"sm.tile_cache_size"] <- "5000"
config[
# Get a configuration parameter
<- config["sm.tile_cache_size"]
tile_cache_size
# Unset a configuration parameter
tiledb_config_unset(config, "sm.tile_cache_size")
# Save to file
<- tiledb_config()
config "sm.tile_cache_size"] <- 0;
config[<- tempfile(pattern = "tiledb_config", fileext = ".txt")
file tiledb_config_save(config, file)
# Load from file
<- tiledb_config_load(file)
config_loaded = config_loaded["sm.tile_cache_size"] tile_cache_size
# R has no native iterator but one loop over the config elements
# by retrieving the configuration as a vector
<- as.vector(tiledb_config())
cfg
# print all non-empty config elements
for (n in names(cfg))
if (cfg[n] != "")
cat(n, ":", cfg[n], "\n")
# '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))
One can read by key:
# 'array' can be a URI, or an array opened for reading
tiledb_get_metadata(array, "aaa")
Or one can retrieve all metadata at once:
# 'array' can be a URI, or an array opened for reading
<- tiledb_get_all_metadata(array)
md
# prints all keys and (formatted) values
print(md)
# 'array' can be a URI, or an array opened for writing
tiledb_delete_metadata(array, "aaa")
# An array URI
<- "<array_uri>"
uri
# Consolidate with default configuration
array_consolidate(uri)
# Alteratively, create and pass a configuration object
<- tiledb_config()
cfg "sm.consolidation.steps"] <- "3"
cfg["sm.consolidation.mode"] <- "fragments"
cfg[array_consolidate(uri, cfg)
# An array URI
<- "<array_uri>"
uri
# Vacuum with default configuration
array_vacuum(uri)
# Alteratively, create and pass a configuration object
<- tiledb_config()
cfg "sm.vacuum.mode"] <- "fragments"
cfg[array_vacuum(uri, cfg)
tiledb_group_create("/tmp/my_group")
<- tiledb_object_type("<path>") type
# List arrays (defaults to default "PREORDER" traversal)
tiledb_object_ls(uri)
# Walk arrays (with "POSTORDER" traversal) returning a data.frame
<- tiledb_object_walk("<uri>", "POSTORDER")
res
# Show the content
print(res)
tiledb_object_mv("/tmp/my_group", "/tmp/my_group_2")
tiledb_object_remove(ctx, "/tmp/my_group_2/dense_array")
# binary file to be written
<- tempfile(pattern = "tiledb_vfs", fileext = ".bin")
uri # open file
<- tiledb_vfs_open(uri, "WRITE")
fhbuf
# create a binary payload from a serialized R object
<- as.integer(serialize(list(dbl=153, string="abcde"), NULL))
payload # write it and close file
tiledb_vfs_write(fhbuf, payload)
tiledb_vfs_close(fhbuf)
# write again overwriting previous write
<- tiledb_vfs_open(uri, "WRITE")
fhbuf <- as.integer(serialize(list(dbl=153.1, string="abcdef"), NULL))
payload tiledb_vfs_write(fhbuf, payload)
tiledb_vfs_close(fhbuf)
# append to existing file
<- tiledb_vfs_open(uri, "APPEND")
fhbuf <- as.integer(serialize(c(string="ghijkl"), NULL))
payload tiledb_vfs_write(fhbuf, payload)
tiledb_vfs_close(fhbuf)
# open a binary file for reading
<- tiledb_vfs_open(uri, "READ")
fhbuf <- tiledb_vfs_read(fhbuf, as.integer64(0), as.integer64(488))
vec tiledb_vfs_close(fhbuf)
# Creating a directory
if (!tiledb_vfs_is_dir("dir_A")) {
tiledb_vfs_create_dir("dir_A")
cat("Created 'dir_A'\n")
else {
} cat("'dir_A' already exists\n")
}
# Creating an (empty) file
if (!tiledb_vfs_is_file("dir_A/file_A")) {
tiledb_vfs_touch("dir_A/file_A")
cat("Created empty file 'dir_A/file_A'\n")
else {
} cat("File 'dir_A/file_A' already existed\n")
}
# Getting the file size
cat("Size of file 'dir_A/file_A': ",
tiledb_vfs_file_size("dir_A/file_A"), "\n")
# Moving files (moving directories is similar)
tiledb_vfs_move_file("dir_A/file_A", "dir_A/file_B")
# Cleaning up
tiledb_vfs_remove_file("dir_A/file_B")
tiledb_vfs_remove_dir("dir_A")
tiledb_vfs_create_bucket("s3://my_bucket")
tiledb_vfs_remove_bucket("s3://my_bucket")
<- tiledb_get_context()
ctx
<- tiledb_config()
config "vfs.file.max_parallel_ops"] <- 16
config[
<- tiledb_vfs(config, ctx)
vfs
# Or create the Config first and pass to the Ctx constructor
# Start collecting statistics
tiledb_stats_enable()
# ... create some query here
<- A[1:4]
res
# Stop collecting statistics
tiledb_stats_disable()
# Show the statistics on the console
tiledb_stats_print()
# Save the statistics to a file
tiledb_stats_dump("my_file_name")
# You can also reset the stats as follows
tiledb_stats_reset()
<- tryCatch({
result # Create a group. The code below creates a group `my_group` and prints a
# message because (normally) it will succeed.
tiledb_group_create("/tmp/my_group")
# Create the same group again. If we attempt to create the same group
# `my_group` as shown below, TileDB will return an error.
tiledb_group_create("/tmp.my_group")
warning = function(w) {
}, cat(w)
error = function(e) {
}, cat(e)
finally = {}
}, )
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.