The following example shows you how to create a 2D sparse TileDB array with a single attribute. See Configuration Parameters for details on the MyTile and core TileDB options you can set. Note that filters are optional for creating a table.
A TileDB array created through MariaDB is and behaves exactly like any other TileDB array. Therefore, it is accessible by all TileDB APIs (e.g., Python) and integrations (e.g., Spark).
Querying TileDB Arrays
MariaDB can dynamically discover existing TileDB arrays, i.e., even if they were created and populated externally from MariaDB. Therefore, you can just insert data into a TileDB array or query it as follows:
//Insert some valuesinsert into test_array (dim0, dim1, attr1) values (1, 1, "cell 1"), (1, 2, "cell 2"), (2, 1, "cell 3");//Read the arrayselect*from test_array;
Note that, if your array URI is longer than 64 characters, you need to use MariaDB's assisted table discovery for long names by simply doing the following:
// The following does notcreate an array, it just informs MariaDB about its existencecreatetablemy_arrayengine=mytile uri='s3://my_bucket/my_array';//Now you can query the arrayusing the new short nameselect*from my_array;
Encrypted TileDB Arrays
MyTile supports querying encrypted TileDB arrays by passing the encryption key as a parameter to the assisted table discovery. Note that due to a limitation of MariaDB, if you pass an encryption key it will be shown in the create table statement for any MariaDB user which has permissions to view the created table.
// The following does notcreate an array, it just informs MariaDB about its existencecreatetablemy_arrayengine=mytile uri='s3://my_bucket/my_array'encryption_key='0123456789abcdeF0123456789abcdeF;// Now you can query the array using the new short nameselect * from my_array;
Querying Array Metadata
Array metadata can be queried using a special suffix for the array URI. Adding @metadata to the URI will trigger MyTile to query the array metadata instead of the array data. The results are returned in two columns, key and value, both with string (TEXT) datatype in MariaDB. If a metadata value contains more than one value then a comma delimited string is returned.
select*from`s3://my_bucket/my_array@metadata`keyvaluekey4 25.1,26.2,27.3,28.4key3 25.1key1 25key5 This is TileDB array metadatakey2 25,26,27,28
Time Traveling
Time traveling for TileDB arrays is supported in two methods.
Dynamic Discovery With @timestamp
You can use the @<timestamp> keyword on the array URI to trigger MyTile to query the array at the given timestamp. This is equivalent to using open_at in other APIs.
select*from`s3://my_bucket/my_array@123`
Create Table
You can also use time traveling with the open_at=<timestamp> parameter with create table discovery.
// The following does notcreate an array, it just informs MariaDB about its existencecreatetablemy_arrayengine=mytile uri='s3://my_bucket/my_array'open_at=123;//Now you can query the arrayand it will be opened at the timestamp123select*from my_array;
Geospatial Data
You can also use certain geospatial functions that leverage the performance benefits of TileDB. These are: ST_Intersects, ST_Overlaps, ST_Equals.In addtion, all of the standard MariaDB spatial functions are available.
If your wkb_geometry column is paired with a spatial index as created by the OGR TileDB driver, the spatial filter will be pushed down to take advantage of TileDB's powerful dimension slicing for a significant performance boost. Without the spatial index, queries will return the same results but using a full scan.
The examples below show the geospatial functions we push down to TileDB. These queries can run on arrays created by MyTile, by TileDB Open Source, or any other of our supported APIs and integrations.
In order for TileDB to identify the spatial data attribute, your array must either have an attribute named "wkb_geometry" or have a "GEOMETRY_ATTRIBUTE_NAME" metadata field that specifies the name of the spatial attribute.