cobble_table/catalog/
contract.rs1use super::model::{CatalogSchemaId, CatalogTable, TableIdentifier};
2use crate::evolution::SchemaChange;
3use crate::{TableError, TableSchema};
4use thiserror::Error;
5
6pub type CatalogResult<T> = std::result::Result<T, CatalogError>;
7
8#[derive(Debug, Error)]
9#[non_exhaustive]
10pub enum CatalogError {
11 #[error("invalid catalog identifier: {0}")]
12 InvalidIdentifier(String),
13 #[error("namespace already exists: {0:?}")]
14 NamespaceAlreadyExists(Vec<String>),
15 #[error("namespace not found: {0:?}")]
16 NamespaceNotFound(Vec<String>),
17 #[error("namespace is not empty: {0:?}")]
18 NamespaceNotEmpty(Vec<String>),
19 #[error("table already exists: {0:?}")]
20 TableAlreadyExists(TableIdentifier),
21 #[error("table not found: {0:?}")]
22 TableNotFound(TableIdentifier),
23 #[error("catalog schema {catalog_schema_id} not found for table {table:?}")]
24 SchemaNotFound {
25 table: TableIdentifier,
26 catalog_schema_id: CatalogSchemaId,
27 },
28 #[error("invalid catalog schema evolution: {0}")]
29 InvalidSchemaEvolution(String),
30 #[error("invalid catalog metadata: {0}")]
31 InvalidMetadata(String),
32 #[error("catalog backend error: {0}")]
33 Backend(#[source] Box<dyn std::error::Error + Send + Sync>),
34 #[error(transparent)]
35 Table(#[from] TableError),
36}
37
38pub trait Catalog: Send + Sync {
40 fn create_namespace(&self, namespace: Vec<String>) -> CatalogResult<()>;
41 fn list_namespaces(&self) -> CatalogResult<Vec<Vec<String>>>;
42 fn drop_namespace(&self, namespace: &[String]) -> CatalogResult<()>;
43 fn create_table(
44 &self,
45 identifier: TableIdentifier,
46 schema: TableSchema,
47 ) -> CatalogResult<CatalogTable>;
48 fn load_table(&self, identifier: &TableIdentifier) -> CatalogResult<CatalogTable>;
49 fn load_table_schema(
50 &self,
51 identifier: &TableIdentifier,
52 catalog_schema_id: CatalogSchemaId,
53 ) -> CatalogResult<TableSchema>;
54 fn evolve_schema(
55 &self,
56 identifier: &TableIdentifier,
57 changes: Vec<SchemaChange>,
58 ) -> CatalogResult<CatalogTable>;
59 fn list_tables(&self, namespace: &[String]) -> CatalogResult<Vec<TableIdentifier>>;
60 fn table_exists(&self, identifier: &TableIdentifier) -> CatalogResult<bool>;
61 fn rename_table(
62 &self,
63 identifier: &TableIdentifier,
64 new_name: String,
65 ) -> CatalogResult<CatalogTable>;
66 fn drop_table(&self, identifier: &TableIdentifier) -> CatalogResult<()>;
67}