Incomplete Queries

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}

Last updated