Creating the Array Schema
After creating the dimensions, domain and attributes, you can create the array schema as follows:
#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);
#include <tiledb/tiledb>
using namespace 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);
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])
# ... create domain dom
# ... create attributes attr1, attr2
# Create a dense array
sch <- tiledb_array_schema(dom,
c(attr1, attr2),
sparse = FALSE)
# Or, create a sparse array
# sch <- tiledb_array_schema(dom,
# c(attr1, attr2),
# sparse = TRUE)
// ... 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);
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)
using TileDB.CSharp;
// ... create context ctx
// ... create domain dom
// ... create attributes attr1, attr2
// Create array schema for a dense array
using ArraySchema schema = new ArraySchema(ctx, ArrayType.Dense);
// Or, create array schema for a sparse array
// using ArraySchema schema = new ArraySchema(ctx, ArrayType.Sparse);
// Add domain and attributes to the schema
schema.SetDomain(domain);
schema.AddAttribute(attr1);
schema.AddAttribute(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 as follows. The tile order may be set to row-major or column-major; the cell order may be set to row-major, column-major, or hilbert.
// 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);
// 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}});
import tiledb
import numpy as np
# ... create domain dom
# ... create attributes attr1, attr2
# The tile and cell 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='R', tile_order='C'
)
# The cell (not tile) order can also be Hilbert for sparse arrays only
# schema = tiledb.ArraySchema(
# domain=domain, sparse=True, attrs=[attr1, attr2],
# cell_order="hilbert"
# )
# ... create domain dom
# ... create attributes attr1, attr2
# The tile and order can be "ROW_MAJOR"
# or "COL_MAJOR"
sch <- tiledb_array_schema(dom, c(attr1, attr2),
cell_order = "COL_MAJOR",
tile_order = "ROW_MAJOR")
## For sparse arrays, the cell (but not tile) order can also be Hilbert
sch <- tiledb_array_schema(dom, c(attr1, attr2), cell_order = "HILBERT")
// The tile and order can be TILEDB_ROW_MAJOR or TILEDB_COL_MAJOR
schema.setTileOrder(TILEDB_ROW_MAJOR);
schema.setCellOrder(TILEDB_COL_MAJOR);
// The cell (not tile) order can also be Hilbert for sparse arrays only
schema.setCellOrder(TILEDB_HILBERT);
// 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)
// The tile and order can be RowMajor or ColumnMajor
schema.SetTileOrder(LayoutType.RowMajor);
schema.SetCellOrder(LayoutType.ColumnMajor);
Setting the Data Tile Capacity
You can set the data tile capacity (applicable to sparse fragments), as follows:
tiledb_array_schema_set_capacity(ctx, schema, 1000000);
schema.set_capacity(1000000);
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)
# sch is TileDB Array schema
# set capacity on schema
capacity(sch) <- 100000
# get capacity on schema
capacity(sch)
schema.setCapacity(1000000);
schema.SetCapacity(1000000)
schema.SetCapacity(1000000);
Allowing Duplicates
Sparse arrays may allow multiple cells with the same coordinates to exist (dense arrays do not allow duplicates). By default, duplicates are not allowed. You can specify that a sparse array allows duplicates as follows:
#import <tiledb/tiledb.h>
// ... create array schema
tiledb_array_schema_set_allows_dups(ctx, array_schema, 1);
#import <tiledb/tiledb>
using namespace tiledb;
// ... create array schema
array_schema.set_allows_dups(true);
import tiledb
import numpy as np
# ... create domain dom
# ... create attributes attr1, attr2
schema = tiledb.ArraySchema(domain=dom, sparse=True,
attrs=[attr1, attr2],
allows_duplicates=True,
capacity=1000000)
# sch is a TileDB Array schema
# get 'duplicates allowed?' status
allow_dups(sch)
# set 'duplicates allowed?' status
allow_dups(sch) <- TRUE
// ... create array schema
arraySchema.setAllowDups(true);
// ... create array schema
arraySchema.SetAllowsDups(true)
schema.SetAllowsDups(true);
When duplicates are allowed, checking for duplicates and deduplication are disabled.
Checking Correctness
You can check if the array schema is set properly as follows:
#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
#import <tiledb/tiledb>
using namespace tiledb;
// ... create context ctx
// ... create array schema
// Test correctness
try {
schema.check();
} catch (const tiledb::TileDBError& e) {
// Handle error
}
import tiledb
import numpy as np
# ... create domain dom
# ... create attributes attr1, attr2
schema = tiledb.ArraySchema(...)
schema.check() # will raise error if invalid
# sch is a TileDB Array schema
check(sch)
// ... create array schema
// ... create filter lists fl1, fl2, similar to attributes
// Test correctness
try {
schema.check();
} catch (tiledb::TileDBError e) {
// Handle error
}
// ... create array schema
// ... create filter lists fl1, fl2, similar to attributes
// Test correctness
err := schema.check();
if err != nil {
// handle error
}
schema.Check();
Last updated