Creating the Array Schema

After creating the dimensions, domain and attribute, you can create the array schema as follows:

C
C++
Python
R
Java
Go
C
# include <tiledb/tiledb.h>
// ... create context ctx
// ... create domain dom
// ... create attributes attr1, attr2
tiledb_array_schema_t* schema;
// Create array schema for a dense array
tiledb_array_schema_alloc(ctx, TILEDB_DENSE, &schema);
// Or, create array schema for a sparse array
// tiledb_array_schema_alloc(ctx, TILEDB_SPARSE, &schema);
// Add domain and attributes to the schema
tiledb_array_schema_set_domain(ctx, schema, domain);
tiledb_array_schema_add_attribute(ctx, schema, attr1);
tiledb_array_schema_add_attribute(ctx, schema, attr2);
// ...
// Delete array schema
tiledb_array_schema_free(&schema);
C++
#include <tiledb/tiledb>
// ... create context ctx
// ... create domain dom
// ... create attributes attr1, attr2
// Create array schema for a dense array
ArraySchema schema(ctx, TILEDB_DENSE);
// Or, create array schema for a sparse array
// ArraySchema schema(ctx, TILEDB_SPARSE);
// Add domain and attributes to the array schema
schema.set_domain(domain);
schema.add_attribute(attr1)
.add_attribute(attr2);
Python
import tiledb
import numpy as np
# ... create domain dom
# ... create attributes attr1, attr2
# Create array schema for a dense array
schema = tiledb.ArraySchema(domain=dom, sparse=False, attrs=[attr1, attr2])
# Or, create array schema for a sparse array
# schema = tiledb.ArraySchema(domain=dom, sparse=True, attrs=[attr1, attr2])
R
# ... create domain dom
# ... create attributes attr1, attr2
# Create a dense array
schema <- tiledb_array_schema(dom, c(attr1, attr2), sparse = FALSE)
# Or, create a sparse array
# schema <- tiledb_array_schema(dom, c(attr1, attr2), sparse = TRUE)
Java
// ... create context ctx
// ... create domain dom
// ... create attributes attr1, attr2
// Create array schema for a dense array
ArraySchema schema = new ArraySchema(ctx, TILEDB_DENSE);
// Or, create array schema for a sparse array
// ArraySchema schema = new ArraySchema(ctx, TILEDB_SPARSE);
// Add domain and attributes to the array schema
schema.setDomain(dom);
schema.addAttribute(attr1);
schema.addAttribute(attr2);
Go
import tiledb "github.com/TileDB/TileDB-Go"
// ... create context ctx
// ... create domain dom
// ... create attributes attr1, attr2
// Create array schema for a dense array
schema, _ := tiledb.NewArraySchema(ctx, tiledb.TILEDB_DENSE)
// Or, create array schema for a sparse array
// schema, _ := tiledb.NewArraySchema(ctx, tiledb.TILEDB_SPARSE)
// Add domain and attributes to the array schema
schema.SetDomain(dom)
schema.AddAttributes(attr1)
schema.AddAttributes(attr2)

When creating the array schema, the dimension and attribute names must be unique.

Setting the Tile and Cell order

You can set the tile and cell order to row-major or column-major as follows:

C
C++
Python
R
Java
Go
C
// The tile and order can be TILEDB_ROW_MAJOR or TILEDB_COL_MAJOR
tiledb_array_schema_set_tile_order(ctx, schema, TILEDB_ROW_MAJOR);
tiledb_array_schema_set_cell_order(ctx, schema, TILEDB_COL_MAJOR);
C++
// The tile and order can be TILEDB_ROW_MAJOR or TILEDB_COL_MAJOR
schema.set_tile_order(TILEDB_ROW_MAJOR);
schema.set_cell_order(TILEDB_COL_MAJOR);
// Or, you case use a single function for both orders
// The first input is for the tile order, and the second for the cell order
schema.set_order({{TILEDB_ROW_MAJOR, TILEDB_COL_MAJOR}});
Python
import tiledb
import numpy as np
# ... create domain dom
# ... create attributes attr1, attr2
# The tile and order can be "row-major" or "col-major"
schema = tiledb.ArraySchema(domain=dom, sparse=False, attrs=[attr1, attr2],
cell_order='col-major', tile_order='row-major')
# or cell_order='F', tile_order='C')
R
# ... create domain dom
# ... create attributes attr1, attr2
# The tile and order can be "ROW_MAJOR" or "COL_MAJOR"
schema <- tiledb_array_schema(dom, c(attr1, attr2),
cell_order = "COL_MAJOR",
tile_order = "ROW_MAJOR")
Java
// The tile and order can be TILEDB_ROW_MAJOR or TILEDB_COL_MAJOR
schema.setTileOrder(TILEDB_ROW_MAJOR);
schema.setCellOrder(TILEDB_COL_MAJOR);
Go
// The tile and order can be TILEDB_ROW_MAJOR or TILEDB_COR_MAJOR
schema.SetTileOrder(tiledb.TILEDB_ROW_MAJOR)
schema.SetCellOrder(tiledb.TILEDB_COL_MAJOR)

Setting the Data Tile Capacity

You can set the data tile capacity (applicable to sparse fragments), as follows:

C
C++
Python
R
Java
Go
C
tiledb_array_schema_set_capacity(ctx, schema, 1000000);
C++
schema.set_capacity(1000000);
Python
import tiledb
import numpy as np
# ... create domain dom
# ... create attributes attr1, attr2
schema = tiledb.ArraySchema(domain=dom, sparse=False, attrs=[attr1, attr2],
capacity=1000000)
R
# TODO: This is currently missing from the R API
Java
schema.setCapacity(1000000);
Go
schema.SetCapacity(1000000)

Setting Coordinate and Offset Filters

You can set filter lists to the coordinates or the offsets of the variable-sized attributes as follows:

C
C++
Python
R
Java
Go
C
#import <tiledb/tiledb.h>
// ... create context ctx
// ... create array schema
// ... create filter lists fl1, fl2, similar to attributes
// Set coordinates and offsets filter lists
tiledb_array_schema_set_coords_filter_list(ctx, schema, fl1);
tiledb_array_schema_set_offsets_filter_list(ctx, schema, fl2);
C++
#import <tiledb/tiledb>
// ... create context ctx
// ... create array schema
// ... create filter lists fl1, fl2, similar to attributes
// Set coordinates and offsets filter lists
schema.set_coords_filter_list(fl1);
schema.set_offsets_filter_list(fl2);
Python
import tiledb
import numpy as np
# ... create domain dom
# ... create attributes attr1, attr2
# ... create filter lists fl1, fl2, similar to attributes
# Create the schema setting the coordinates and offsets filter lists
schema = tiledb.ArraySchema(domain=dom, sparse=False, attrs=[attr1, attr2],
coords_filters=fl1,
offsets_filters=fl2)
R
# ... create domain dom
# ... create attributes attr1, attr2
# ... create filter lists fl1, fl2, similar to attributes
# Create the schema setting the coordinates and offsets filter lists
schema <- tiledb_array_schema(dom, c(attr1, attr2),
coords_filter_list = fl1,
offsets_filter_list = fl2)
Java
// ... create array schema
// ... create filter lists fl1, fl2, similar to attributes
// Set coordinates and offsets filter lists
schema.setCoordsFilterList(fl1);
schema.setOffsetsFilterList(fl2);
Go
// ... create array schema
// ... create filter lists fl1, fl2, similar to attributes
// Set coordinates and offsets filter lists
schema.SetCoordsFilterList(fl1);
schema.SetOffsetsFilterList(fl2);

Note that the offset filters are applied to all variable-size attributes.

Checking Correctness

You can check if the array schema is set properly as follows:

C
C++
Python
R
Java
Go
C
#import <tiledb/tiledb.h>
// ... create context ctx
// ... create array schema
// Test correctness
int rc = tiledb_array_schema_check(ctx, schema);
// rc == TILEDB_OK if correct
// rc == TILEDB_ERR if incorrect
C++
#import <tiledb/tiledb>
// ... create context ctx
// ... create array schema
// Test correctness
try {
schema.check();
} catch (const tiledb::TileDBError& e) {
// Handle error
}
Python
# TODO: Not supported yet
R
# TODO: Not supported yet
Java
// ... create array schema
// ... create filter lists fl1, fl2, similar to attributes
// Test correctness
try {
schema.check();
} catch (tiledb::TileDBError e) {
// Handle error
}
Go
// ... create array schema
// ... create filter lists fl1, fl2, similar to attributes
// Test correctness
err := schema.check();
if err != nil {
// handle error
}