Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Query conditions can selectively return data that meets a given expression. Rather than filter the results after a query, a condition is pushed down to TileDB and returns a subset of the valid elements.
tiledb_ctx_t * ctx;
tiledb_ctx_alloc(NULL, &ctx);
tiledb_array_t* array_read;
tiledb_array_alloc(ctx, "<array_uri>", &array_read);
tiledb_array_open(ctx, array_read, TILEDB_READ);
// Query condition where a1 != NULL
tiledb_query_condition_t* queryCondition1;
tiledb_query_condition_alloc(ctx, &queryCondition1);
tiledb_query_condition_init(ctx, queryCondition1, "a1", NULL, 0, TILEDB_NE);
// Query condition where a2 > 10.5
float conditionVal = 10.5f;
tiledb_query_condition_t* queryCondition2;
tiledb_query_condition_alloc(ctx, &queryCondition2);
tiledb_query_condition_init(ctx, queryCondition2, "a2", &conditionVal, sizeof(float), TILEDB_GT);
// Query condition where (a1 != NULL || a2 > 10.5)
tiledb_query_condition_t* queryCondition;
tiledb_query_condition_alloc(ctx, &queryCondition);
tiledb_query_condition_combine(ctx, queryCondition1, queryCondition2, TILEDB_OR, &queryCondition);
// Slice rows 1, 2 and cols 2, 3, 4
int32_t subarray_ranges[] = {1, 2, 2, 4};
tiledb_subarray_t* subarray;
tiledb_subarray_alloc(ctx, array_read, &subarray);
tiledb_subarray_set_subarray(ctx, subarray, subarray_ranges);
// Allocate buffers for query
int32_t a1_read[6];
uint64_t a1_read_size = sizeof(a1_read);
uint8_t a1_read_validity[6];
uint64_t a1_read_validity_size = sizeof(a1_read_validity);
float a2_read[6];
uint64_t a2_read_size = sizeof(a2_read);
tiledb_query_t* query_read;
tiledb_query_alloc(ctx, array_read, TILEDB_READ, &query_read);
tiledb_query_set_layout(ctx, query_read, TILEDB_ROW_MAJOR);
tiledb_query_set_data_buffer(ctx, query_read, "a1", a1_read, &a1_read_size);
tiledb_query_set_validity_buffer(ctx, query_read, "a1", a1_read_validity, &a1_read_validity_size);
tiledb_query_set_data_buffer(ctx, query_read, "a2", a2_read, &a2_read_size);
tiledb_query_set_subarray_t(ctx, query_read, subarray);
tiledb_query_set_condition(ctx, query_read, queryCondition);
tiledb_query_submit(ctx, query_read);
// For sparse arrays, a1_read_size will be set to number of bytes read into the buffer
// + Values that don't meet the query condition won't be read, so we can use byte math to get a1_result_num
int a1_result_num = (int)(a1_read_size / sizeof(int32_t));
for (size_t i = 0; i < a1_result_num; i++) {
// Print buffers from sparse array...
}
// For dense arrays, we can use the fill value of an attribute to check the element met our conditions
tiledb_array_schema_t* schema;
tiledb_array_get_schema(ctx, array_read, &schema);
tiledb_attribute_t* attr;
tiledb_array_schema_get_attribute_from_name(ctx, schema, "a2", &attr);
float* fillVal;
uint64_t valSize;
tiledb_attribute_get_fill_value(ctx, attr, &fillVal, &valSize);
for (size_t i = 0; i < a2_read_size / sizeof(float); i++) {
if (a2_read[i] != *fillVal) {
// Print buffers from dense array...
}
}
// Free allocated objects
tiledb_array_free(&array_read);
tiledb_query_condition_free(&queryCondition1);
tiledb_query_condition_free(&queryCondition2);
tiledb_query_condition_free(&queryCondition);
tiledb_subarray_free(&subarray);
tiledb_query_free(&query_read);
Context ctx;
Array array_read(ctx, "<array_uri>", TILEDB_READ);
// QueryCondition for attribute values where a1 == nullptr
QueryCondition queryCondition1(ctx);
queryCondition1.init("a1", nullptr, 0, TILEDB_EQ);
// QueryCondition for attribute values where a2 <= 10.5
float qcVal = 10.5;
QueryCondition queryCondition2(ctx);
queryCondition2.init("a2", &qcVal, sizeof(float), TILEDB_LE);
// QueryCondition for (a1 == nullptr && a2 <= 10.5)
QueryCondition queryCondition = queryCondition1.combine(queryCondition2, TILEDB_AND);
// Slice rows 1, 2 and cols 2, 3, 4
Subarray subarray(ctx, array_read);
subarray.add_range("rows", 1, 2)
.add_range("cols", 2, 4);
// Allocate buffers for query
std::vector<int32_t> a1_read(6);
std::vector<uint8_t> a1_read_validity(6);
std::vector<float> a2_read(6);
Query query_read(ctx, array_read);
query_read.set_layout(TILEDB_ROW_MAJOR)
.set_subarray(subarray)
.set_data_buffer("a1", a1_read)
.set_validity_buffer("a1", a1_read_validity)
.set_data_buffer("a2", a2_read)
.set_condition(queryCondition2);
query_read.submit();
// For sparse arrays, we can check query result buffers for number of elements read with our query condition
auto buffers = query_read.result_buffer_elements();
uint64_t a1_result_num = buffers["a1"].second;
uint64_t a2_result_num = buffers["a2"].second;
for (size_t i = 0; i < a1_result_num; i++) {
// Print or consume buffers from sparse array...
}
// For dense arrays, we can use the fill value of an attribute to check the element met our conditions
const float* fillVal;
uint64_t fillValSize;
auto a2 = array_read.schema().attribute("a2");
a2.get_fill_value((const void**)&fillVal, &fillValSize);
for (size_t i = 0; i < a2_read.size(); i++) {
if (a2_read[i] != *fillVal) {
// Print or consume buffers from dense array...
}
}
import tiledb
with tiledb.open(uri, mode="r") as A:
# select cells where the attribute values for foo are less than 5
# and bar equal to string asdf.
# create a QueryCondition and pass a string containing a Python valid
# Boolean expression. Note that strings are be enclosed in quotes (either
# single or double quotes) whereas attribute names are not. The exception
# is if the attribute name has any special characters in it, in which
# case replace `namehere` with `attr("namehere")`.
q = A.query(cond="foo > 5 and bar == 'asdf'")
# Or:
q = A.query(cond="attr('percent.mt') > 10.0")
# output the results
print(q.df[:])
## Example assumes current array is the standard Palmer Penguins data set
### Via qc creation API
qc <- tiledb_query_condition_init(attr = "bill_length_mm",
value = 52,
dtype = "FLOAT64",
op = "GE")
res <- tiledb_array(uri, query_condition=qc)[]
dim(res) # 344 -> 18 due to qc
### Via query parser
arr <- tiledb_array(uri)
qc <- parse_query_condition(bill_length_mm > 52, arr)
query_condition(arr) <- qc
dim(res) # 344 -> 18 due to qc
### Or piped (for R 4.1.0 or later)
arr |>
tdb_filter(bill_length_mm > 52) |>
tdb_collect() |>
dim()
// Create TileDB context and open the array
try(Context ctx = new Context(),
Array array = new Array(ctx, "<array-uri>", TILEDB_READ)) {
// Slice only rows 1, 2 and cols 2, 3, 4
NativeArray subarray = new NativeArray(ctx, new long[] {1, 2, 2, 4}, Integer.class);
// Prepare the query
Query query = new Query(ctx, array, TILEDB_READ);
// Prepare the vectors that will hold the results
query.setBuffer(
"d1", new NativeArray(ctx, 20, Integer.class));
query.setBuffer(
"d2", new NativeArray(ctx, 20, Integer.class));
query.setBuffer(
"a1", new NativeArray(ctx, 20, Integer.class));
query.setBuffer(
"a2", new NativeArray(ctx, 20, Float.class));
query.setSubarray(subarray)
.setLayout(TILEDB_ROW_MAJOR);
// QueryCondition Equivalent to: a2 > 15.0f AND a1 == null;
QueryCondition con1 = new QueryCondition(ctx, "a2", 15.0f, Float.class, TILEDB_GT);
QueryCondition con2 = new QueryCondition(ctx, "a1", 0, null, TILEDB_EQ);
// Combine the two conditions
QueryCondition con3 = con1.combine(con2, TILEDB_AND);
query.setCondition(con3);
// Submit the query and close the array.
query.submit();
// NOTE: although not recommended (for performance reasons),
// you can get the coordinates even when slicing dense arrays.
// NOTE: The layout could have also been TILEDB_COL_MAJOR or
// TILEDB_GLOBAL_ORDER.
// Get the results in native java arrays
int[] d1 = (int[]) query.getBuffer("d1");
int[] d2 = (int[]) query.getBuffer("d2");
int[] a1 = (int[]) query.getBuffer("a1");
float[] a2 = (float[]) query.getBuffer("a2");
// Close the query
query.close();
}
// TODO
using TileDB.CSharp;
// Create TileDB context
using Context ctx = new Context();
// Prepare the array for reading
using Array array = new Array(ctx, "<array-uri>");
array.Open(QueryType.Read);
// QueryCondition for attribute values where a1 == null
using QueryCondition queryCondition1 =
// TODO: Actually implement this API.
QueryCondition.CreateIsNull(ctx, "a1");
// QueryCondition for attribute values where a2 <= 10.5
using QueryCondition queryCondition2 =
QueryCondition.Create(ctx, "a2", 10.5f, QueryConditionOperatorType.LessThanOrEqual);
// QueryCondition for (a1 == null && a2 <= 10.5)
using QueryCondition queryCondition = queryCondition1 & queryCondition2;
// Slice rows 1, 2 and cols 2, 3, 4
using Subarray subarray = new Subarray(array);
subarray.AddRange("rows", 1, 2);
subarray.AddRange("cols", 2, 4);
int[] a1 = new int[6];
byte[] a1Validity = new byte[6];
float[] a2 = new float[6];
using Query query = new Query(ctx, array, QueryType.Read);
query.SetSubarray(subarray);
query.SetLayout(LayoutType.RowMajor);
query.SetDataBuffer("a1", a1);
query.SetValidityBuffer("a", a1Validity);
query.SetDataBuffer("a2", a2);
query.SetCondition(queryCondition);
query.Submit();
// For sparse arrays, we can check query result buffers
// for number of elements read with our query condition
ulong a1Num = query.GetResultDataElements("a1");
ulong a2Num = query.GetResultDataElements("a2");
for (ulong i = 0; i < a1Num; i++)
{
// Print or consume buffers from sparse array...
}
// For dense arrays, we can use the fill value of an
// attribute to check the element met our conditions
float fillVal;
using (ArraySchema schema = array.Schema())
using (Attribute attribute = schema.Attribute("a2"))
{
fillVal = attribute.FillValue<float>()[0];
}
for (ulong i = 0; i < a2Num; i++)
{
if (a2[i] != fillVal)
{
// Print or consume buffer from dense array...
}
}
You can slice a multi-range subarray as follows (also see ):
You can also get the various ranges set to the query as follows:
You can open or reopen an array at a particular timestamp, if for example you'd like to see a view of the array in the past. See for more details. You can do so as follows:
You can get the schema of an existing array as follows:
The following code snippet shows how to inspect the various array schema members.
You can inspect the members of the domain as follows:
You can inspect a dimensions as follows:
You can inspect an attribute as follows:
You can inspect filters as follows:
When reading from sparse arrays or variable-length attributes from either dense or sparse arrays, there is no way to know how big the result will be, unless we actually execute the query. If that is the case, how should one allocate their buffers before passing them to TileDB? TileDB offers a way to get the estimated result size for any attribute. Note that TileDB does not actually execute the query and, therefore, getting the estimated result is very fast. However, this comes at the cost of accuracy, since allocating your buffers based on the estimate may still lead to . Therefore, you should always check for the query status, even if you allocate your buffers based on the result estimate.
You can get the result estimate as follows:
The number of bytes returned is an estimation and may not be divisible by the datatype size. It is left to the user to perform any ceiling operations necessary.
Aggregates can be requested on the data of a query so that the computation is pushed down to TileDB rather than needing to compute the result externally. The currently supported operations can be found in .
Here are some examples of using aggregates with TileDB:
To read either a dense or a sparse array, the user typically opens the array in read mode and provides a subarray, any subset of the attributes (potentially including the coordinates) and the layout to get the results into (see for more details). You can read from an array as follows:
You can read variable-length attributes (as written by the earlier example) as follows:
You can read fixed-length, nullable attributes as follows:
You can read variable-length, nullable attributes as follows:
You can get the non-empty domain of an array as follows:
Assuming an already open array, you can reopen the array at the current timestamp. This is useful when potential writes happened since you last opened the array, and you wish to reopen it to get the most up-to-date view of the array. Also note that this is more efficient than closing and opening the array, as it will prevent refetching already loaded fragment metadata. You can reopen an array as follows:
You can slice negative domains in Python as follows:
Slicing with a stride is not currently supported, but it is work in progress. See our for updates.
// ... create context ctx
// ... create query
// Create subarray object
tiledb_subarray_t* subarray;
tiledb_subarray_alloc(ctx, array, &subarray);
// Add two ranges to first dimension
int row_0_start = 1, row_0_end = 2;
int row_1_start = 4, row_1_end = 4;
tiledb_subarray_add_range(ctx, subarray, 0, &row_0_start, &row_0_end, NULL);
tiledb_subarray_add_range(ctx, subarray, 0, &row_1_start, &row_1_end, NULL);
// Add one range to the second dimension
int col_0_start = 1, col_0_end = 4;
tiledb_subarray_add_range(ctx, subarray, 1, &col_0_start, &col_0_end, NULL);
// For var-sized dimensions:
const char* start = "abc";
const char* end = "def";
tiledb_subarray_add_range_var(
ctx, subarray, 0, start, strlen(start), end, strlen(end));
// Set the subarray to the query
tiledb_query_set_subarray_t(ctx, query, subarray);
// ... Do stuff with the query.
tiledb_subarray_free(&subarray);
// ... create query
Subarray subarray(ctx, array);
// Add two ranges to first dimension
int row_0_start = 1, row_0_end = 2;
int row_1_start = 4, row_1_end = 4;
subarray.add_range(0, row_0_start, row_0_end)
.add_range(0, row_1_start, row_1_end);
// Add one range to the second dimension
int col_0_start = 1, col_0_end = 4;
subarray.add_range(1, col_0_start, col_0_end);
// For var-sized dimensions:
subarray.add_range(1, "abc", "def");
// Set the subarray to the query
query.set_subarray(subarray);
# ... open array
# slice subarrays [1,2]x[1,4] and [4,4]x[1,4]
A.multi_index[ [slice(1,2), 4], 1:4 ]
# NOTE: Ranges in multi_index are all inclusive
# multi-range slicing of a dense array returns a NumPy array
# matching the shape of the selection.
# multi-range slicing of a sparse array returns a coordinate
# array and value array(s) for each attribute, similar to
# other sparse queries
# slicing string dimensions
# assuming array with nonempty_domain() == ('a', 'c'):
A.multi_index['a':'c']
# to slice with a constructed list, pass arguments as a tuple:
slices = [slice(1,2), (slice(3,4)]
A.mtuli_index[tuple(slices)]
# The array will be 10x10 with dimensions "rows" and "cols", with domain [1,10]
dom <- tiledb_domain(dims = c(tiledb_dim("rows", c(1L, 10L), 4L, "INT32"),
tiledb_dim("cols", c(1L, 10L), 4L, "INT32")))
# The array will be dense with a single attribute "a" so each (i,j) cell
# can store an integer value
schema <- tiledb_array_schema(dom, attrs = c(tiledb_attr("a", type = "INT32")))
# Create the (empty) array on disk.
tiledb_array_create(uri, schema)
# Prepare a query
qry <- tiledb_query(arr, "READ")
# Allocate storage: for simple types we can use R vectors
# For more complex types we need to allocate data structures
rows <- integer(100)
cols <- integer(100)
values <- integer(100)
tiledb_query_set_buffer(qry, "rows", rows)
tiledb_query_set_buffer(qry, "cols", cols)
tiledb_query_set_buffer(qry, "a", values)
# Now set two ranges on the first dimension and one on the second
sch <- schema(arr)
tiledb_query_add_range(qry, sch, "rows", 3L, 4L)
tiledb_query_add_range(qry, sch, "rows", 7L, 9L)
tiledb_query_add_range(qry, sch, "cols", 2L, 4L)
tiledb_query_submit(qry)
tiledb_query_finalize(qry)
n <- tiledb_query_result_buffer_elements(qry, "a")
print(data.frame(rows=rows,cols=cols,a=values)[1:n,])
# This also works on string or float columns provided they have no
# missing values as in the is demo of 'penguins' where NAs have
# been removed so that we can index on 'species' and 'body_mass_g'
uri <- tempfile()
ppnona <- na.omit(penguins)
fromDataFrame(ppnona, uri, col_index=c("species", "body_mass_g"))
# We specify ranges as (named) list with one or more entries corresponding
# to the dimension name. Each list contains a matrix where each row contains
# the min and max value of a selection. Here we request species names from
# 'Aa' to 'Bz' (matching 'Adelie' penguins) as well as two body mass ranges
# from 2900 to 2999 and 3100 to 3199 grams, respectively. This returns
# eleven matching rows.
rngs <- list(species = cbind("Aa", "Bz"),
body_mass_g = matrix(c(2900,2999,
3100,3199),
2, 2, byrow=TRUE))
dat <- tiledb_array(uri, selected_range=rngs)[]
print(dat)
// ... create query
// Add two ranges to first dimension
int row_0_start = 1, row_0_end = 2;
int row_1_start = 4, row_1_end = 4;
query.addRange(0, row_0_start, row_0_end)
.addRange(0, row_1_start, row_1_end);
// Add one range to the second dimension
int col_0_start = 1, col_0_end = 4;
query.addRange(1, col_0_start, col_0_end);
// For var-sized dimensions:
query.addRangeVar(1, "abc", "def");
// ... create query
// Add two ranges to first dimension
query.AddRange(0, int32(1), int32(2))
query.AddRange(0, int32(4), int32(4))
// Add one range to the second dimension
query.AddRange(1, int32(1), int32(4))
// For var-sized dimensions:
query.AddRangeVar(0, []byte("abc"), []byte("def"))
// ... create array and query
// Create subarray
using Subarray subarray = new Subarray(array);
// Add two ranges to the first dimension
subarray.AddRange(0, 1, 2);
subarray.AddRange(0, 4, 4);
// Add one range to the second dimension
subarray.AddRange(1, 1, 4);
// For var-sized dimensions:
subarray.AddRange(1, "abc", "def");
// Set the subarray to the query.
query.SetSubarray(subarray);
// ... create context ctx
// ... create query
// ... set range
// Get subarray from query
tiledb_subarray_t* subarray;
tiledb_query_get_subarray_t(ctx, query, &subarray);
// Get the number of ranges for a dimension
int dim_idx = 1;
unsigned long long range_num;
tiledb_subarray_get_range_num(ctx, subarray, dim_idx, &range_num);
// Get a range based on a dimension index
// NOTE: This function does not copy, it assigns pointers
const void* start;
const void* end;
const void* stride;
int dim_idx = 0;
unsigned long long range_idx = 2;
tiledb_subarray_get_range(
ctx, subarray, dim_idx, range_idx, &start, &end, &stride);
// For var-sized dimensions, we need to get the sizes of the start/end of the range
unsigned long long start_size, end_size;
tiledb_subarray_get_range_var_size(
ctx, subarray, dim_idx, range_idx, &start_size, &end_size);
// And then get the var-sized start and end
// NOTE: This function copies into the inputs
char start_str[start_size];
char end_str[end_size];
tiledb_subarray_get_range_var(
ctx, subarray, dim_idx, range_idx, start_str, end_str);
// ... create query
// ... set ranges
// Get the number of ranges
unsigned dim_idx = 1;
uint64_t range_num = query.range_num(dim_idx);
// Get a range given a dimension index
unsigned dim_idx = 0;
unsigned range_idx = 0;
auto range = query.range<int32_t>(dim_idx, range_idx);
// This returns a triplet (start, end, strid)
// For var-sized dimensions:
std::array<std::string, 2> range = query.range(dim_idx, range_idx);
// This returns a pair of strings (start, end)
# TODO: not supported yet
# number of ranges given index
num <- tiledb_query_get_range_num(qry, idx)
# range start, end and stride for range i (1 <= i <= num)
rng <- tiledb_query_get_range(qry, idx, i)
# range start and end for variable-sized dimension for range i (1 <= i <= num)
strrng <- tiledb_query_get_range_var(qry, idx, i)
// ... create query
// ... set ranges
// Get the number of ranges
int dimIdx = 1;
long rangeNum = query.getRangeNum(dimIdx);
// Get a range given a dimension index
int dimIdx = 0;
int rangeIdx = 0;
Pair<Object, Object> range = query.getRange(dimIdx, rangeIdx);
// This returns a triplet (start, end, strid)
// For var-sized dimensions:
Pair<Object, Object> range = query.getRangeVar(dimIdx, BigInteger.valueOf(rangeIdx));
// This returns a pair of strings (start, end)
// ... create query
// ... set ranges
// Get the number of ranges
dimIdx := 1;
numOfRanges, _ := query.GetRangeNum(dimIdx)
// Get a range given a dimension index
var I uint64
for I = 0; I < *numOfRanges; I++ {
start, end, _ := query.GetRange(dimIdx, I)
fmt.Printf("Range for dimension: %d, start: %v, end: %v\n", dimIdx, start, end)
}
// For var-sized dimensions:
rangeIdx := 0
start, end, _ := query.GetRangeVar(dimIdx, rangeIdx)
// This returns a pair of strings (start, end)
// ... create context ctx, query and subarray
// Get the number of ranges for a dimension
ulong rangeCount = subarray.GetRangeCount(1);
// Get a range based on a dimension index
// NOTE: This will throw if the types mismatch
(int Start, int End) = subarray.GetRange<int>(0, 2);
// For var-sized dimensions, we need to call GetStringRange
(string StartVar, string EndVar) = subarray.GetStringRange(0, 2);
// ... create context ctx
// Open at a timestamp
uint64_t timestamp = 1561492235844; // In ms
tiledb_array_alloc(ctx, "<array-uri>", &array);
tiledb_array_set_open_timestamp_end(ctx, array, timestamp);
tiledb_array_open(ctx, array, TILEDB_READ);
// ... create context ctx
// Open at a timestamp
uint64_t timestamp = 1561492235844; // In ms
Array array(ctx, "<array-uri>", TILEDB_READ, TemporalPolicy(TimeTravel, timestamp));
// Or, open encrypted array with key at timestamp
const char key[] = "0123456789abcdeF0123456789abcdeF";
Array array(ctx, "<array-uri>", TILEDB_READ, TemporalPolicy(TimeTravel, timestamp), EncryptionAlgorithm(AESGCM, key));
timestamp = 1561492235844 # time in ms
# `tiledb.open` supports the `timestamp` keyword argument
A = tiledb.open(uri, timestamp=timestamp)
# `timestamp` may also be specified as a (start, end) tuple
A = tiledb.open(uri, timestamp=(start_ts, end_ts))
# Or, open encrypted array with key at timestamp
key = "0123456789abcdeF0123456789abcdeF"
A = tiledb.open(uri, key=key, timestamp=timestamp)
# time traveling is accessible via the lower-level API as well as the
# higher level api. we first show the lower-level
# we use the R Datetime type; internally TileDB uses milliseconds since epoch
tstamp <- Sys.time() - 60*60 # one hour ago
ctx <- tiledb_ctx()
arrptr <- tiledb:::libtiledb_array_open_at(ctx@ptr, uridense, "READ", tstamp)
subarr <- c(1L,2L, 2L,4L)
qryptr <- tiledb:::libtiledb_query(ctx@ptr, arrptr, "READ")
qryptr <- tiledb:::libtiledb_query_set_subarray(qryptr, subarr)
qryptr <- tiledb:::libtiledb_query_set_layout(qryptr, "ROW_MAJOR")
a <- integer(6) # reserve space
qryptr <- tiledb:::libtiledb_query_set_buffer(qryptr, "a", a)
qryptr <- tiledb:::libtiledb_query_submit(qryptr)
res <- tiledb:::libtiledb_array_close(arrptr)
a
# we can do the same with encrypted arrays
encryption_key <- "0123456789abcdeF0123456789abcdeF"
arrptr <- tiledb:::libtiledb_array_open_at_with_key(ctx@ptr, uridense, "READ",
encryption_tstamp)
# we can also pass datetime objects directly to the array access
# here we open an array at a given timestamp range, we can also
# use only one of the start or end timestamps
arr <- tiledb_array(uri,
timestamp_start = as.POSIXct("2021-01-01 00:00:00"),
timestamp_end = as.POSIXct("2021-01-31 23:59:99.999"))
// ... create context ctx
// Open at a timestamp
BigInteger timestamp = BigInteger.valueOf(1561492235844L); // In ms
Array array = new Array(ctx, "<array-uri>", TILEDB_READ, timestamp);
// Or, open encrypted array with key at timestamp
String key = "0123456789abcdeF0123456789abcdeF";
Array array = new Array(ctx, "<array-uri>", TILEDB_READ, EncryptionType.TILEDB_AES_256_GCM, key.getBytes(), timestamp)
// ... create context ctx
// Open at a timestamp
var timestamp uint64 = 1561492235844; // In ms
array.OpenAt(TILEDB_READ, timestamp)
// Or, open encrypted array with key at timestamp
var key := "0123456789abcdeF0123456789abcdeF"
array.OpenWithKey(TILEDB_READ, TILEDB_AES_256_GCM, key)
// ... create context ctx
// Open at a timestamp
ulong timestamp = 1561492235844; // In ms
using Array array = new Array(ctx, "<array-uri>");
array.SetOpenTimestampEnd(timestamp);
array.Open(QueryType.Read);
// ... create context ctx
tiledb_array_schema_t* schema;
// Get schema directly from storage
tiledb_array_schema_load(ctx, "<array-uri>", &schema);
// Or, load with key if the array is encrypted
const char key[] = "0123456789abcdeF0123456789abcdeF";
tiledb_array_schema_t* array_schema;
tiledb_array_schema_load_with_key(
ctx, "<array-uri>", TILEDB_AES_256_GCM, key, sizeof(key), &schema);
// Alternatively, you can get the schema from an open array
tiledb_array_t* array;
tiledb_array_alloc(ctx, "<array-uri>", &array);
tiledb_array_open(ctx, array, TILEDB_READ);
tiledb_array_get_schema(ctx, array, &array_schema);
// Or, open the array with key if it is encrypted
tiledb_array_open_with_key(
ctx, array, TILEDB_READ, TILEDB_AES_256_GCM, key, sizeof(key));
tiledb_array_get_schema(ctx, array, &array_schema);
// Make sure to free the array schema object
tiledb_array_schema_free(&schema);
tiledb_array_free(&array);
// ... create context ctx
// Get schema directly from storage
ArraySchema schema(ctx, "<array-uri>");
// Or, load with key if the array is encrypted
const char key[] = "0123456789abcdeF0123456789abcdeF";
ArraySchema schema(ctx, "<array-uri>", TILEDB_AES_256_GCM, key, sizeof(key));
// Alternatively, you can get the schema from an open array
Array array(ctx, "<array-uri>", TILEDB_READ);
auto schema = array.schema();
// Or, open the array with key if it is encrypted
Array array(
ctx, "<array-uri>", TILEDB_WRITE, TILEDB_AES_256_GCM, key, sizeof(key));
auto schema = array.schema();
# load the schema directly
# optionally pass `key=...` for encrypted arrays
schema = tiledb.ArraySchema.load(array_name)
# or access the schema from an open array object
A = tiledb.Array(array_name)
schema = A.schema
# get a schema directly from storage, uri holds a valid array URI
uri <- "<array_uri>"
sch <- schema(uri)
# get an encrypted scheme directory from storage, enc_key is the AES-256 key
sch <- schema(uri, enc_key)
# get a schema from an already openened array
# using a sparse array example, works the same for dense arrays
array_name <- urisparse
A <- tiledb_array(uri = array_name, is.sparse = TRUE)
sch <- schema(A)
# one can also open encrypted arrays with key for AES-256 encryption
# and all other options (for sparse arrays, data.frame objects...)
key <- "0123456789abcdeF0123456789abcdeF"
A <- tiledb_array(uri = array_name, encryption_key = key)
sch <- schema(A)
// ... create context ctx
// Get schema directly from storage
ArraySchema schema = new ArraySchema(ctx, "<array-uri>");
// Or, load with key if the array is encrypted
String key = "0123456789abcdeF0123456789abcdeF";
ArraySchema schema = new ArraySchema(ctx, "<array-uri>", TILEDB_AES_256_GCM, key.getBytes(StandardCharsets.UTF_8));
// Alternatively, you can get the schema from an open array
Array array = new Array(ctx, "<array-uri>", TILEDB_READ);
ArraySchema schema = array.schema();
// Or, open the array with key if it is encrypted
Array array = new Array(
ctx, "<array-uri>", TILEDB_WRITE, TILEDB_AES_256_GCM, key.getBytes(StandardCharsets.UTF_8));
ArraySchema schema = array.schema();
// ... create context ctx
// Get schema directly from storage
schema, _ := LoadArraySchema(ctx, "<array-uri>")
// Or, load with key if the array is encrypted
key := "0123456789abcdeF0123456789abcdeF"
schema, _ := LoadArraySchemaWithKey(ctx, "<array-uri>", TILEDB_AES_256_GCM, key)
// Alternatively, you can get the schema from an open array
array, _ := NewArray(ctx, "<array-uri>")
array.Open(TILEDB_READ)
schema, _ = array.Schema()
// Or, open the array with key if it is encrypted
array.OpenWithKey(TILEDB_READ, TILEDB_AES_256_GCM, key)
schema, err = array.Schema()
// ... create context ctx
// Get schema directly from storage
using ArraySchema schema = ArraySchema.Load(ctx, "<array-uri>");
// Alternatively, you can get the schema from an open array
using Array array = new Array(ctx, "<array-uri>");
using ArraySchema schema2 = array.Schema();
// ... create context ctx
// ... get array schema
// Get array type
tiledb_array_type_t* array_type;
tiledb_array_schema_get_array_type(ctx, schema, &array_type);
// Get tile capacity
unsigned long long capacity;
tiledb_array_schema_get_capacity(ctx, schema, &capacity);
// Get tile order
tiledb_layout_t tile_order;
tiledb_array_schema_get_tile_order(ctx, schema, &tile_order);
// Get cell order
tiledb_layout_t cell_order;
tiledb_array_schema_get_cell_order(ctx, schema, &cell_order);
// Get coordinates filter list
tiledb_filter_list_t* filter_list;
tiledb_array_schema_get_coords_filter_list(ctx, schema, &filter_list);
// Make sure to call `tiledb_filter_list_free(ctx, &filter_list);`
// Get offsets filter list
tiledb_filter_list_t* filter_list;
tiledb_array_schema_get_offsets_filter_list(ctx, schema, &filter_list);
// Make sure to call `tiledb_filter_list_free(ctx, &filter_list);`
// Get the array domain
tiledb_domain_t* domain;
tiledb_array_schema_get_domain(ctx, schema, &domain);
// Make sure to call `tiledb_domain_free(&domain);`
// Get number of attributes
unsigned int attr_num;
tiledb_array_schema_get_attribute_num(ctx, schema, &attr_num);
// Get attribute from index (0 <= idx < attr_num)
tiledb_attribute_t* attr;
tiledb_array_schema_get_attribute_from_index(ctx, schema, idx, &attr);
// Make sure to call `tiledb_attribute_free(&attr);`
// Get attribute from name
tiledb_attribute_t* attr;
tiledb_array_schema_get_attribute_from_name(ctx, schema, "attr", &attr);
// Make sure to call `tiledb_attribute_free(&attr);`
// Check if array schema has attribute with a given name
int has_attr;
tiledb_array_schema_has_attribute(ctx, array_schema, "attr", &has_attr);
// Checking if the array allows duplicates
int allows_dups;
tiledb_array_schema_get_allows_dups(ctx, array_schema, &allows_dups);
// Dump the array schema in ASCII format in the selected output
tiledb_array_schema_dump(ctx, array_schema, stdout);
// ... get array schema
// Get array type
tiledb_array_type_t array_type = schema.array_type();
// Get tile capacity
uint64_t capacity = schema.capacity()
// Get tile order
tiledb_layout_t tile_order = schema.tile_order();
// Get cell order
tiledb_layout_t cell_order = schema.cell_order();
// Get coordinates filter list
FilterList filter_list = schema.coords_filter_list();
// Get offsets filter list
FilterList filter_list = schema.offsets_filter_list();
// Get the array domain
Domain domain = schema.domain();
// Get number of attributes
uint32_t attr_num = schema.attribute_num();
// Get attribute from index (0 <= idx < attr_num)
Attribute attr = schema.attribute(idx);
// Get attribute from name
Attribute attr = schema.attribute("attr");
// Check if array schema has attribute with a given name
bool has_attr = schema.has_attribute("attr");
// Check if the array allows duplicates
bool allows_dups = schema.allows_dups();
// Dump the array schema in ASCII format in the selected output
schema.dump(stdout);
# ... get array schema
# Check if array is sparse
schema.sparse
# Get tile capacity
schema.capacity
# Cell and tile order return 'row-major', 'col-major', or 'global'
# Get tile order
schema.tile_order
# Get cell order
schema.cell_order
# Get coordinates filter list
coords_filters = schema.coords_filters
# Get offsets filter list
offsets_filters = schema.offsets_filters
# Get the array domain
domain = schema.domain
# Get number of attributes
attr_num = schema.nattr
# Get attribute by index (0 <= idx < attr_num)
attr = schema.attr(idx)
# Check if the named attribute exists
schema.has_attr("attr")
# Get attribute by name
attr = schema.attr("attr")
# Check if the schema allows duplicates (sparse)
allows_duplicates = schema.allows_duplicates
# Print the array schema in ASCII format
schema.dump()
# Get array schema, this shows the sparse accessor
# and it is similar for tiledb_dense()
A <- tiledb_array(uri = array_name, is.sparse = TRUE)
schema <- schema(A)
# Get array type
sparse <- is.sparse(schema)
# Get tile capacity
t_capacity <- capacity(schema)
# Get tile order
t_order <- tile_order(schema)
# Get cell order
c_order <- cell_order(schema)
# Get coordinates and offset filter list
reslist <- filter_list(schema)
# Get the array domain
dom <- domain(schema)
# Get all attributes as list
attrs <- attrs(schema)
# Check if given attribute exists
has_attr <- has_attribute(schema, "attr")
# Get attribute from name
attr <- attrs(schema, "attr")
# Dump the array schema in ASCII format in the selected output
show(schema)
// ... get array schema
// Get array type
ArrayType arrayType = schema.getArrayType();
// Get tile capacity
long capacity = schema.getCapacity()
// Get tile order
Layout tileOrder = schema.getTileOrder();
// Get cell order
Layout cellOrder = schema.getCellOrder();
// Get coordinates filter list
FilterList filterList = schema.getCoordsFilterList();
// Get offsets filter list
FilterList filterList = schema.getOffsetsFilterList();
// Get the array domain
Domain domain = schema.getDomain();
// Get number of attributes
long attrNnum = schema.getAttributeNum();
// Get all attributes
HashMap<String, Attribute> attrs = schema.getAttributes();
// Get attribute from index (0 <= idx < attr_num)
Attribute attr = schema.getAttribute(idx);
// Get attribute from name
Attribute attr = schema.getAttribute("attr");
// Check if array schema has attribute with a given name
boolean hasAttr = schema.hasAttribute("attr");
// Check if the array allows duplicates
boolean allowDups = schema.getAllowDups();
// Dump the array schema in ASCII format in the selected output
schema.dump();
// ... get array schema
// Get array type
arrayType, _ := schema.Type()
// Get tile capacity
capacity, _ := schema.Capacity()
// Get tile order
tileOrder, _ := schema.TileOrder()
// Get cell order
cellOrder := schema.CellOrder()
// Get coordinates filter list
filterList, _ := schema.CoordsFilterList()
// Get offsets filter list
filterList, _ := schema.OffsetsFilterList()
// Get the array domain
domain, _ := schema.Domain()
// Get number of attributes
attrNum := schema.AttributeNum()
// Get attribute from index (0 <= idx < attr_num)
attr, _ := schema.AttributeFromIndex(idx)
// Get attribute from name
attr, _ := schema.AttributeFromName("attr")
// Check if array schema has attribute with a given name
hasAttr, _ := schema.HasAttribute("attr")
// Check if the array allows duplicates
allowsDups, _ := schema.AllowsDups();
// Dump the array schema in ASCII format in the selected output
schema.DumpSTDOUT()
// ... get array schema
// Get array type
ArrayType arrayType = schema.ArrayType();
// Get tile capacity
ulong capacity = schema.Capacity()
// Get tile order
LayoutType tile_order = schema.TileOrder();
// Get cell order
LayoutType cell_order = schema.CellOrder();
// Get coordinates filter list
using FilterList coordsFilterList = schema.CoordsFilterList();
// Get offsets filter list
using FilterList offsetsFilterList = schema.OffsetsFilterList();
// Get the array domain
using Domain domain = schema.Domain();
// Get number of attributes
uint attrNum = schema.AttributeNum();
// Get attribute from index (0 <= idx < attr_num)
using Attribute attr1 = schema.Attribute(idx);
// Get attribute from name
using Attribute attr2 = schema.Attribute("attr");
// Check if array schema has attribute with a given name
bool hasAttr = schema.HasAttribute("attr");
// Check if the array allows duplicates
bool allowsDups = schema.AllowsDups();
// ... create context
// ... get array schema
// ... get domain from schema
// Get the domain datatype (i.e., the datatype of all dimensions)
tiledb_datatype_t type;
tiledb_domain_get_type(ctx, domain, &type);
// Get number of dimensions
uint32_t dim_num;
tiledb_domain_get_ndim(ctx, domain, &dim_num);
// Get dimension by index (0 <= idx < dim_num)
tiledb_dimension_t* dim;
tiledb_domain_get_dimension_from_index(ctx, domain, idx, &dim);
// Get dimension from name
tiledb_dimension_t* dim;
tiledb_domain_get_dimension_from_name(ctx, domain, "dim", &dim);
// Check if domain has dimension with a given name
int32_t has_dim;
tiledb_domain_has_dimension(ctx, domain, "dim", &has_dim);
// Dump the domain in ASCII format in the selected output
tiledb_domain_dump(ctx, domain, stdout);
// ... get array schema
// ... get domain from schema
// Get the domain datatype (i.e., the datatype of all dimensions)
tiledb_datatype_t type = domain.type();
// Get number of dimensions
uint32_t dim_num = domain.ndim();
// Get dimension by index (0 <= idx < dim_num)
Dimension dim = domain.dimension(idx);
// Get dimension from name
Dimension dim = domain.dimension("dim");
// Check if domain has dimension with a given name
bool has_dim = domain.has_dimension("dim");
// Dump the domain in ASCII format in the selected output
domain.dump(stdout);
# ... get array schema
# ... get domain from schema
# Get the domain data type (i.e., the datatype of all dimensions)
# note: types are automatically converted to NumPy dtypes
domain_dtype = domain.dtype
# Get number of dimensions
dim_num = domain.ndim
# Get dimension by index (0 <= idx < dim_num)
dim = domain.dim(idx)
# Get dimension by name
dim = domain.dim("dim")
# Check if domain has named dimension
domain.has_dim("dim")
# Print the domain in ASCII format
domain.dump()
# ... get array schema
# ... get domain from schema
# Get the domain datatype (i.e., the datatype of all dimensions)
type <- datatype(dom)
# Get number of dimensions
dim_num <- dim(dom)
# Get all dimension
dims <- dimensions(dom)
# Get dimension by index (0 <= i < dim_num)
dim <- tiledb_domain_get_dimension_from_index(dom, 1)
# Get dimension by name
dim <- tiledb_domain_get_dimension_from_name(dom, "dimname")
# 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 from schema
// Get the domain datatype (i.e., the datatype of all dimensions)
Datatype type = domain.getType();
// Get number of dimensions
long dim_num = domain.getNDim();
// Get dimension by index (0 <= idx < dim_num)
Dimension dim = domain.getDimension(idx);
// Get dimension from name
Dimension dim = domain.getDimension("dim");
// Check if domain has dimension with a given name
boolean hasDim = domain.hasDimension("dim");
// Dump the domain in ASCII format in the selected output
domain.dump(stdout);
// ... get array schema
// ... get domain from schema
// Get the domain datatype (i.e., the datatype of all dimensions)
domainType, _ := domain.Type()
// Get number of dimensions
dimNum, _ := domain.NDim();
// Get dimension by index (0 <= idx < dim_num)
dim, _ := domain.DimensionFromIndex(idx)
// Get dimension from name
dim, _ := domain.DimensionFromName("<dimension_name>")
// Check if domain has dimension with a given name
hasDim, _ := domain.HasDimension("<dimension_name>")
// Dump the domain in ASCII format in the selected output
domain.DumpSTDOUT()
// ... get domain from schema
// Get the domain datatype (i.e., the datatype of all dimensions)
DataType type = domain.Type();
// Get number of dimensions
uint32_t dim_num = domain.NDim();
// Get dimension by index (0 <= idx < dim_num)
using Dimension dim1 = domain.Dimension(idx);
// Get dimension from name
using DImension dim2 = domain.Dimension("dim");
// Check if domain has dimension with a given name
bool hasDimension = domain.HasDimension("dim");
// ... create context ctx
// ... get array schema
// ... get domain
// ... get dimension by index or name
// Get dimension name
const char* dim_name;
tiledb_dimension_get_name(ctx, dim, &dim_name);
// Get dimension datatype
tiledb_datatype_t dim_type;
tiledb_dimension_get_type(ctx, dim, &dim_type);
// Get dimension domain
tiledb_domain_t* domain;
tiledb_dimension_get_domain(ctx, dim, &domain);
// Get tile extent
const int* tile_extent;
tiledb_dimension_get_tile_extent(ctx, dim, &tile_extent);
// Get filter list
tiledb_filter_list_t* filter_list;
tiledb_dimension_get_filter_list(ctx, dim, &filter_list);
// Make sure to call `tiledb_filter_list_free(&filter_list);`
// Dump the dimension in ASCII format in the selected output
tiledb_dimension_dump(ctx, dim, stdout);
// Make sure to delete the dimension in the end
tiledb_dimension_free(&dim);
// ... get array schema
// ... get domain
// ... get dimension by index
// Get dimension name
std::string dim_name = dimension.name();
// Get dimension datatype
tiledb_datatype_t dim_type = dimension.type();
// Get dimension domain
std::pair<int, int> domain = dimension.domain<int>();
// Get tile extent
int tile_extent = dimension.tile_extent<int>();
// Get filter list
FilterList filter_list = dimension.filter_list();
// Dump the dimension in ASCII format in the selected output
dimension.dump(stdout);
# ... get array schema
# ... get domain
# ... get dimension by index
# Get dimension name
dim_name = dimension.name
# Get dimension datatype
dim_dtype = dimension.dtype
# Get dimension domain
dim_domain = dimension.domain
# Get tile extent
tile_extent = dimension.tile
# Get dimension filter list
filter_list = dimension.filters
# ... get array schema
# ... get domain
# ... get dimension by index or name
# Get dimension name
dim_name <- name(dim)
# Get dimension datatype
dim_type <- datatype(dim)
# Get dimension domain
domain <- domain(dim)
# Get tile extent
tile_extent <- tile(dim)
# Dump the dimension in ASCII format in the selected output
show(dim)
// ... get array schema
// ... get domain
// ... get dimension by index
// Get dimension name
String dimName = dimension.getName();
// Get dimension datatype
Datatype dim_type = dimension.getType();
// Get dimension domain
Pair domain = dimension.domain();
// Get filter list
FilterList filterList = dimension.getFilterList();
// Get tile extent
Integer tileExtent = dimension.getTileExtent();
// ... get array schema
// ... get domain
// ... get dimension by index or name
// Get dimension name
dimName, _ := dimension.Name()
// Get dimension datatype
dimType, _ := dimension.Type()
// Get dimension domain
domain, _ := dimension.Domain()
// Get tile extent
extent, _ := dimension.Extent;
// Get filter list
filterList, _ := dimension.FilterList()
// Dump the dimension in ASCII format in the selected output
dimension.DumpSTDOUT()
// ... create context ctx
// ... get array schema
// ... get domain
// ... get dimension by index or name
// Get dimension name
string dim_name = dim.Name();
// Get dimension datatype
DataType = dim.Type();
// Get dimension domain
using Domain domain = dim.Domain();
// Get tile extent
int tileExtent = dim.TileExtent<int>();
// Get filter list
using FilterList filterList = fim.FilterList();
// ... create context
// ... get array schema
// ... get attribute by index or name
// Get attribute name
const char* attr_name;
tiledb_attribute_get_name(ctx, attr, &attr_name);
// Get attribute datatype
tiledb_datatype_t attr_type;
tiledb_attribute_get_type(ctx, attr, &attr_type);
// Get filter list
tiledb_filter_list_t* filter_list;
tiledb_attribute_get_filter_list(ctx, attr, &filter_list);
// Make sure to call `tiledb_filter_list_free(&filter_list);`
// Get number of values per cell
uint32_t num;
tiledb_attribute_get_cell_val_num(ctx, attr, &num);
// Get cell size for this attribute
uint64_t cell_size;
tiledb_attribute_get_cell_size(ctx, attr, &cell_size);
// Get the fill value assuming a int32 attribute
const int32_t* value;
unsigned long long size;
tiledb_attribute_get_fill_value(ctx, attr, &value, &size);
// Get the fill value assuming a var char attribute
const char* value;
unsigned long long size;
tiledb_attribute_get_fill_value(ctx, attr, &value, &size);
// Dump the attribute in ASCII format in the selected output
tiledb_attribute_dump(ctx, dim, stdout);
// Make sure to delete the attribute in the end
tiledb_attribute_free(&attr);
// ... get array schema
// ... get attribute by index or name
// Get attribute name
std::string attr_name = attr.name();
// Get attribute datatype
tiledb_datatype_t attr_type = attr.type();
// Get filter list
FilterList filter_list = attr.filter_list();
// Check if attribute is variable-length
bool var_length = attr.variable_size();
// Get number of values per cell
uint32_t num = attr.cell_val_num();
// Get cell size for this attribute
uint64_t cell_size = attr.cell_size();
// Get the fill value assuming a fixed-sized attribute
const int32_t* value;
uint64_t size;
attr.get_fill_value(&value, &size);
// Get the fill value assuming a var-sized attribute
const char* value;
uint64_t size;
attr.get_fill_value(&value, &size);
// Dump the attribute in ASCII format in the selected output
attr.dump(stdout);
# ... create context
# ... get array schema
# ... get attribute by index or name
# Get attribute name
attr_name = attr.name
# Get attribute datatype
attr_dtype = attr.dtype
# Get filter list
filter_list = attr.filters
# Check if attribute is variable-length
var_length = attr.isvar
# Get number of values per cell
# note: for variable-length attributes, ncells == typemax(np.uint32)
num = attr.ncells
# Get datatype size (bytes) for this attribute
cell_size = attr.dtype.itemsize
# ... get array schema
# ... get attribute by index or name
# Get attribute name
attr_name <- name(attr)
# Get attribute datatype
attr_type <- datatype(attr)
# Get filter list
filter_list <- filter_list(attr)
# Check if attribute is variable-length
is_var <- tiledb_attribute_is_variable_sized(attr)
# Get number of values per cell
num <- ncells(attr)
# Get cell size for this attribute
sz <- tiledb_attribute_get_cell_size(attr)
# 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)
// ... get array schema
// ... get attribute by index or name
// Get attribute name
String attr_name = attr.getName();
// Get attribute datatype
Datatype attr_type = attr.getType();
// Get filter list
FilterList filter_list = attr.filter_list();
// Check if attribute is variable-length
boolean varLength = attr.isVar();
// Get number of values per cell
long num = attr.getCellValNum();
// Get cell size for this attribute
long cellSize = attr.getCellSize();
// Get the fill value assuming a fixed-sized attribute
int value = (int)attr.getFillValue().getFirst();
// Get the fill value assuming a var-sized attribute
String strValue = (String) attr.getFillValue().getFirst();
// Dump the attribute in ASCII format in the selected output
System.out.Println(attr.toString());
// ... get array schema
// ... get attribute by index or name
// Get attribute name
attrName, _ := attr.Name()
// Get attribute datatype
attrType, _ := attr.Type()
// Get filter list
filterList , _= attr.FilterList();
// Check if attribute is variable-length
TILEDB_VAR_NUM, _ := attr.CellValNum()
// Get number of values per cell
num, _ := attr.CellValNum()
// Get cell size for this attribute
cellSize, _ := attr.CellSize()
// Get the fill value assuming a fixed-sized attribute
fillValue, valueSize, _ := attribute.GetFillValue()
// Get the fill value assuming a var-sized attribute
charFillValue, valueSize, _ := attribute.GetFillValue()
// Dump the attribute in ASCII format in the selected output
attr.DumpSTDOUT()
// ... get array schema
// ... get attribute by index or name
// Get attribute name
string name = attr.name();
// Get attribute datatype
DataType type = attr.type();
// Get filter list
using FilterList fitlerList = attr.FilterList();
// Check if attribute is variable-length
bool isVarLength = attr.CellValNum() == Attribute.VariableSized;
// Get number of values per cell
uint num = attr.CellValNum();
// Get cell size for this attribute
ulong cellSize = attr.CellSize();
// Get the fill value assuming a fixed-sized attribute
int[] fillValue = attr.FillValue<int>();
// Get the fill value assuming a var-sized attribute
string fillValueStr = attr.FillValue();
// ... create context ctx
// ... get filter list
// Get number of filters
uint32_t num_filters;
tiledb_filter_list_get_nfilters(ctx, filter_list, &num_filters);
// Get the maximum tile chunk size
uint32_t max_chunk_size;
tiledb_filter_list_get_max_chunk_size(ctx, filter_list, &max_chunk_size);
// Get a filter by index (0 <= idx < num_filters)
tiledb_filter_t* filter;
tiledb_filter_list_get_filter_from_index(ctx, filter_list, idx, &filter);
// Get filter type
tiledb_filter_type_t type;
tiledb_filter_get_type(ctx, filter, &type);
// Get filter option (depends on the filter)
int32_t level;
tiledb_filter_get_option(ctx, filter, TILEDB_COMPRESSION_LEVEL, &level);
// Make sure to delete the filter list and filter
tiledb_filter_list_free(&filter_list);
tiledb_filter_free(&filter);
// ... get filter list
// Get number of filters
uint32_t num_filters = filter_list.nfilters();
// Get the maximum tile chunk size
uint32_t max_chunk_size = filter_list.max_chunk_size();
// Get a filter by index (0 <= idx < num_filters)
Filter filter = filter_list.filter(idx);
// Get filter type
tiledb_filter_type_t type = filter.filter_type();
// Get filter option (depends on the filter)
int32_t level;
filter.get_option(TILEDB_COMPRESSION_LEVEL, &level);
# ... get filter list
# Get number of filters
num_filters = len(filter_list)
# Get the maximum tile chunk size
max_chunk_size = filter_list.chunksize
# Get a filter by index (0 <= idx < num_filters)
filter = filter_list[idx]
# Get filter type
filter.__class__
# Get filter option (depends on the filter: `filter.<option name>`)
level = filter.level
# dim hold a previously created or load Dimension object
fltrlst <- filter_list(dim)
# or fltrlst <- filter_list(attr) for some attribute `attr`
# get number of filter
nb <- nfilters(fltrlst)
# get max chunk size
mxsz <- max_chunk_size(fltrlst)
# get filter by index from filter list (0 <= idx < num_filters)
idx <- i
fltr <- fltrlst[idx]
# 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)
// ... get filter list
// Get number of filters
uint32_t numFilters = filterList.getNumFilters();
// Get the maximum tile chunk size
uint32_t maxChunkSize = filterList.getMaxChunkSize();
// Get a filter by index (0 <= idx < num_filters)
Filter filter = filterList.getFilter(idx);
// Get filter type
if (filter instanceof BitShuffleFilter) {
} else if (filter instanceof BitWidthReductionFilter) {
} else if (filter instanceof ByteShuffleFilter) {
} else if (filter instanceof Bzip2Filter) {
} else if (filter instanceof CompressionFilter) {
} else if (filter instanceof DoubleDeltaFilter) {
} else if (filter instanceof GzipFilter) {
} else if (filter instanceof LZ4Filter) {
} else if (filter instanceof NoneFilter) {
} else if (filter instanceof PositiveDeltaFilter) {
} else if (filter instanceof RleFilter) {
} else if (filter instanceof ZstdFilter) {
}
// Get filter option (depends on the filter)
// Example #1: CompressionFilter
filter.getLevel();
// Example #2: PositiveDeltaFilter
filter.getWindow()
// Example #3: BitWidthReductionFilter
filter.getWindow()
// ... get filter list
// Get number of filters
numFilters, _ := filter_list.NFilters()
// Get the maximum tile chunk size
maxChunkSize, _ := filter_list.max_chunk_size()
// Get a filter by index (0 <= idx < num_filters)
filter, _ := filter_list.FilterFromIndex(idx)
// Get filter type
filterType, _ := filter.Type()
// Get filter option (depends on the filter)
level, _ := filter.Option(TILEDB_COMPRESSION_LEVEL)
// ... get filter list
// Get number of filters
uint num_filters = filterList.NFilters();
// Get the maximum tile chunk size
uint max_chunk_size = filterList.MaxChunkSize();
// Get a filter by index (0 <= idx < num_filters)
using Filter filter = filter_list.filter(idx);
// Get filter type
FilterType type = filter.FilterType();
// Get filter option (depends on the filter)
int level = filter.GetOption<int>(FilterOption.CompressionLevel);
// ... create context ctx
// ... create query
// Get estimate for a fixed-length attribute or dimension (in bytes)
uint64_t size;
tiledb_query_get_est_result_size(ctx, query, "a", &size);
// Get estimate for a variable-length attribute or dimension (in bytes)
uint64_t size_off, size_val;
tiledb_query_get_est_query_size_var(ctx, query, "b", &size_off, &size_val);
// ... create query
// Get estimate for a fixed-length attribute or dimension (in bytes)
uint64_t est_size = query.est_result_size("a");
// Get estimate for a variable-length attribute or dimension (in bytes)
// The first returned element is for the offsets buffer, and the second
// for the variable-length values buffer
std::pair<uint64_t, uint64_t> est_size = query.est_result_size_var("b");
# Create query object:
with tiledb.open(uri) as A:
iterable = A.query(return_incomplete=True).multi_index[:]
# then call `estimated_result_sizes`, which will return an
# OrderedDict of {'result name': estimate}
iterable.estimated_result_sizes()
# ...create query object
# estimated size of a fixed-length attribute in sparse array
sz <- tiledb_query_get_est_result_size(qryptr, "a")
# estimated size of a variable-length attribute in dense of sparse array
sz <- tiledb_query_get_est_result_size_var(qryptr, "b")
// ... create query
// Get estimate for a fixed-length attribute or dimension (in bytes)
int estSize = query.getEstResultSize("a");
// Get estimate for a variable-length attribute or dimension (in bytes)
// The first returned element is for the offsets buffer, and the second
// for the variable-length values buffer
Pair<Integer, Integer> estSize = query.getEstResultSizeVar("b");
// ... create context ctx
// ... create query
// Get estimate for a fixed-length attribute or dimension (in bytes)
size, _ := query.EstResultSize("a")
// Get estimate for a variable-length attribute or dimension (in bytes)
sizeOff, sizeVal, _ := query.EstResultSizeVar("a")
// ... create context ctx
// ... create query
ResultSize resultSize = query.EstResultSize("a");
resultSize.DataBytesSize // size in bytes
resultSize.DataSize(DataType.Int32) // size as Int32 elements
resultSize.OffsetsSize(); // number of offsets (var-size only)
tiledb_ctx_t * ctx;
tiledb_ctx_alloc(NULL, &ctx);
tiledb_array_t* array;
tiledb_array_alloc(ctx, "<array_uri>", &array);
tiledb_array_open(ctx, array, TILEDB_READ);
// Buffers that will hold the result (1 cells)
uint64_t count[1];
uint64_t count_size = sizeof(count);
int64_t sum[1];
uint64_t sum_size = sizeof(sum);
int32_t min[1];
uint64_t min_size = sizeof(min);
int32_t max[1];
uint64_t max_size = sizeof(max);
uint64_t null_count[1];
uint64_t null_count_size = sizeof(null_count);
double mean[1];
uint64_t mean_size = sizeof(mean);
// Create query
tiledb_query_t* query;
tiledb_query_alloc(ctx, array, TILEDB_READ, &query);
// Get the default channel from the query
tiledb_query_channel_t* default_channel;
tiledb_query_get_default_channel(ctx, query, &default_channel);
// Apply count aggregate
const tiledb_channel_operation_t* count_aggregate;
tiledb_aggregate_count_get(ctx, &count_aggregate);
tiledb_channel_apply_aggregate(
ctx, default_channel, "Count", count_aggregate);
// Apply sum aggregate on "a" attribute
const tiledb_channel_operator_t* operator_sum;
tiledb_channel_operator_sum_get(ctx, &operator_sum);
tiledb_channel_operation_t* sum_a;
tiledb_create_unary_aggregate(ctx, query, operator_sum, "a", &sum_a);
tiledb_channel_apply_aggregate(ctx, default_channel, "SumA", sum_a);
// Apply min aggregate on "b" attribute
const tiledb_channel_operator_t* operator_min;
tiledb_channel_operator_min_get(ctx, &operator_min);
tiledb_channel_operation_t* min_b;
tiledb_create_unary_aggregate(ctx, query, operator_min, "b", &min_b);
tiledb_channel_apply_aggregate(ctx, default_channel, "MinB", min_b);
// Apply max aggregate on "b" attribute
const tiledb_channel_operator_t* operator_max;
tiledb_channel_operator_max_get(ctx, &operator_max);
tiledb_channel_operation_t* max_b;
tiledb_create_unary_aggregate(ctx, query, operator_max, "b", &max_b);
tiledb_channel_apply_aggregate(ctx, default_channel, "MaxB", max_b);
// Apply null count aggregate on "c" attribute
const tiledb_channel_operator_t* operator_nc;
tiledb_channel_operator_null_count_get(ctx, &operator_nc);
tiledb_channel_operation_t* nc_c;
tiledb_create_unary_aggregate(ctx, query, operator_nc, "c", &nc_c);
tiledb_channel_apply_aggregate(ctx, default_channel, "NullCountC", nc_c);
// Apply mean aggregate on "c" attribute
const tiledb_channel_operator_t* operator_mean;
tiledb_channel_operator_mean_get(ctx, &operator_mean);
tiledb_channel_operation_t* mean_c;
tiledb_create_unary_aggregate(ctx, query, operator_mean, "c", &mean_c);
tiledb_channel_apply_aggregate(ctx, default_channel, "MeanC", mean_c);
// Set layout and buffers
tiledb_query_set_layout(ctx, query, TILEDB_UNORDERED);
tiledb_query_set_data_buffer(ctx, query, "Count", count, &count_size);
tiledb_query_set_data_buffer(ctx, query, "SumA", sum, &sum_size);
tiledb_query_set_data_buffer(ctx, query, "MinB", min, &min_size);
tiledb_query_set_data_buffer(ctx, query, "MaxB", max, &max_size);
tiledb_query_set_data_buffer(ctx, query, "NullCountC", null_count, &null_count_size);
tiledb_query_set_data_buffer(ctx, query, "MeanC", mean, &mean_size);
// Submit query
tiledb_query_submit(ctx, query);
// Close array
tiledb_array_close(ctx, array);
// Print out the results.
printf("Count has data %i\n", (int)count[0]);
printf("Sum of A has data %i\n", (int)sum[0]);
printf("Min of B has data %i\n", (int)min[0]);
printf("Max of B has data %i\n", (int)max[0]);
printf("Null count of C has data %i\n", (int)null_count[0]);
printf("Mean of C has data %f\n", mean[0]);
// Free allocated objects
tiledb_aggregate_free(ctx, &sum_a);
tiledb_aggregate_free(ctx, &min_b);
tiledb_aggregate_free(ctx, &max_b);
tiledb_aggregate_free(ctx, &nc_c);
tiledb_aggregate_free(ctx, &mean_c);
tiledb_query_channel_free(ctx, &default_channel);
tiledb_array_free(&array);
tiledb_query_free(&query);
tiledb_ctx_free(&ctx);
Context ctx;
Array array(ctx, "<array_uri>", TILEDB_READ);
// Vectors that will hold the result (1 cells)
std::vector<uint64_t> count(1);
std::vector<int64_t> sum(1);
std::vector<int32_t> min(1);
std::vector<int32_t> max(1);
std::vector<uint64_t> null_count(1);
std::vector<double> mean(1);
// Create a query
Query query(ctx, array);
// Get the default channel
QueryChannel default_channel = QueryExperimental::get_default_channel(query);
// Apply count aggregate
default_channel.apply_aggregate("Count", CountOperation());
// Apply sum aggregate on "a" attribute
ChannelOperation operation_sum =
QueryExperimental::create_unary_aggregate<SumOperator>(query, "a");
default_channel.apply_aggregate("SumA", operation_sum);
// Apply min/max aggregate on "b" attribute
ChannelOperation operation_min =
QueryExperimental::create_unary_aggregate<MinOperator>(query, "b");
default_channel.apply_aggregate("MinB", operation_min);
ChannelOperation operation_max =
QueryExperimental::create_unary_aggregate<MaxOperator>(query, "b");
default_channel.apply_aggregate("MaxB", operation_max);
// Apply null count/mean aggregate on "c" attribute
ChannelOperation operation_nc =
QueryExperimental::create_unary_aggregate<NullCountOperator>(query, "c");
default_channel.apply_aggregate("NullCountC", operation_nc);
ChannelOperation operation_mean =
QueryExperimental::create_unary_aggregate<MeanOperator>(query, "c");
default_channel.apply_aggregate("MeanC", operation_mean);
// Set layout and buffers.
query.set_layout(TILEDB_UNORDERED)
.set_data_buffer("Count", count)
.set_data_buffer("SumA", sum)
.set_data_buffer("MinB", min)
.set_data_buffer("MaxB", max)
.set_data_buffer("NullCountC", null_count)
.set_data_buffer("MeanC", mean);
// Submit the query and close the array.
query.submit();
array.close();
// Print out the results.
std::cout << "Count: " << count[0] << std::endl;
std::cout << "Sum of A: " << sum[0] << std::endl;
std::cout << "Min of B: " << min[0] << std::endl;
std::cout << "Max of B: " << max[0] << std::endl;
std::cout << "Null count of C: " << null_count[0] << std::endl;
std::cout << "Mean of C: " << mean[0] << std::endl;
import tiledb
with tiledb.open(uri, mode="r") as A:
# create a query object to run aggregate against
q = A.query()
# count the number of records in the array
print(q.agg("count")[:])
# Get the maximum value of attribute "a"
print(q.agg({"a": "max"})[:])
# Get the maximum, minimum and count value of attribute "a"
print(q.agg({"a": ["max", "min", "count"]})[:])
# Get the maximum, minimum of attribute "a" and the minimum of attribute "b"
print(q.agg({"a": ["max", "min"], "b":["min"]})[:])
# select cells where the attribute values for foo are less than 5
# and bar equal to string asdf and preform count
# create a QueryCondition and pass a string containing a Python valid
# Boolean expression. Note that strings are be enclosed in quotes (either
# single or double quotes) whereas attribute names are not. The exception
# is if the attribute name has any special characters in it, in which
# case replace `namehere` with `attr("namehere")`.
q = A.query(cond="foo > 5 and bar == 'asdf'")
# Or:
q = A.query(cond="attr('percent.mt') > 10.0")
# output the results
print(q.agg("count")[:])
# Open the array
arr <- tiledb_array(uri)
# Create a query
qry <- tiledb_query(arr)
qry <- tiledb_query_set_layout(qry, "UNORDERED")
# Compute "Mean"
res <- tiledb_query_apply_aggregate(qry, attr, "Mean", True)
cat("Mean for ", attr, " is ", res, "\n")
# Compute NullCount
res <- tiledb_query_apply_aggregate(qry, attr, "NullCount", True)
cat("Mean for ", attr, " is ", res, "\n")
# Compute Sum
res <- tiledb_query_apply_aggregate(qry, attr, "Sum", True)
cat("Sum for ", attr, " is ", res, "\n")
# Compute Min
res <- tiledb_query_apply_aggregate(qry, attr, "Min", True)
cat("Min for ", attr, " is ", res, "\n")
# Compute Max
res <- tiledb_query_apply_aggregate(qry, attr, "Max", True)
cat("Max for ", attr, " is ", res, "\n")
// Create TileDB context
tiledb_ctx_t* ctx;
tiledb_ctx_alloc(NULL, &ctx);
// Open a 2D array for reading
tiledb_array_t* array;
tiledb_array_alloc(ctx, "<array-uri>", &array);
tiledb_array_open(ctx, array, TILEDB_READ);
// Slice only rows 1, 2 and cols 2, 3, 4
int subarray[] = {1, 2, 2, 4};
// Prepare the vectors that will hold the results
int d1[20];
uint64_t d1_size = sizeof(d1);
int d2[20];
uint64_t d2_size = sizeof(d2);
int a[20];
uint64_t a_size = sizeof(a);
// Create query
tiledb_query_t* query;
tiledb_query_alloc(ctx, array, TILEDB_READ, &query);
tiledb_query_set_subarray(ctx, query, subarray);
tiledb_query_set_layout(ctx, query, TILEDB_ROW_MAJOR);
tiledb_query_set_data_buffer(ctx, query, "a", a, &a_size);
tiledb_query_set_data_buffer(ctx, query, "d1", d1, &d1_size);
tiledb_query_set_data_buffer(ctx, query, "d2", d2, &d2_size);
// NOTE: although not recommended (for performance reasons),
// you can get the coordinates even when slicing dense arrays.
// NOTE: The layout could have also been TILEDB_COL_MAJOR or
// TILEDB_GLOBAL_ORDER.
// Submit query
tiledb_query_submit(ctx, query);
// Close array
tiledb_array_close(ctx, array);
// NOTE: a_size, d1_size and d2_size now reflect the result size,
// i.e., TileDB changes those values so that you know how many
// results were retrieved (in bytes)
// Clean up
tiledb_array_free(&array);
tiledb_query_free(&query);
tiledb_ctx_free(&ctx);
// Create TileDB context
Context ctx;
// Prepare the array for reading
Array array(ctx, "<array-uri>", TILEDB_READ);
// Slice only rows 1, 2 and cols 2, 3, 4
const std::vector<int> subarray = {1, 2, 2, 4};
// Prepare the vectors that will hold the results
std::vector<int> d1(20);
std::vector<int> d2(20);
std::vector<int> a(20);
// Prepare the query
Query query(ctx, array, TILEDB_READ);
query.set_subarray(subarray)
.set_layout(TILEDB_ROW_MAJOR)
.set_data_buffer("a", a)
.set_data_buffer("d1", d1)
.set_data_buffer("d2", d2);
// Submit the query and close the array.
query.submit();
// NOTE: although not recommended (for performance reasons),
// you can get the coordinates even when slicing dense arrays.
// NOTE: The layout could have also been TILEDB_COL_MAJOR or
// TILEDB_GLOBAL_ORDER.
// Close the array
array.close();
// Get the number of elements in the result vectors
auto d1_num = query.result_buffer_elements()["d1"].second;
auto d2_num = query.result_buffer_elements()["d2"].second;
auto a_num = query.result_buffer_elements()["a"].second;
# or, tiledb.open will return DenseArray or SparseArray as per schema
with tiledb.open(array_uri) as A:
# note that array indexes are half-open like NumPy
data = A[1:3, 2:5]
a = data['a']
d1 = data['d1']
d2 = data['d2']
# using `with` (context manager) ensure call to A.close()
d1_num = len(d1)
d2_num = len(d2)
a_num = len(a)
# to select only a single attribute, use the `query` method
# with `attrs` argument, which returns an indexable object
with tiledb.open(array_uri) as A:
q = A.query(attrs=('a',))
# indexing the Query object will only retrieve the
# selected attribute(s)
q[1:3, 2:5]
# If you wish to return the coordinate vectors as well
with tiledb.open(array_uri) as A:
q = A.query(attrs=('a',), coords=True)
q[1:3, 2:5]
# NOTE: Indexing of the query object follows numpy semantics,
# therefore, q[1:10] stands for range [1,9]
# Create a TileDB context
ctx <- tiledb_ctx()
# Open a dense array
A <- tiledb_array(uri = uridense)
# Or, open a sparse array
# A <- tiledb_array(uri = "<array-uri>", is.sparse = TRUE)
# Slice only rows 1, 2 and cols 2, 3, 4
a <- A[1:2, 2:4]
show(a)
# we can also read using lower-level code
ctx <- tiledb_ctx()
arrptr <- tiledb:::libtiledb_array_open(ctx@ptr, uridense, "READ")
## subarray of rows 1,2 and cols 2,3,4
subarr <- c(1L,2L, 2L,4L)
qryptr <- tiledb:::libtiledb_query(ctx@ptr, arrptr, "READ")
qryptr <- tiledb:::libtiledb_query_set_subarray(qryptr, subarr)
qryptr <- tiledb:::libtiledb_query_set_layout(qryptr, "ROW_MAJOR")
a <- integer(6) # reserve space
qryptr <- tiledb:::libtiledb_query_set_buffer(qryptr, "a", a)
qryptr <- tiledb:::libtiledb_query_submit(qryptr)
print(a) # unformed array, no coordinates
res <- tiledb:::libtiledb_array_close(arrptr)
// Create TileDB context and open the array
try(Context ctx = new Context(),
Array array = new Array(ctx, "<array-uri>", TILEDB_READ)) {
// Slice only rows 1, 2 and cols 2, 3, 4
NativeArray subarray = new NativeArray(ctx, new long[] {1, 2, 2, 4}, Integer.class);
// Prepare the query
Query query = new Query(ctx, array, TILEDB_READ);
// Prepare the vectors that will hold the results
query.setBuffer(
"d1", new NativeArray(ctx, 20, Integer.class));
query.setBuffer(
"d2", new NativeArray(ctx, 20, Integer.class));
query.setBuffer(
"a1", new NativeArray(ctx, 20, Integer.class));
query.setSubarray(subarray)
.setLayout(TILEDB_ROW_MAJOR);
// Submit the query and close the array.
query.submit();
// NOTE: although not recommended (for performance reasons),
// you can get the coordinates even when slicing dense arrays.
// NOTE: The layout could have also been TILEDB_COL_MAJOR or
// TILEDB_GLOBAL_ORDER.
// Get the results in native java arrays
int[] d1 = (int[]) query.getBuffer("d1");
int[] d2 = (int[]) query.getBuffer("d2");
int[] a1 = (int[]) query.getBuffer("a1");
// Close the query
query.close();
}
// Create TileDB context
ctx, _ := tiledb.NewContext(nil)
// Open a 2D array for reading
array, _ := tiledb.NewArray(ctx, "<array-uri>")
array.Open(tiledb.TILEDB_READ)
// Slice only rows 1, 2 and cols 2, 3, 4
subArray := []int32{1, 2, 2, 4}
// Prepare the vectors that will hold the results
d1 := make([]int32, 20)
d2 := make([]int32, 20)
a := make([]int32, 20)
// Create query
query, _ := tiledb.NewQuery(ctx, array)
query.SetSubArray(subArray)
query.SetLayout(tiledb.TILEDB_ROW_MAJOR)
query.SetBuffer("a", a)
query.SetBuffer("d1", d1)
query.SetBuffer("d2", d2)
// NOTE: although not recommended (for performance reasons),
// you can get the coordinates even when slicing dense arrays.
// NOTE: The layout could have also been TILEDB_COL_MAJOR or
// TILEDB_GLOBAL_ORDER.
// Submit query
query.Submit()
// Close array
array.Close()
// NOTE: len(a)*size_of(int32), len(d1)*size_of(int32) and
// len(d2)*size_of(int32) now reflect the result size,
// i.e., TileDB changes those values so that you know how many
// results were retrieved (in bytes)
using System.Collections.Generic;
using TileDB.CSharp;
// Create TileDB context
using Context ctx = new Context();
// Prepare the array for reading
using Array array = new Array(ctx, "<array-uri>");
array.Open(QueryType.Read);
// Slice only rows 1, 2 and cols 2, 3, 4
using Subarray subarray = new Subarray(array);
subarray.SetSubarray(1, 2, 2, 4);
int[] d1 = new int[20];
int[] d2 = new int[20];
int[] a = new int[20];
using Query query = new Query(ctx, array, QueryType.Read);
query.SetSubarray(subarray);
query.SetLayout(LayoutType.RowMajor);
query.SetDataBuffer("a", a);
query.SetDataBuffer("d1", d1);
query.SetDataBuffer("d2", d2);
// Submit the query and close the array.
query.Submit();
// NOTE: although not recommended (for performance reasons),
// you can get the coordinates even when slicing dense arrays.
// NOTE: The layout could have also been ColumnMajpr or GlobalOrder.
// Close the array
array.Close();
// Get the number of elements read to the buffers
ulong d1Num = query.GetResultDataElements("d1");
ulong d2Num = query.GetResultDataElements("d2");
ulong aNum = query.GetResultDataElements("a");
// ... create contect ctx
// ... create query
// You need two buffers per variable-length attribute
char b_val[100];
unsigned long long b_val_size = sizeof(b_val);
unsigned long long b_off[20];
unsigned long long b_off_size = sizeof(b_off);
// Set buffers for the variable-length attributes
tiledb_query_set_data_buffer(ctx, query, "b", b_val, &b_val_size);
tiledb_query_set_offsets_buffer(ctx, query, "b", b_off, &b_off_size);
// Submit query
tiledb_query_submit(ctx, query);
// Close array
tiledb_array_close(ctx, array);
// NOTE: b_off_size and b_val_size now reflect the result size (in bytes)
// for the offsets and values of the results on this attribute,
// i.e., TileDB changes those values so that you know how many
// results were retrieved
// Clean up
tiledb_array_free(&array);
tiledb_query_free(&query);
tiledb_ctx_free(&ctx);
// ... create contect ctx
// ... create query
// You need two buffer per variable-length attribute
std::vector<char> b_val(100);
std::vector<uint64_t> b_off(20);
// Set buffers for the variable-length attributes
query.set_data_buffer(ctx, query, "b", b_val)
.set_offsets_buffer(ctx, query, "b", b_off);
// Get the number of elements in the result vectors
auto b_off_num = query.result_buffer_elements()["b"].first;
auto b_val_num = query.result_buffer_elements()["b"].second;
# Variable-length arrays may be sliced as usual in Python.
# The API handles unpacking and type conversion, and returns
# a NumPy object array-of-arrays.
# For example, given the var-length array created in the
# Writing Arrays section, the result will be returned as:
with tiledb.SparseArray(array_name) as A:
print(A[:][attr_name])
# Returns:
# array([array([1, 1], dtype=int32), array([2], dtype=int32),
# array([3, 3, 3], dtype=int32), array([4], dtype=int32)],
# dtype=object)
arr <- tiledb_array(tmp, "READ")
qry <- tiledb_query(arr, "READ")
qry <- tiledb_query_set_layout(qry, "ROW_MAJOR")
# reserve space
d1 <- integer(4)
d2 <- integer(4)
data <- integer(7)
data_off <- integer(4)
# setting buffers uses lower-level function
qryptr <- qry@ptr
vecptr <- tiledb:::libtiledb_query_buffer_var_vec_create(data_off, data)
qryptr <- tiledb:::libtiledb_query_set_buffer_var_vec(qryptr, "a", vecptr)
qry <- tiledb_query_set_buffer(qry, "d1", d1)
qry <- tiledb_query_set_buffer(qry, "d2", d2)
qry <- tiledb_query_submit(qry)
rl <- tiledb:::libtiledb_query_get_buffer_var_vec(qryptr, "a", vecptr)
print(rl)
// ... create contect ctx
// ... create query
// You need two buffer per variable-length attribute
query.setBuffer(
"b", new NativeArray(ctx, 100, Long.class),
new NativeArray(ctx, 20, String.class));
// Get the results in native java arrays
long[] b_offsets = (long[]) query.getVarBuffer("b");
byte[] b_data = (byte[]) query.getBuffer("b");
// Strings can be constructed by copying the bytes
String firstBString = new String(Arrays.copyOfRange(b_data, (int) b_offsets[0], b_offsets[1])
// ... create contect ctx
// ... create query
bufferElements, _ := query.EstimateBufferElements()
a1Off := make([]uint64, bufferElements["a1"][0])
a1Data := make([]byte, bufferElements["a1"][1]*rowsVariableLengthTileExtent)
query.SetLayout(tiledb.TILEDB_ROW_MAJOR)
query.SetBufferVar("a1", a1Off, a1Data)
// Submit the query
err = query.Submit()
elements, _ := query.ResultBufferElements()
// Get the string sizes
resultElA1Off := elements["a1"][0]
var a1StrSizes []uint64
for i := 0; i < int(resultElA1Off)-1; i++ {
a1StrSizes = append(a1StrSizes, a1Off[i+1]-a1Off[i])
}
resultA1DataSize := resultElMap["a1"][1] *
uint64(unsafe.Sizeof(byte(0)))
a1StrSizes = append(a1StrSizes,
resultA1DataSize-a1Off[resultElA1Off-1])
// Get the strings
a1Str := make([][]byte, resultElA1Off)
for i := 0; i < int(resultElA1Off); i++ {
a1Str[i] = make([]byte, 0)
for j := 0; j < int(a1StrSizes[i]); j++ {
a1Str[i] = append(a1Str[i], a1Data[a1Off[i]])
}
}
// Print the results
for i := 0; i < int(resultElA1Off); i++ {
fmt.Printf("a1: %s\n", string(a1Str[i]))
}
// ... create contect ctx
// ... create query
// You need two buffer per variable-length attribute
byte[] bValues = new byte[100];
ulong[] bOffsets = new ulong[20];
// Set buffers for the variable-length attributes
query.SetDataBuffer(bValues);
query.SetOffsetsBuffer(bOffsets);
query.Submit();
// Get the number of elements read to the buffers
ulong bOffsetsNum = query.GetResultOffsets("b");
ulong bNum = query.GetResultDataElements("b");
// Create TileDB context
tiledb_ctx_t* ctx;
tiledb_ctx_alloc(NULL, &ctx);
// Open a 2D array for reading
tiledb_array_t* array;
tiledb_array_alloc(ctx, "<array-uri>", &array);
tiledb_array_open(ctx, array, TILEDB_READ);
// Slice only rows 1, 2 and cols 2, 3, 4
int subarray[] = {1, 2, 2, 4};
// Prepare the vectors that will hold the results
int d1[20];
uint64_t d1_size = sizeof(d1);
int d2[20];
uint64_t d2_size = sizeof(d2);
int a[20];
uint64_t a_size = sizeof(a);
uint8_t a_validity[20];
uint64_t a_validity_size = sizeof(a_validity);
// Create query
tiledb_query_t* query;
tiledb_query_alloc(ctx, array, TILEDB_READ, &query);
tiledb_query_set_subarray(ctx, query, subarray);
tiledb_query_set_layout(ctx, query, TILEDB_ROW_MAJOR);
tiledb_query_set_data_buffer(ctx, query, "d1", d1, &d1_size);
tiledb_query_set_data_buffer(ctx, query, "d2", d2, &d2_size);
tiledb_query_set_data_buffer(ctx, query, "a", a, &a_size);
tiledb_query_set_validity_buffer(
ctx, query, "a", a_validity, &a_validity_size);
// NOTE: although not recommended (for performance reasons),
// you can get the coordinates even when slicing dense arrays.
// NOTE: The layout could have also been TILEDB_COL_MAJOR or
// TILEDB_GLOBAL_ORDER.
// Submit query
tiledb_query_submit(ctx, query);
// Close array
tiledb_array_close(ctx, array);
// NOTE: a_size, a_validity_size, d1_size and d2_size now reflect
// the result size, i.e., TileDB changes those values so that you
// know how many results were retrieved (in bytes)
// Clean up
tiledb_array_free(&array);
(&query);
tiledb_ctx_free(&ctx);
// Create TileDB context
Context ctx;
// Prepare the array for reading
Array array(ctx, "<array-uri>", TILEDB_READ);
// Slice only rows 1, 2 and cols 2, 3, 4
const std::vector<int> subarray = {1, 2, 2, 4};
// Prepare the vectors that will hold the results
std::vector<int> d1(20);
std::vector<int> d2(20);
std::vector<int> a(20);
std::vector<uint8_t> a_validity(20);
// Prepare the query
Query query(ctx, array, TILEDB_READ);
query.set_subarray(subarray)
.set_layout(TILEDB_ROW_MAJOR)
.set_data_buffer("a", a)
.set_validity_buffer("a", a_validity)
.set_data_buffer("d1", d1)
.set_data_buffer("d2", d2);
// Submit the query and close the array.
query.submit();
// NOTE: although not recommended (for performance reasons),
// you can get the coordinates even when slicing dense arrays.
// NOTE: The layout could have also been TILEDB_COL_MAJOR or
// TILEDB_GLOBAL_ORDER.
// Close the array
array.close();
// Get the number of elements in the result vectors
auto d1_num = query.result_buffer_elements()["d1"].second;
auto d2_num = query.result_buffer_elements()["d2"].second;
auto a_num = std::get<1>(query.result_buffer_elements_nullable()["a"]);
auto a_validity_num = std::get<2>(query.result_buffer_elements_nullable()["a"]);
# TODO
# To read the array written in the 'Fixed-length Attributes' section
arr <- tiledb_array(tmp, "READ")
qry <- tiledb_query(arr, "READ")
qry <- tiledb_query_set_layout(qry, "ROW_MAJOR")
v <- double(8)
d1 <- integer(4)
d2 <- integer(4)
qry <- tiledb_query_set_buffer(qry, "a", v)
qry <- tiledb_query_set_buffer(qry, "d1", d1)
qry <- tiledb_query_set_buffer(qry, "d2", d2)
qry <- tiledb_query_submit(qry)
res <- tiledb_array_close(arr)
# turn the vector in a list of tuples
v2l <- lapply(seq(1, length(v), by=2),
function(i) v[i:(i+1)] )
# use list protected by I() to create a list column
print(data.frame(d1 = d1, d2 = d2, a = I(v2l)))
# alternate approach is to ask for a data.frame
chk <- tiledb_array(tmp, return_as="data.frame")[]
print(chk)
// Create array and query
try (Array array = new Array(ctx, arrayURI, TILEDB_READ);
ArraySchema schema = array.getSchema();
Query query = new Query(array, TILEDB_READ)) {
// Fetch all cells
query.addRange(0, 1, 2);
query.addRange(1, 1, 2);
query.setLayout(TILEDB_ROW_MAJOR);
//create buffers for the query
NativeArray dim1Array = new NativeArray(ctx, 100, Integer.class);
NativeArray dim2Array = new NativeArray(ctx, 100, Integer.class);
NativeArray a1Array = new NativeArray(ctx, 100, Character.class);
NativeArray a1byteMap = new NativeArray(ctx, 100, Datatype.TILEDB_UINT8);
NativeArray a2Array = new NativeArray(ctx, 100, Float.class);
NativeArray a2byteMap = new NativeArray(ctx, 100, Datatype.TILEDB_UINT8);
//set buffers
query.setBuffer("rows", dim1Array);
query.setBuffer("cols", dim2Array);
query.setBufferNullable("a1", a1Array, a1byteMap);
query.setBufferNullable("a2", a2Array, a2byteMap);
Pair<Long, Long> estimated = query.getEstResultSizeNullable(ctx, "a1");
Assert.assertEquals((long) estimated.getFirst(), 4);
Assert.assertEquals((long) estimated.getSecond(), 4);
// Submit query
query.submit();
HashMap<String, Pair<Long, Long>> resultElements = query.resultBufferElements();
//get the populated buffers after query submission
int[] dim1 = (int[]) query.getBuffer("rows");
int[] dim2 = (int[]) query.getBuffer("cols");
byte[] a1 = (byte[]) query.getBuffer("a1");
float[] a2 = (float[]) query.getBuffer("a2");
//get the validity buffers
short[] a1ValidityByteMap = query.getValidityByteMap("a1");
short[] a2ValidityByteMap = query.getValidityByteMap("a2");
}
// TODO
using TileDB.CSharp;
// Create TileDB context
using Context ctx = new Context();
// Prepare the array for reading
using Array array = new Array(ctx, "<array-uri>");
array.Open(QueryType.Read);
// Slice only rows 1, 2 and cols 2, 3, 4
using Subarray subarray = new Subarray(array);
subarray.SetSubarray(1, 2, 2, 4);
int[] d1 = new int[20];
int[] d2 = new int[20];
int[] a = new int[20];
byte[] aValidity = new byte[20];
using Query query = new Query(ctx, array, QueryType.Read);
query.SetSubarray(subarray);
query.SetLayout(LayoutType.RowMajor);
query.SetDataBuffer("a", a);
query.SetValidityBuffer("a", aValidity);
query.SetDataBuffer("d1", d1);
query.SetDataBuffer("d2", d2);
// Submit the query and close the array.
query.Submit();
// NOTE: although not recommended (for performance reasons),
// you can get the coordinates even when slicing dense arrays.
// NOTE: The layout could have also been ColumnMajor or GlobalOrder.
// Close the array
array.Close();
// Get the number of elements read to the buffers
ulong d1Num = query.GetResultDataElements("d1");
ulong d2Num = query.GetResultDataElements("d2");
ulong aNum = query.GetResultDataElements("a");
ulong aValidityNum = query.GetResultValidities("a");
// ... create contect ctx
// ... create query
// You need three buffers per variable-length, nullable attribute
char b_val[100];
unsigned long long b_val_size = sizeof(b_val);
unsigned long long b_off[20];
unsigned long long b_off_size = sizeof(b_off);
uint8_t b_validity[20];
unsigned long long b_validity_size = sizeof(b_validity);
// Set buffers for the variable-length, nullable attribute
tiledb_query_set_data_buffer(ctx, query, "b", b_val, &b_val_size);
tiledb_query_set_offsets_buffer(ctx, query, "b", b_off, &b_off_size);
tiledb_query_set_validity_buffer(
ctx, query, "b", b_validity, &b_validity_size);
// Submit query
tiledb_query_submit(ctx, query);
// Close array
tiledb_array_close(ctx, array);
// NOTE: b_off_size, b_val_size, and b_validity_size now reflect
// the result size (in bytes) for the offsets, data values, and validity
// values of the results on this attribute, i.e., TileDB changes those
// values so that you know how many results were retrieved
// Clean up
tiledb_array_free(&array);
tiledb_query_free(&query);
tiledb_ctx_free(&ctx);
// ... create contect ctx
// ... create query
// You need two buffers per variable-length attribute
std::vector<char> b_val(100);
std::vector<uint64_t> b_off(20);
std::vector<uint8_t> b_validity(20);
// Set buffers for the variable-length attributes
query.set_data_buffer("b", b_val)
.set_offsets_buffer("b", b_off)
.set_validity_buffer("b", b_validity);
// Get the number of elements in the result vectors
auto b_off_num = std::get<0>(query.result_buffer_elements_nullable()["b"]);
auto b_val_num = std::get<1>(query.result_buffer_elements_nullable()["b"]);
auto b_validity_num = std::get<2>(query.result_buffer_elements_nullable()["b"]);
# TODO
## Variable-length nullable (numerical) attributes are not yet supported
// TODO
// TODO
// ... create contect ctx
// ... create query
// You need two buffer per variable-length attribute
byte[] b = new byte[100];
ulong[] bOffsets = new ulong[20];
byte[] bValidity = new byte[20];
// Set buffers for the variable-length attributes
query.SetDataBuffer("b", b);
query.SetOffsetsBuffer("b", bOffsets);
query.SetValidityBuffer("b", bValidity);
// Get the number of elements read to the buffers
ulong bNum = query.GetResultDataElements("b");
ulong bOffsetsNum = query.GetResultOffsets("b");
ulong bValiditiesNum = query.GetResultValidities("b");
// ... open array for reading
// Get non-empty domain for a dimension based on its index
int dom[2];
int is_empty;
tiledb_array_get_non_empty_domain_from_index(ctx, array, 0, domain, &is_empty);
// Or by name
tiledb_array_get_non_empty_domain_from_name(ctx, array, "dim", domain, &is_empty);
// For string dimensions, we need to first get the size of the
// start and end of the domain range, using the dimension index
unsigned long long start_size, end_size;
tiledb_array_get_non_empty_domain_var_size_from_index(
ctx, array, 0, &start_size, &end_size, &is_empty);
// Or by dimension name
tiledb_array_get_non_empty_domain_var_size_from_name(
ctx, array, "dim", &start_size, &end_size, &is_empty);
// Then we can allocate appropriately strings that will hold the start and end
char start[start_size];
char end[end_size];
tiledb_array_get_non_empty_domain_var_from_index(
ctx, array, 0, start, end, &is_empty);
// Or by dimension name
tiledb_array_get_non_empty_domain_var_from_name(
ctx, array, "dim", start, end, &is_empty);
// ... open array for reading
// Returns a pair for the [start, end] of the non-empty domain of
// the dimension with the given index
auto non_empty_domain = array.non_empty_domain<int>(0);
// Or by name
auto non_empty_domain = array.non_empty_domain<int>("dim");
// For var-sized dimensions, the following returns a pair of strings
auto non_empty_domain = array.non_empty_domain_var(0);
// Or by name
auto non_empty_domain = array.non_empty_domain_var("dim");
# ... open `array` for reading
# returns a tuple of the non-empty domain for each
# dimension:
non_empty_domain = array.nonempty_domain()
# example with one fixed- and one variable-sized domain
dom <- tiledb_domain(dims = c(tiledb_dim("d1", c(1L, 4L), 4L, "INT32"),
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")
// ... open array for reading
// Returns a pair for the [start, end] of the non-empty domain of
// the dimension with the given index
Pair<Object, Object> nonEmptyDomain = array.getNonEmptyDomainFromIndex(0);
// Or by name
Pair<Object, Object> nonEmptyDomain = array.getNonEmptyDomainFromName("dim");
// For var-sized dimensions, the following returns a pair of strings
Pair<String, String> nonEmptyDomain = array.getNonEmptyDomainVarFromIndex(0);
// Or by name
Pair<Object, Object> non_empty_domain = array.getNonEmptyDomainVarFromName("dim");
array.close();
// ... open array for reading
// Contains the non empty dimension bounds, by index
nonEmptyDomainFromIndex, isEmpty, _ := array.NonEmptyDomainFromIndex(0)
// Or by name
nonEmptyDomainFromName, isEmpty, _ := array.NonEmptyDomainFromName("dim")
// For var-sized dimensions, contains the non empty dimension bounds, by index
nonEmptyDomainVarFromIndex, isEmpty, _ := array.NonEmptyDomainVarFromIndex(0)
// Or by name
nonEmptyDomainVarFromName, isEmpty, _ := array.NonEmptyDomainVarFromName("dim")
// ... open array for reading
// Returns a pair for the [start, end] of the non-empty domain of
// the dimension with the given index
(int Start, int End, bool IsEmpty) nonEmptyDomain =
array.NonEmptyDomain<int>(0);
// Or by name
nonEmptyDomain = array.NonEmptyDomain<int>("dim");
// For var-sized dimensions, the following returns a pair of strings
(string Start, string End, bool IsEmpty) nonEmptyDomainVar =
array.NonEmptyDomainVar(0);
// Or by name
nonEmptyDomainVar = array.NonEmptyDomainVar("dim");
// ... create context ctx
// ... open an array for reading
tiledb_array_reopen(ctx, array);
// ... open an array for reading
array.reopen();
# ... create context ctx
# ... open an array for reading
array.reopen()
# optionally, specify a timestamp:
# array.reopen(timestamp=...)
# Arrays are reopened automatically for you based on
# read or write being performed. For direct pointer-based
# access you can also explicitly reopen
arr@ptr <- tiledb:::libtiledb_array_reopen(arr@ptr)
// ... open an array for reading
array.reopen();
// ... open an array for reading
array.Reopen()
// ... create context ctx
// ... open an array for reading
array.Reopen();
# NOTE: In `multi_index`, all ranges are inclusive
with tiledb.SparseArray(path) as A:
print(A.multi_index[-3:3])
To read from an encrypted array, you simply need to open it for reading using the encryption key you used to create it.
// ... create context ctx
// Open encrypted array for reading
const char key[] = "0123456789abcdeF0123456789abcdeF";
tiledb_config_t* config;
tiledb_config_alloc(&config, &error);
tiledb_config_set(config, "sm.encryption_type", "AES_256_GCM", &error);
tiledb_config_set(config, "sm.encryption_key", key, &error);
tiledb_array_t* array;
tiledb_array_alloc(ctx, "<array-uri>", &array);
tiledb_array_set_config(ctx, array, config);
tiledb_array_open(ctx, array, TILEDB_READ);
// ... create context ctx
// Open encrypted array for reading
const char key[] = "0123456789abcdeF0123456789abcdeF";
Array array(ctx,
"<array-uri>",
TILEDB_READ,
// Load all fragments available
TemporalPolicy(0, std::numeric_limits<uint64_t>::max()),
EncryptionAlgorithm(AESGCM, key));
// Or, open at timestamp
uint64_t timestamp = 1561492235844; // In ms
Array array(ctx,
"<array-uri>",
TILEDB_READ,
TemporalPolicy(0, timestamp),
EncryptionAlgorithm(AESGCM, key));
# All array and schema opening APIs support `key` as an
# optional keyword argument to open encrypted arrays:
key = "0123456789abcdeF0123456789abcdeF"
tiledb.DenseArray(uri, key=key)
tiledb.SparseArray(uri, key=key)
tiledb.open(uri, key=key)
tiledb.ArraySchema.load(uri, key=key)
ctx <- tiledb_ctx()
arrptr <-
tiledb:::libtiledb_array_open_with_key(ctx@ptr, uridensewkey, "READ",
encryption_key)
# timestamps for TileDB are milliseconds since epoch, we use
# R Datime object to pass the value
tstamp <- as.POSIXct(1577955845.678, origin="1970-01-01")
arrptr <-
tiledb:::libtiledb_array_open_at_with_key(ctx@ptr, uridensewkey, "READ",
encryption_key, tstamp)
// ... create context ctx
// Open encrypted array for reading
String key = "0123456789abcdeF0123456789abcdeF";
Array array = new Array(ctx, "<array-uri>", TILEDB_READ, TILEDB_AES_256_GCM, key.getBytes(StandardCharsets.UTF_8));
// Or, open at timestamp
uint64_t timestamp = 1561492235844; // In ms
Array array = new Array(ctx, "<array-uri>", TILEDB_READ, TILEDB_AES_256_GCM, key.getBytes(StandardCharsets.UTF_8), timestamp);
// ... create context ctx
// Open encrypted array for reading
var encryption_key = "0123456789abcdeF0123456789abcdeF"
array, _ := tiledb.NewArray(ctx, "<array-uri>")
array.OpenWithKey(tiledb.TILEDB_READ, tiledb.TILEDB_AES_256_GCM, encryption_key)
// Or, open at timestamp
var timestamp uint64 = 1561492235844 // In ms
array.OpenAtWithKey(tiledb.TILEDB_READ, tiledb.TILEDB_AES_256_GCM, encryption_key, timestamp)
// ... create context ctx
// Open encrypted array for reading
string Key = "0123456789abcdeF0123456789abcdeF";
using Config config = new Config();
tiledb_config_t* config;
tiledb_config_alloc(&config, &error);
config.Set("sm.encryption_type", "AES_256_GCM");
config.Set("sm.encryption_key", key);
using Array array = new Array(ctx, "<array-uri>");
array.SetConfig(config);
array.Open(QueryType.Read);
What happens if the buffer you set to a read query is not big enough to hold the results? TileDB is smart enough not to crash in that case. Instead, it will try to fill as many results as possible to your buffers, and through the query status inform you on whether the query completed or if it is incomplete. In the latter case, you can consume the results and resubmit the query (with the same buffers or newly set buffers), and TileDB will pick up where it left off. TileDB also allows you to get a result estimate, but even that does not guarantee whether the buffers will indeed large enough to hold the actual result.
The example below shows how to typically submit a read query to account for the possible case of incomplete queries.
// ... create context ctx
// ... create query
// ... suppose you query attribute "a" with buffer size "a_size"
// Create a loop
tiledb_query_status_t status;
do {
// Submit query and get status
tiledb_query_submit(ctx, query);
tiledb_query_get_status(ctx, query, &status);
// IMPORTANT: check if there are any results, as your buffer
// could have been too small to fit even a single result
if (status == TILEDB_INCOMPLETE && a_size == 0) { // No results
// You need to reallocate your buffers, otherwise
// you will get an infinite loop
} else if (a_size > 0) { // There are results
// Do something with the results
// You could set new buffers to the query here
}
} while (status == TILEDB_INCOMPLETE);
// Other statuses:
// TILEDB_{FAILED, COMPLETED, INPROGRESS, UNINITIALIZED}
// ... create context ctx
// ... create query
// ... suppose you query attribute "a"
// Create a loop
Query::Status status;
do {
// Submit query and get status
query.submit();
status = query.query_status();
// IMPORTANT: check if there are any results, as your buffer
// could have been too small to fit even a single result
bool has_results = query.result_buffer_elements()["a"].second != 0
if (status == Query::Status::INCOMPLETE && !has_results)) {
// You need to reallocate your buffers, otherwise
// you will get an infinite loop
} else if (has_results) {
// Do something with the results
// You could set new buffers to the query here
}
} while (status == Query::Status::INCOMPLETE);
// Other statuses:
// Query::Status::{FAILED, COMPLETED, INPROGRESS, UNINITIALIZED}
# Note that incomplete queries are only supported for
# sparse arrays in TileDB-Py at this time.
# Dense reads will internally reallocate buffers and resubmit the
# query until successful completion.
with tiledb.open(uri) as A:
# iterate results as an OrderedDict
iterable = A.query(return_incomplete=True).multi_index[:]
# -- or --
# iterate results as a dataframe
iterable = A.query(return_incomplete=True).df[:]
for result in iterable:
# this loop will iterate until the query has
# returned all results for the given range
print(result)
# Querying estimated result size for query:
# Create query object as above:
# iterable = A.query(return_incomplete=True).multi_index[:]
# then call `estimated_result_sizes`, which will return an
# OrderedDict of {'result name': estimate}
# iterable.estimated_result_sizes()
# We create buffers to fit the entire result in memory. If
# there is not enough memory allocated in the buffers to hold
# the complete result, TileDB will signal it, consume as much
# as it can after which one can consume the remainder
ctx <- tiledb_ctx()
arrptr <- tiledb:::libtiledb_array_open(ctx@ptr, uridense,
"READ")
qryptr <- tiledb:::libtiledb_query(ctx@ptr, arrptr, "READ")
subarr <- c(1L,4L, 1L,4L)
qryptr <- tiledb:::libtiledb_query_set_subarray(qryptr, subarr)
vec <- integer(4) # reserve (insufficient) space
qryptr <- tiledb:::libtiledb_query_set_buffer(qryptr, "a", vec)
finished <- FALSE
while (!finished) {
qryptr <- tiledb:::libtiledb_query_submit(qryptr)
print(vec)
finished <-
tiledb:::libtiledb_query_status(qryptr) == "COMPLETE"
}
res <- tiledb:::libtiledb_array_close(arrptr)
// ... create context ctx
// ... create query
// ... suppose you query attribute "a"
// Create a loop
QueryStatus status;
do {
// Submit query and get status
status = query.submit();
// IMPORTANT: check if there are any results, as your buffer
// could have been too small to fit even a single result
bool has_results = query.resultBufferElements().get("a").getSecond() != 0
if (status == TILEDB_INCOMPLETE && !has_results)) {
// You need to reallocate your buffers, otherwise
// you will get an infinite loop
} else if (has_results) {
// Do something with the results
// You could set new buffers to the query here
}
} while (status == TILEDB_INCOMPLETE);
// Other statuses:
// Query::Status::{FAILED, COMPLETED, INPROGRESS, UNINITIALIZED}
// ... create context ctx
// ... create query
// ... suppose you query attribute "a"
var queryStatus tiledb.QueryStatus
for {
// Submit the query
query.Submit()
queryStatus, _ = query.Status()
// IMPORTANT: check if there are any results, as your buffer
// could have been too small to fit even a single result
elements, _ := query.ResultBufferElements()
resultNum := elements["a1"][1]
if queryStatus == tiledb.TILEDB_INCOMPLETE && resultNum == 0 {
// You need to reallocate your buffers, otherwise
// you will get an infinite loop
} else {
// Do something with the results
// You could set new buffers to the query here
}
if queryStatus != tiledb.TILEDB_INCOMPLETE {
break
}
}
// Other statuses:
// Query::Status::{FAILED, COMPLETED, INPROGRESS, UNINITIALIZED}
// ... create context ctx
// ... create query
// ... suppose you query attribute "a"
// Create a loop
QueryStatus status;
do
{
// Submit query and get status
query.Submit();
status = query.Status();
// IMPORTANT: check if there are any results, as your buffer
// could have been too small to fit even a single result
bool hasResults = query.GetResultDataElements("a") != 0;
if (status == QueryStatus.Incomplete
&& query.GetStatusDetails().Reason == QueryStatusDetailsReason.UserBufferSize)
{
// You need to reallocate your buffers, otherwise
// you will get an infinite loop
}
else if (hasResults)
{
// Do something with the results
// You could set new buffers to the query here
}
} while (status == QueryStatus.Incomplete);
// Other statuses:
// QueryStatus.{Failed, Completed, InProgress, Uninitialized}
You can get information about the fragments for any array as follows: