#[derive(Debug, Clone)]
pub struct TileDBConfig {
pub tile_capacity: usize,
pub compression: Compression,
pub tile_order: TileOrder,
pub cell_order: TileOrder,
}
impl Default for TileDBConfig {
fn default() -> Self {
Self {
tile_capacity: 1024,
compression: Compression::None,
tile_order: TileOrder::RowMajor,
cell_order: TileOrder::RowMajor,
}
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Compression {
None,
Rle,
Dictionary,
Delta,
}
#[non_exhaustive]
#[derive(Debug, Clone)]
pub enum ArraySchema {
Dense {
dimensions: Vec<Dimension>,
attributes: Vec<Attribute>,
},
Sparse {
dimensions: Vec<Dimension>,
attributes: Vec<Attribute>,
},
}
impl ArraySchema {
pub fn dimensions(&self) -> &[Dimension] {
match self {
ArraySchema::Dense { dimensions, .. } => dimensions,
ArraySchema::Sparse { dimensions, .. } => dimensions,
}
}
pub fn attributes(&self) -> &[Attribute] {
match self {
ArraySchema::Dense { attributes, .. } => attributes,
ArraySchema::Sparse { attributes, .. } => attributes,
}
}
pub fn is_dense(&self) -> bool {
matches!(self, ArraySchema::Dense { .. })
}
}
#[derive(Debug, Clone)]
pub struct Dimension {
pub name: String,
pub domain: (f64, f64),
pub tile_extent: f64,
}
impl Dimension {
pub fn new(name: &str, domain: (f64, f64), tile_extent: f64) -> Self {
Self {
name: name.to_string(),
domain,
tile_extent,
}
}
pub fn num_cells(&self) -> usize {
let span = self.domain.1 - self.domain.0 + 1.0;
if span <= 0.0 {
0
} else {
span as usize
}
}
pub fn num_tiles(&self) -> usize {
let cells = self.num_cells() as f64;
if self.tile_extent <= 0.0 {
1
} else {
(cells / self.tile_extent).ceil() as usize
}
}
}
#[derive(Debug, Clone)]
pub struct Attribute {
pub name: String,
pub dtype: DataType,
}
impl Attribute {
pub fn new(name: &str, dtype: DataType) -> Self {
Self {
name: name.to_string(),
dtype,
}
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DataType {
Float64,
Float32,
Int64,
Int32,
UInt8,
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TileOrder {
RowMajor,
ColMajor,
Hilbert,
}
#[derive(Debug)]
#[non_exhaustive]
pub enum TileDBError {
Io(std::io::Error),
SchemaError(String),
OutOfBounds(String),
InvalidQuery(String),
Other(String),
}
impl std::fmt::Display for TileDBError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
TileDBError::Io(e) => write!(f, "TileDB I/O error: {e}"),
TileDBError::SchemaError(msg) => write!(f, "TileDB schema error: {msg}"),
TileDBError::OutOfBounds(msg) => write!(f, "TileDB out of bounds: {msg}"),
TileDBError::InvalidQuery(msg) => write!(f, "TileDB invalid query: {msg}"),
TileDBError::Other(msg) => write!(f, "TileDB error: {msg}"),
}
}
}
impl std::error::Error for TileDBError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
TileDBError::Io(e) => Some(e),
_ => None,
}
}
}
impl From<std::io::Error> for TileDBError {
fn from(e: std::io::Error) -> Self {
TileDBError::Io(e)
}
}
impl From<TileDBError> for crate::error::IoError {
fn from(e: TileDBError) -> Self {
crate::error::IoError::Other(format!("{e}"))
}
}