pub struct SchemaRegistry { /* private fields */ }Expand description
Thread-safe registry of table schemas.
All tables that should be replicated from OLTP to OLAP must be registered here with their Arrow schema and primary key definition.
Implementations§
Source§impl SchemaRegistry
impl SchemaRegistry
Sourcepub fn new() -> Self
pub fn new() -> Self
Create an empty SchemaRegistry.
Sourcepub fn register(&self, schema: TableSchema) -> Result<(), CoreError>
pub fn register(&self, schema: TableSchema) -> Result<(), CoreError>
Register a TableSchema.
Calls TableSchema::validate before inserting. The registry holds an
Arc clone of the schema so subsequent get calls are cheap.
§Errors
Returns CoreError::TableAlreadyRegistered if a table with the same
name is already present. Returns CoreError::SchemaValidation if
validation fails.
Sourcepub fn get(&self, table_name: &str) -> Result<Arc<TableSchema>, CoreError>
pub fn get(&self, table_name: &str) -> Result<Arc<TableSchema>, CoreError>
Look up a TableSchema by table name.
Returns an Arc clone — the call is cheap and does not copy the schema.
§Errors
Returns CoreError::TableNotFound if table_name has not been
registered.
Sourcepub fn table_names(&self) -> Vec<String>
pub fn table_names(&self) -> Vec<String>
List all registered table names.
Sourcepub fn unregister(
&self,
table_name: &str,
) -> Result<Arc<TableSchema>, CoreError>
pub fn unregister( &self, table_name: &str, ) -> Result<Arc<TableSchema>, CoreError>
Remove a table from the registry and return its schema.
§Errors
Returns CoreError::TableNotFound if table_name is not registered.
Sourcepub fn update(&self, schema: TableSchema) -> Result<(), CoreError>
pub fn update(&self, schema: TableSchema) -> Result<(), CoreError>
Replace an existing table’s schema in-place (used during schema evolution).
Validates schema before replacing. Does not apply DDL to any
engine; callers must also call the corresponding OlapEngine::add_column
/ OlapEngine::drop_column methods.
§Errors
Returns CoreError::TableNotFound if the table is not registered.
Returns CoreError::SchemaValidation if the new schema is invalid.
Sourcepub fn add_column(
&self,
table_name: &str,
column_name: &str,
data_type: DataType,
) -> Result<Arc<TableSchema>, CoreError>
pub fn add_column( &self, table_name: &str, column_name: &str, data_type: DataType, ) -> Result<Arc<TableSchema>, CoreError>
Add a nullable column to a registered table’s schema.
The column is appended at the end of the field list. New columns are always marked nullable so that existing rows (which lack the column) remain valid.
Returns the updated schema arc.
§Errors
Returns CoreError::TableNotFound if the table is not registered.
Returns CoreError::SchemaValidation if column_name is invalid or
already exists.
Sourcepub fn drop_column(
&self,
table_name: &str,
column_name: &str,
) -> Result<Arc<TableSchema>, CoreError>
pub fn drop_column( &self, table_name: &str, column_name: &str, ) -> Result<Arc<TableSchema>, CoreError>
Remove a column from a registered table’s schema.
Returns the updated schema arc. Note that the SQLite OLTP engine
requires CDC triggers to be torn down before issuing DROP COLUMN
(SQLite rejects DROP COLUMN while triggers reference the column).
§Errors
Returns CoreError::TableNotFound if the table is not registered.
Returns CoreError::SchemaValidation if column_name is a primary
key column or does not exist in the schema.
Source§impl SchemaRegistry
impl SchemaRegistry
Sourcepub fn save_to_disk(&self, path: &str) -> Result<(), CoreError>
pub fn save_to_disk(&self, path: &str) -> Result<(), CoreError>
Persist the current registry contents to a JSON file at path.
The file is written atomically via a temp file + rename so a crash mid-write cannot produce a corrupt file.
§Errors
Returns CoreError::SchemaValidation if serialization fails or the
file cannot be written or renamed (e.g., permission denied, disk full).
Sourcepub fn load_from_disk(path: &str) -> Result<SchemaRegistry, CoreError>
pub fn load_from_disk(path: &str) -> Result<SchemaRegistry, CoreError>
Load a previously persisted registry from a JSON file at path.
Returns an empty SchemaRegistry if the file does not exist (fresh
start). This design means that the first run behaves identically to
subsequent runs — no special-casing is needed at call sites.
§Errors
Returns CoreError::SchemaValidation if the file exists but cannot
be read, is not valid JSON, contains an unknown Arrow type string, or
contains schemas that fail TableSchema::validate.
Trait Implementations§
Source§impl Clone for SchemaRegistry
impl Clone for SchemaRegistry
Source§fn clone(&self) -> SchemaRegistry
fn clone(&self) -> SchemaRegistry
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more