Reading the Array Schema

Inspecting the Array Schema

You can get the schema of an existing array as follows:

// ... create context ctx

tiledb_array_schema_t* schema;

// Get schema directly from storage
tiledb_array_schema_load(ctx, "<array-uri>", &schema);

// Or, load with key if the array is encrypted
const char key[] = "0123456789abcdeF0123456789abcdeF";
tiledb_array_schema_t* array_schema;
tiledb_array_schema_load_with_key(
    ctx, "<array-uri>", TILEDB_AES_256_GCM, key, sizeof(key), &schema);

// Alternatively, you can get the schema from an open array
tiledb_array_t* array;
tiledb_array_alloc(ctx, "<array-uri>", &array);
tiledb_array_open(ctx, array, TILEDB_READ);
tiledb_array_get_schema(ctx, array, &array_schema);

// Or, open the array with key if it is encrypted
tiledb_array_open_with_key(
    ctx, array, TILEDB_READ, TILEDB_AES_256_GCM, key, sizeof(key));
tiledb_array_get_schema(ctx, array, &array_schema);

// Make sure to free the array schema object
tiledb_array_schema_free(&schema);
tiledb_array_free(&array);

The following code snippet shows how to inspect the various array schema members.

// ... create context ctx
// ... get array schema

// Get array type
tiledb_array_type_t* array_type;
tiledb_array_schema_get_array_type(ctx, schema, &array_type);

// Get tile capacity
unsigned long long capacity;
tiledb_array_schema_get_capacity(ctx, schema, &capacity);

// Get tile order
tiledb_layout_t tile_order;
tiledb_array_schema_get_tile_order(ctx, schema, &tile_order);

// Get cell order
tiledb_layout_t cell_order;
tiledb_array_schema_get_cell_order(ctx, schema, &cell_order);

// Get coordinates filter list
tiledb_filter_list_t* filter_list;
tiledb_array_schema_get_coords_filter_list(ctx, schema, &filter_list);
// Make sure to call `tiledb_filter_list_free(ctx, &filter_list);`

// Get offsets filter list
tiledb_filter_list_t* filter_list;
tiledb_array_schema_get_offsets_filter_list(ctx, schema, &filter_list);
// Make sure to call `tiledb_filter_list_free(ctx, &filter_list);`

// Get the array domain
tiledb_domain_t* domain;
tiledb_array_schema_get_domain(ctx, schema, &domain);
// Make sure to call `tiledb_domain_free(&domain);`

// Get number of attributes
unsigned int attr_num;
tiledb_array_schema_get_attribute_num(ctx, schema, &attr_num);

// Get attribute from index (0 <= idx < attr_num)
tiledb_attribute_t* attr;
tiledb_array_schema_get_attribute_from_index(ctx, schema, idx, &attr);
// Make sure to call `tiledb_attribute_free(&attr);`

// Get attribute from name
tiledb_attribute_t* attr;
tiledb_array_schema_get_attribute_from_name(ctx, schema, "attr", &attr);
// Make sure to call `tiledb_attribute_free(&attr);`

// Check if array schema has attribute with a given name
int has_attr;
tiledb_array_schema_has_attribute(ctx, array_schema, "attr", &has_attr);

// Checking if the array allows duplicates
int allows_dups;
tiledb_array_schema_get_allows_dups(ctx, array_schema, &allows_dups);

// Dump the array schema in ASCII format in the selected output
tiledb_array_schema_dump(ctx, array_schema, stdout);

Inspecting Domain

You can inspect the members of the domain as follows:

// ... create context
// ... get array schema
// ... get domain from schema

// Get the domain datatype (i.e., the datatype of all dimensions)
tiledb_datatype_t type;
tiledb_domain_get_type(ctx, domain, &type);

// Get number of dimensions
uint32_t dim_num;
tiledb_domain_get_ndim(ctx, domain, &dim_num);

