# Import necessary libraries
import os.path
import shutil
import numpy as np
import tiledb
# Set array URI
= os.path.expanduser("~/result_estimation_python")
array_uri
# Delete array if it already exists
if os.path.exists(array_uri):
shutil.rmtree(array_uri)
Result Estimation
When reading from sparse arrays or variable-length attributes from either dense or sparse arrays, you have no way to know how big the result will be, unless you execute the query. If that is the case, how should you allocate your buffers before passing them to TileDB? TileDB offers a way to get the estimated result size for any attribute. Note that TileDB does not execute the query. Thus, getting the estimated result is faster than executing the query. However, this comes at the cost of accuracy, since allocating your buffers based on the estimate may still lead to incomplete queries. Thus, you should always check for the query status, even if you allocate your buffers based on the result estimate.
The number of bytes returned is an estimation and may not be divisible by the datatype size. You must perform any ceiling operations necessary to make sure the query works.
First, import the necessary libraries, set the array URI (that is, its path, which in this tutorial will be on local storage), and delete any previously created arrays with the same name.
Next, create the array, and write data to the array. This example uses a sparse array, but the described incomplete query functionality is applicable to any array.
Calculate the result estimate.
Clean up in the end by deleting the array.