scirs2_io/tiledb/
types.rs1#[derive(Debug, Clone)]
8pub struct TileDBConfig {
9 pub tile_capacity: usize,
11 pub compression: Compression,
13 pub tile_order: TileOrder,
15 pub cell_order: TileOrder,
17}
18
19impl Default for TileDBConfig {
20 fn default() -> Self {
21 Self {
22 tile_capacity: 1024,
23 compression: Compression::None,
24 tile_order: TileOrder::RowMajor,
25 cell_order: TileOrder::RowMajor,
26 }
27 }
28}
29
30#[non_exhaustive]
32#[derive(Debug, Clone, Copy, PartialEq, Eq)]
33pub enum Compression {
34 None,
36 Rle,
38 Dictionary,
40 Delta,
42}
43
44#[non_exhaustive]
46#[derive(Debug, Clone)]
47pub enum ArraySchema {
48 Dense {
50 dimensions: Vec<Dimension>,
52 attributes: Vec<Attribute>,
54 },
55 Sparse {
57 dimensions: Vec<Dimension>,
59 attributes: Vec<Attribute>,
61 },
62}
63
64impl ArraySchema {
65 pub fn dimensions(&self) -> &[Dimension] {
67 match self {
68 ArraySchema::Dense { dimensions, .. } => dimensions,
69 ArraySchema::Sparse { dimensions, .. } => dimensions,
70 }
71 }
72
73 pub fn attributes(&self) -> &[Attribute] {
75 match self {
76 ArraySchema::Dense { attributes, .. } => attributes,
77 ArraySchema::Sparse { attributes, .. } => attributes,
78 }
79 }
80
81 pub fn is_dense(&self) -> bool {
83 matches!(self, ArraySchema::Dense { .. })
84 }
85}
86
87#[derive(Debug, Clone)]
89pub struct Dimension {
90 pub name: String,
92 pub domain: (f64, f64),
94 pub tile_extent: f64,
96}
97
98impl Dimension {
99 pub fn new(name: &str, domain: (f64, f64), tile_extent: f64) -> Self {
101 Self {
102 name: name.to_string(),
103 domain,
104 tile_extent,
105 }
106 }
107
108 pub fn num_cells(&self) -> usize {
110 let span = self.domain.1 - self.domain.0 + 1.0;
111 if span <= 0.0 {
112 0
113 } else {
114 span as usize
115 }
116 }
117
118 pub fn num_tiles(&self) -> usize {
120 let cells = self.num_cells() as f64;
121 if self.tile_extent <= 0.0 {
122 1
123 } else {
124 (cells / self.tile_extent).ceil() as usize
125 }
126 }
127}
128
129#[derive(Debug, Clone)]
131pub struct Attribute {
132 pub name: String,
134 pub dtype: DataType,
136}
137
138impl Attribute {
139 pub fn new(name: &str, dtype: DataType) -> Self {
141 Self {
142 name: name.to_string(),
143 dtype,
144 }
145 }
146}
147
148#[non_exhaustive]
150#[derive(Debug, Clone, Copy, PartialEq, Eq)]
151pub enum DataType {
152 Float64,
154 Float32,
156 Int64,
158 Int32,
160 UInt8,
162}
163
164#[non_exhaustive]
166#[derive(Debug, Clone, Copy, PartialEq, Eq)]
167pub enum TileOrder {
168 RowMajor,
170 ColMajor,
172 Hilbert,
174}
175
176#[derive(Debug)]
178#[non_exhaustive]
179pub enum TileDBError {
180 Io(std::io::Error),
182 SchemaError(String),
184 OutOfBounds(String),
186 InvalidQuery(String),
188 Other(String),
190}
191
192impl std::fmt::Display for TileDBError {
193 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
194 match self {
195 TileDBError::Io(e) => write!(f, "TileDB I/O error: {e}"),
196 TileDBError::SchemaError(msg) => write!(f, "TileDB schema error: {msg}"),
197 TileDBError::OutOfBounds(msg) => write!(f, "TileDB out of bounds: {msg}"),
198 TileDBError::InvalidQuery(msg) => write!(f, "TileDB invalid query: {msg}"),
199 TileDBError::Other(msg) => write!(f, "TileDB error: {msg}"),
200 }
201 }
202}
203
204impl std::error::Error for TileDBError {
205 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
206 match self {
207 TileDBError::Io(e) => Some(e),
208 _ => None,
209 }
210 }
211}
212
213impl From<std::io::Error> for TileDBError {
214 fn from(e: std::io::Error) -> Self {
215 TileDBError::Io(e)
216 }
217}
218
219impl From<TileDBError> for crate::error::IoError {
220 fn from(e: TileDBError) -> Self {
221 crate::error::IoError::Other(format!("{e}"))
222 }
223}