pub mod context;
pub mod create;
pub mod database;
pub mod drop;
pub mod entry;
pub mod memory;
pub mod profile;
pub mod system;
use std::fmt::Debug;
use std::sync::Arc;
use create::{
CreateAggregateFunctionInfo,
CreateScalarFunctionInfo,
CreateSchemaInfo,
CreateTableFunctionInfo,
CreateTableInfo,
CreateViewInfo,
};
use drop::DropInfo;
use entry::{CatalogEntry, CatalogEntryType};
use futures::Stream;
use glaredb_error::{DbError, Result};
use crate::execution::operators::PlannedOperator;
use crate::execution::planner::OperatorIdGen;
use crate::storage::storage_manager::{StorageManager, StorageTableId};
pub trait Catalog: Debug + Sync + Send {
type Schema: Schema;
fn create_schema(&self, create: &CreateSchemaInfo) -> Result<Arc<Self::Schema>>;
fn get_schema(&self, name: &str) -> Result<Option<Arc<Self::Schema>>>;
fn require_get_schema(&self, name: &str) -> Result<Arc<Self::Schema>> {
self.get_schema(name)?
.ok_or_else(|| DbError::new(format!("Missing schema '{name}'")))
}
fn drop_entry(&self, drop: &DropInfo) -> Result<Option<Arc<CatalogEntry>>>;
fn plan_create_view(
self: &Arc<Self>,
id_gen: &mut OperatorIdGen,
schema: &str,
create: CreateViewInfo,
) -> Result<PlannedOperator>;
fn plan_create_table(
self: &Arc<Self>,
storage: &Arc<StorageManager>,
id_gen: &mut OperatorIdGen,
schema: &str,
create: CreateTableInfo,
) -> Result<PlannedOperator>;
fn plan_create_table_as(
self: &Arc<Self>,
storage: &Arc<StorageManager>,
id_gen: &mut OperatorIdGen,
schema: &str,
create: CreateTableInfo,
) -> Result<PlannedOperator>;
fn plan_insert(
self: &Arc<Self>,
storage: &Arc<StorageManager>,
id_gen: &mut OperatorIdGen,
entry: Arc<CatalogEntry>,
) -> Result<PlannedOperator>;
fn plan_create_schema(
self: &Arc<Self>,
id_gen: &mut OperatorIdGen,
create: CreateSchemaInfo,
) -> Result<PlannedOperator>;
fn plan_drop(
self: &Arc<Self>,
storage: &Arc<StorageManager>,
id_gen: &mut OperatorIdGen,
drop: DropInfo,
) -> Result<PlannedOperator>;
fn list_schemas(
self: &Arc<Self>,
) -> impl Stream<Item = Result<Vec<Arc<Self::Schema>>>> + Sync + Send + 'static;
}
pub trait Schema: Debug + Sync + Send {
fn as_entry(&self) -> Arc<CatalogEntry>;
fn create_table(
&self,
create: &CreateTableInfo,
storage_id: StorageTableId,
) -> Result<Arc<CatalogEntry>>;
fn create_view(&self, create: &CreateViewInfo) -> Result<Arc<CatalogEntry>>;
fn create_scalar_function(
&self,
create: &CreateScalarFunctionInfo,
) -> Result<Arc<CatalogEntry>>;
fn create_aggregate_function(
&self,
create: &CreateAggregateFunctionInfo,
) -> Result<Arc<CatalogEntry>>;
fn create_table_function(&self, create: &CreateTableFunctionInfo) -> Result<Arc<CatalogEntry>>;
fn get_table_or_view(&self, name: &str) -> Result<Option<Arc<CatalogEntry>>>;
fn require_get_table(&self, name: &str) -> Result<Arc<CatalogEntry>> {
let ent = self
.get_table_or_view(name)?
.ok_or_else(|| DbError::new(format!("Missing table '{name}'")))?;
if ent.entry_type() != CatalogEntryType::Table {
return Err(DbError::new(format!("'{name}' is not a table")));
}
Ok(ent)
}
fn get_table_function(&self, name: &str) -> Result<Option<Arc<CatalogEntry>>>;
fn get_inferred_table_function(&self, path: &str) -> Result<Option<Arc<CatalogEntry>>>;
fn get_function(&self, name: &str) -> Result<Option<Arc<CatalogEntry>>>;
fn get_scalar_function(&self, name: &str) -> Result<Option<Arc<CatalogEntry>>>;
fn get_aggregate_function(&self, name: &str) -> Result<Option<Arc<CatalogEntry>>>;
fn find_similar_entry(
&self,
entry_types: &[CatalogEntryType],
name: &str,
) -> Result<Option<Arc<CatalogEntry>>>;
fn list_entries(
self: &Arc<Self>,
) -> impl Stream<Item = Result<Vec<Arc<CatalogEntry>>>> + Sync + Send + 'static;
fn list_tables(
self: &Arc<Self>,
) -> impl Stream<Item = Result<Vec<Arc<CatalogEntry>>>> + Sync + Send + 'static;
}