risingwave_frontend/catalog/
mod.rsuse risingwave_common::catalog::{
is_row_id_column_name, is_system_schema, ROWID_PREFIX, RW_RESERVED_COLUMN_NAME_PREFIX,
};
use risingwave_connector::sink::catalog::SinkCatalog;
use thiserror::Error;
use crate::error::{ErrorCode, Result, RwError};
pub(crate) mod catalog_service;
pub(crate) mod connection_catalog;
pub(crate) mod database_catalog;
pub(crate) mod function_catalog;
pub(crate) mod index_catalog;
pub(crate) mod root_catalog;
pub(crate) mod schema_catalog;
pub(crate) mod source_catalog;
pub(crate) mod subscription_catalog;
pub(crate) mod system_catalog;
pub(crate) mod table_catalog;
pub(crate) mod view_catalog;
pub(crate) mod secret_catalog;
pub(crate) use catalog_service::CatalogReader;
pub use index_catalog::IndexCatalog;
pub use table_catalog::TableCatalog;
use crate::user::UserId;
pub(crate) type ConnectionId = u32;
pub(crate) type SourceId = u32;
pub(crate) type SinkId = u32;
pub(crate) type SubscriptionId = u32;
pub(crate) type ViewId = u32;
pub(crate) type DatabaseId = u32;
pub(crate) type SchemaId = u32;
pub(crate) type TableId = risingwave_common::catalog::TableId;
pub(crate) type ColumnId = risingwave_common::catalog::ColumnId;
pub(crate) type FragmentId = u32;
pub(crate) type SecretId = risingwave_common::catalog::SecretId;
pub fn check_valid_column_name(column_name: &str) -> Result<()> {
if is_row_id_column_name(column_name) {
return Err(ErrorCode::InternalError(format!(
"column name prefixed with {:?} are reserved word.",
ROWID_PREFIX
))
.into());
}
if column_name.starts_with(RW_RESERVED_COLUMN_NAME_PREFIX) {
return Err(ErrorCode::InternalError(format!(
"column name prefixed with {:?} are reserved word.",
RW_RESERVED_COLUMN_NAME_PREFIX
))
.into());
}
if ["tableoid", "xmin", "cmin", "xmax", "cmax", "ctid"].contains(&column_name) {
return Err(ErrorCode::InvalidInputSyntax(format!(
"column name \"{column_name}\" conflicts with a system column name"
))
.into());
}
Ok(())
}
pub fn check_schema_writable(schema: &str) -> Result<()> {
if is_system_schema(schema) {
Err(ErrorCode::ProtocolError(format!(
"permission denied to write on \"{}\", System catalog modifications are currently disallowed.",
schema
)).into())
} else {
Ok(())
}
}
pub type CatalogResult<T> = std::result::Result<T, CatalogError>;
#[derive(Error, Debug)]
pub enum CatalogError {
#[error("{0} not found: {1}")]
NotFound(&'static str, String),
#[error("{0} with name {1} exists")]
Duplicated(&'static str, String),
#[error("cannot drop {0} {1} because {2} {3} depend on it")]
NotEmpty(&'static str, String, &'static str, String),
}
impl From<CatalogError> for RwError {
fn from(e: CatalogError) -> Self {
ErrorCode::CatalogError(Box::new(e)).into()
}
}
pub trait OwnedByUserCatalog {
fn owner(&self) -> UserId;
}
impl OwnedByUserCatalog for SinkCatalog {
fn owner(&self) -> UserId {
self.owner.user_id
}
}