Multi-Range Subarrays

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

// ... 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);

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:

// ... 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);

Last updated