pub struct TableMetadata {
pub table_id: u32,
pub name: String,
pub catalog_name: String,
pub namespace_name: String,
pub table_type: TableType,
pub data_source_format: DataSourceFormat,
pub columns: Vec<ColumnMetadata>,
pub primary_key: Option<Vec<String>>,
pub storage_options: StorageOptions,
pub storage_location: Option<String>,
pub comment: Option<String>,
pub properties: HashMap<String, String>,
}Expand description
Metadata for a table in the catalog.
Contains the table ID, name, column definitions, and optional primary key constraint.
§Examples
use alopex_sql::catalog::{TableMetadata, ColumnMetadata};
use alopex_sql::planner::types::ResolvedType;
let columns = vec![
ColumnMetadata::new("id", ResolvedType::Integer)
.with_primary_key(true)
.with_not_null(true),
ColumnMetadata::new("name", ResolvedType::Text)
.with_not_null(true),
];
let table = TableMetadata::new("users", columns)
.with_primary_key(vec!["id".to_string()]);
assert_eq!(table.name, "users");
assert!(table.get_column("id").is_some());
assert_eq!(table.column_names(), vec!["id", "name"]);Fields§
§table_id: u32Unique table ID assigned by the catalog.
name: StringTable name.
catalog_name: StringCatalog name.
namespace_name: StringNamespace name.
table_type: TableTypeTable type.
data_source_format: DataSourceFormatData source format.
columns: Vec<ColumnMetadata>Column definitions (order is preserved).
primary_key: Option<Vec<String>>Primary key columns (supports composite keys).
storage_options: StorageOptionsStorage configuration (row/columnar, compression, row group sizing).
storage_location: Option<String>Storage location path.
comment: Option<String>Comment.
properties: HashMap<String, String>Custom properties.
Implementations§
Source§impl TableMetadata
impl TableMetadata
Sourcepub fn new(name: impl Into<String>, columns: Vec<ColumnMetadata>) -> Self
pub fn new(name: impl Into<String>, columns: Vec<ColumnMetadata>) -> Self
Create a new table metadata with the given name and columns.
The table_id defaults to 0; use with_table_id() to set it,
or it will be assigned by the Catalog when the table is created.
Sourcepub fn with_table_id(self, table_id: u32) -> Self
pub fn with_table_id(self, table_id: u32) -> Self
Set the table ID.
Sourcepub fn with_primary_key(self, columns: Vec<String>) -> Self
pub fn with_primary_key(self, columns: Vec<String>) -> Self
Set the primary key columns.
Sourcepub fn get_column(&self, name: &str) -> Option<&ColumnMetadata>
pub fn get_column(&self, name: &str) -> Option<&ColumnMetadata>
Get a column by name.
Returns None if the column doesn’t exist.
§Examples
use alopex_sql::catalog::{TableMetadata, ColumnMetadata};
use alopex_sql::planner::types::ResolvedType;
let table = TableMetadata::new("users", vec![
ColumnMetadata::new("id", ResolvedType::Integer),
ColumnMetadata::new("name", ResolvedType::Text),
]);
assert!(table.get_column("id").is_some());
assert!(table.get_column("unknown").is_none());Sourcepub fn get_column_index(&self, name: &str) -> Option<usize>
pub fn get_column_index(&self, name: &str) -> Option<usize>
Get the index of a column by name.
Returns None if the column doesn’t exist.
Sourcepub fn column_names(&self) -> Vec<&str>
pub fn column_names(&self) -> Vec<&str>
Get a list of all column names in definition order.
§Examples
use alopex_sql::catalog::{TableMetadata, ColumnMetadata};
use alopex_sql::planner::types::ResolvedType;
let table = TableMetadata::new("users", vec![
ColumnMetadata::new("id", ResolvedType::Integer),
ColumnMetadata::new("name", ResolvedType::Text),
ColumnMetadata::new("age", ResolvedType::Integer),
]);
assert_eq!(table.column_names(), vec!["id", "name", "age"]);Sourcepub fn column_count(&self) -> usize
pub fn column_count(&self) -> usize
Get the number of columns in the table.
Trait Implementations§
Source§impl Clone for TableMetadata
impl Clone for TableMetadata
Source§fn clone(&self) -> TableMetadata
fn clone(&self) -> TableMetadata
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more