Multi-Range Subarrays
You can slice a multi-range subarray as follows (also see Subarray):
C
C++
Python
R
Java
Go
1
// ... create context ctx
2
// ... create query
3
4
// Add two ranges to first dimension
5
int row_0_start = 1, row_0_end = 2;
6
int row_1_start = 4, row_1_end = 4;
7
tiledb_query_add_range(ctx, query, 0, &row_0_start, &row_0_end, NULL);
8
tiledb_query_add_range(ctx, query, 0, &row_1_start, &row_1_end, NULL);
9
10
// Add one range to the second dimension
11
int col_0_start = 1, col_0_end = 4;
12
tiledb_query_add_range(ctx, query, 1, &col_0_start, &col_0_end, NULL);
13
14
// For var-sized dimensions:
15
const char* start = "abc";
16
const char* end = "def";
17
tiledb_query_add_range_var(
18
ctx, query, 0, start, strlen(start), end, strlen(end));
Copied!
1
// ... create query
2
3
// Add two ranges to first dimension
4
int row_0_start = 1, row_0_end = 2;
5
int row_1_start = 4, row_1_end = 4;
6
query.add_range(0, row_0_start, row_0_end)
7
.add_range(0, row_1_start, row_1_end);
8
9
// Add one range to the second dimension
10
int col_0_start = 1, col_0_end = 4;
11
query.add_range(1, col_0_start, col_0_end);
12
13
// For var-sized dimensions:
14
query.add_range(1, "abc", "def");
Copied!
1
# ... open array
2
3
# slice subarrays [1,2]x[1,4] and [4,4]x[1,4]
4
A.multi_index[ [slice(1,2), 4], 1:4 ]
5
6
# NOTE: Ranges in multi_index are all inclusive
7
8
# multi-range slicing of a dense array returns a NumPy array
9
# matching the shape of the selection.
10
11
# multi-range slicing of a sparse array returns a coordinate
12
# array and value array(s) for each attribute, similar to
13
# other sparse queries
14
# slicing string dimensions
15
# assuming array with nonempty_domain() == ('a', 'c'):
16
A.multi_index['a':'c']
Copied!
1
# create query, allocate result buffer, ...
2
3
# add two query range on the first dimension
4
qry <- tiledb_query_add_range(qry, schema, "d1", 2L, 4L)
5
qry <- tiledb_query_add_range(qry, schema, "d1", 6L, 8L)
6
7
# add a query range on the second dimension, using variable size
8
qry <- tiledb_query_add_range(qry, schema, "d2", "caaa", "gzzz")
Copied!
1
// ... create query
2
3
// Add two ranges to first dimension
4
int row_0_start = 1, row_0_end = 2;
5
int row_1_start = 4, row_1_end = 4;
6
query.addRange(0, row_0_start, row_0_end)
7
.addRange(0, row_1_start, row_1_end);
8
9
// Add one range to the second dimension
10
int col_0_start = 1, col_0_end = 4;
11
query.addRange(1, col_0_start, col_0_end);
12
13
// For var-sized dimensions:
14
query.addRangeVar(1, "abc", "def");
Copied!
1
// ... create query
2
3
// Add two ranges to first dimension
4
query.AddRange(0, int32(1), int32(2))
5
query.AddRange(0, int32(4), int32(4))
6
7
// Add one range to the second dimension
8
query.AddRange(1, int32(1), int32(4))
9
10
// For var-sized dimensions:
11
query.AddRangeVar(0, []byte("abc"), []byte("def"))
Copied!
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
1
// ... create context ctx
2
// ... create query
3
// ... set range
4
5
// Get the number of ranges for a dimension
6
int dim_idx = 1;
7
unsigned long long range_num;
8
tiledb_query_get_range_num(ctx, query, dim_idx, &range_num);
9
10
// Get a range based on a dimension index
11
// NOTE: This functions does not copy, it assigns pointers
12
const void* start;
13
const void* end;
14
const void* stride;
15
int dim_idx = 0;
16
unsigned long long range_idx = 2;
17
tiledb_query_get_range(
18
ctx, query, dim_idx, range_idx, &start, &end, &stride);
19
20
// For var-sized dimensions, we need to get the sizes of the start/end of the range
21
unsigned long long start_size, end_size;
22
tiledb_query_get_range_var_size(
23
ctx, query, dim_idx, range_idx, &start_size, &end_size);
24
25
// And then get the var-sized start and end
26
// NOTE: This function copies into the inputs
27
char start_str[start_size];
28
char end_str[end_size];
29
tiledb_query_get_range_var(
30
ctx, query, dim_idx, range_idx, start_str, end_str);
Copied!
1
// ... create query
2
// ... set ranges
3
4
// Get the number of ranges
5
unsigned dim_idx = 1;
6
uint64_t range_num = query.range_num(dim_idx);
7
8
// Get a range given a dimension index
9
unsigned dim_idx = 0;
10
unsigned range_idx = 0;
11
auto range = query.range<int32_t>(dim_idx, range_idx);
12
// This returns a triplet (start, end, strid)
13
14
// For var-sized dimensions:
15
std::array<std::string, 2> range = query.range(dim_idx, range_idx);
16
// This returns a pair of strings (start, end)
Copied!
1
# TODO: not supported yet
Copied!
1
# number of ranges given index
2
num <- tiledb_query_get_range_num(qry, idx)
3
4
# range start, end and stride for range i (1 <= i <= num)
5
rng <- tiledb_query_get_range(qry, idx, i)
6
7
# range start and end for variable-sized dimension for range i (1 <= i <= num)
8
strrng <- tiledb_query_get_range_var(qry, idx, i)
Copied!
1
// ... create query
2
// ... set ranges
3
4
// Get the number of ranges
5
int dimIdx = 1;
6
long rangeNum = query.getRangeNum(dimIdx);
7
8
// Get a range given a dimension index
9
int dimIdx = 0;
10
int rangeIdx = 0;
11
Pair<Object, Object> range = query.getRange(dimIdx, rangeIdx);
12
// This returns a triplet (start, end, strid)
13
14
// For var-sized dimensions:
15
Pair<Object, Object> range = query.getRangeVar(dimIdx, BigInteger.valueOf(rangeIdx));
16
// This returns a pair of strings (start, end)
Copied!
1
// ... create query
2
// ... set ranges
3
4
// Get the number of ranges
5
dimIdx := 1;
6
numOfRanges, _ := query.GetRangeNum(dimIdx)
7
8
// Get a range given a dimension index
9
var I uint64
10
for I = 0; I < *numOfRanges; I++ {
11
start, end, _ := query.GetRange(dimIdx, I)
12
fmt.Printf("Range for dimension: %d, start: %v, end: %v\n", dimIdx, start, end)
13
}
14
15
// For var-sized dimensions:
16
rangeIdx := 0
17
start, end, _ := query.GetRangeVar(dimIdx, rangeIdx)
18
// This returns a pair of strings (start, end)
Copied!
Copy link