mod database;
mod factory;
mod filesystem;
mod rest;
use std::collections::HashMap;
use std::fmt;
pub use database::*;
pub use factory::*;
pub use filesystem::*;
pub use rest::*;
use serde::{Deserialize, Serialize};
pub const SYSTEM_TABLE_SPLITTER: &str = "$";
pub const SYSTEM_BRANCH_PREFIX: &str = "branch_";
pub const DEFAULT_MAIN_BRANCH: &str = "main";
pub const UNKNOWN_DATABASE: &str = "unknown";
pub const DB_LOCATION_PROP: &str = "location";
pub const DB_SUFFIX: &str = ".db";
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Identifier {
database: String,
object: String,
}
impl Identifier {
pub fn new(database: impl Into<String>, object: impl Into<String>) -> Self {
Self {
database: database.into(),
object: object.into(),
}
}
pub fn database(&self) -> &str {
&self.database
}
pub fn object(&self) -> &str {
&self.object
}
pub fn full_name(&self) -> String {
if self.database == UNKNOWN_DATABASE {
self.object.clone()
} else {
format!("{}.{}", self.database, self.object)
}
}
}
impl fmt::Display for Identifier {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.full_name())
}
}
impl fmt::Debug for Identifier {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Identifier")
.field("database", &self.database)
.field("object", &self.object)
.finish()
}
}
use async_trait::async_trait;
use crate::spec::{Schema, SchemaChange};
use crate::table::Table;
use crate::Result;
#[async_trait]
pub trait Catalog: Send + Sync {
async fn list_databases(&self) -> Result<Vec<String>>;
async fn create_database(
&self,
name: &str,
ignore_if_exists: bool,
properties: HashMap<String, String>,
) -> Result<()>;
async fn get_database(&self, name: &str) -> Result<Database>;
async fn drop_database(
&self,
name: &str,
ignore_if_not_exists: bool,
cascade: bool,
) -> Result<()>;
async fn get_table(&self, identifier: &Identifier) -> Result<Table>;
async fn list_tables(&self, database_name: &str) -> Result<Vec<String>>;
async fn create_table(
&self,
identifier: &Identifier,
creation: Schema,
ignore_if_exists: bool,
) -> Result<()>;
async fn drop_table(&self, identifier: &Identifier, ignore_if_not_exists: bool) -> Result<()>;
async fn rename_table(
&self,
from: &Identifier,
to: &Identifier,
ignore_if_not_exists: bool,
) -> Result<()>;
async fn alter_table(
&self,
identifier: &Identifier,
changes: Vec<SchemaChange>,
ignore_if_not_exists: bool,
) -> Result<()>;
}