Multi-Range Subarrays

You can slice a multi-range subarray as follows (also see Subarray):

C
C++
Python
R
Java
Go
C
// ... create context ctx
// ... 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;
tiledb_query_add_range(ctx, query, 0, &row_0_start, &row_0_end, NULL);
tiledb_query_add_range(ctx, query, 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_query_add_range(ctx, query, 1, &col_0_start, &col_0_end, NULL);
// For var-sized dimensions:
const char* start = "abc";
const char* end = "def";
tiledb_query_add_range_var(
ctx, query, 0, start, strlen(start), end, strlen(end));
C++
// ... 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.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;
query.add_range(1, col_0_start, col_0_end);
// For var-sized dimensions:
query.add_range(1, "abc", "def");
Python
# ... 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']
R
# create query, allocate result buffer, ...
# add two query range on the first dimension
qry <- tiledb_query_add_range(qry, schema, "d1", 2L, 4L)
qry <- tiledb_query_add_range(qry, schema, "d1", 6L, 8L)
# add a query range on the second dimension, using variable size
qry <- tiledb_query_add_range(qry, schema, "d2", "caaa", "gzzz")
Java
// ... 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");
Go
// ... 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"))

Slicing with a stride is not currently supported, but it is work in progress. See our roadmap for updates.

You can also get the various ranges set to the query as follows:

C
C++
Python
R
Java
Go
C
// ... create context ctx
// ... create query
// ... set range
// Get the number of ranges for a dimension
int dim_idx = 1;
unsigned long long range_num;
tiledb_query_get_range_num(ctx, query, dim_idx, &range_num);
// Get a range based on a dimension index
// NOTE: This functions 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_query_get_range(
ctx, query, 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_query_get_range_var_size(
ctx, query, 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_query_get_range_var(
ctx, query, dim_idx, range_idx, start_str, end_str);
C++
// ... 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)
Python
# TODO: not supported yet
R
# 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)
Java
// ... 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)
Go
// ... 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)