// Get dimension by index (0 <= idx < dim_num)
tiledb_dimension_t* dim;
tiledb_domain_get_dimension_from_index(ctx, domain, idx, &dim);

// Get dimension from name
tiledb_dimension_t* dim;
tiledb_domain_get_dimension_from_name(ctx, domain, "dim", &dim);

// Check if domain has dimension with a given name
int32_t has_dim;
tiledb_domain_has_dimension(ctx, domain, "dim", &has_dim);

// Dump the domain in ASCII format in the selected output
tiledb_domain_dump(ctx, domain, stdout);

Inspecting Dimensions

You can inspect a dimensions as follows:

// ... create context ctx
// ... get array schema
// ... get domain
// ... get dimension by index or name

// Get dimension name
const char* dim_name;
tiledb_dimension_get_name(ctx, dim, &dim_name);

// Get dimension datatype
tiledb_datatype_t dim_type;
tiledb_dimension_get_type(ctx, dim, &dim_type);

// Get dimension domain
tiledb_domain_t* domain;
tiledb_dimension_get_domain(ctx, dim, &domain);

// Get tile extent
const int* tile_extent;
tiledb_dimension_get_tile_extent(ctx, dim, &tile_extent);

// Get filter list
tiledb_filter_list_t* filter_list;
tiledb_dimension_get_filter_list(ctx, dim, &filter_list);
// Make sure to call `tiledb_filter_list_free(&filter_list);`

// Dump the dimension in ASCII format in the selected output
tiledb_dimension_dump(ctx, dim, stdout);

// Make sure to delete the dimension in the end
tiledb_dimension_free(&dim);

Inspecting Attributes

You can inspect an attribute as follows:

// ... create context
// ... get array schema
// ... get attribute by index or name

// Get attribute name
const char* attr_name;
tiledb_attribute_get_name(ctx, attr, &attr_name);

// Get attribute datatype
tiledb_datatype_t attr_type;
tiledb_attribute_get_type(ctx, attr, &attr_type);

// Get filter list
tiledb_filter_list_t* filter_list;
tiledb_attribute_get_filter_list(ctx, attr, &filter_list);
// Make sure to call `tiledb_filter_list_free(&filter_list);`

// Get number of values per cell
uint32_t num;
tiledb_attribute_get_cell_val_num(ctx, attr, &num);

// Get cell size for this attribute
uint64_t cell_size;
tiledb_attribute_get_cell_size(ctx, attr, &cell_size);

// Get the fill value assuming a int32 attribute
const int32_t* value;
unsigned long long size;
tiledb_attribute_get_fill_value(ctx, attr, &value, &size);

// Get the fill value assuming a var char attribute
const char* value;
unsigned long long size;
tiledb_attribute_get_fill_value(ctx, attr, &value, &size);

// Dump the attribute in ASCII format in the selected output
tiledb_attribute_dump(ctx, dim, stdout);

// Make sure to delete the attribute in the end
tiledb_attribute_free(&attr);

Inspecting Filters

You can inspect filters as follows:

// ... create context ctx
// ... get filter list

// Get number of filters
uint32_t num_filters;
tiledb_filter_list_get_nfilters(ctx, filter_list, &num_filters);

// Get the maximum tile chunk size
uint32_t max_chunk_size;
tiledb_filter_list_get_max_chunk_size(ctx, filter_list, &max_chunk_size);

// Get a filter by index (0 <= idx < num_filters)
tiledb_filter_t* filter;
tiledb_filter_list_get_filter_from_index(ctx, filter_list, idx, &filter);

// Get filter type
tiledb_filter_type_t type;
tiledb_filter_get_type(ctx, filter, &type);

// Get filter option (depends on the filter)
int32_t level;
tiledb_filter_get_option(ctx, filter, TILEDB_COMPRESSION_LEVEL, &level);

// Make sure to delete the filter list and filter
tiledb_filter_list_free(&filter_list);
tiledb_filter_free(&filter);

Last updated