pub struct TableMetadata {Show 15 fields
pub table_uuid: Uuid,
pub format_version: i32,
pub location: String,
pub last_sequence_number: i64,
pub last_updated_ms: i64,
pub last_column_id: i32,
pub current_schema_id: i32,
pub schemas: Vec<Schema>,
pub default_spec_id: i32,
pub partition_specs: Vec<PartitionSpec>,
pub current_snapshot_id: Option<i64>,
pub snapshots: Vec<Snapshot>,
pub snapshot_log: Vec<SnapshotLogEntry>,
pub properties: HashMap<String, String>,
pub metrics: TableMetrics,
}Expand description
The root metadata object for a SuperTable table.
This struct contains all information needed to understand the current state of a table, including its schema history, partition specs, snapshots, and properties.
§Concurrency
The last_sequence_number field is used for optimistic concurrency control.
Each operation that modifies the table increments this counter, allowing
the catalog to detect and reject conflicting concurrent updates.
§Example
use supercore::metadata::TableMetadata;
use supercore::schema::{Schema, Field, Type};
let schema = Schema {
schema_id: 0,
fields: vec![
Field { id: 1, name: "id".into(), required: true, field_type: Type::Long },
Field { id: 2, name: "data".into(), required: false, field_type: Type::String },
],
};
let metadata = TableMetadata::builder("s3://bucket/my_table", schema)
.with_property("write.format.default", "parquet")
.build();Fields§
§table_uuid: UuidThe unique identifier for this table (UUID v4).
format_version: i32The format version of this metadata file. Used for forward/backward compatibility checks.
location: StringThe base location of the table (e.g., s3://bucket/table).
All data and metadata files are stored relative to this location.
last_sequence_number: i64Monotonically increasing sequence number for optimistic concurrency. Incremented on each metadata update operation.
last_updated_ms: i64Timestamp of the last update in milliseconds since epoch (UTC).
last_column_id: i32The highest assigned column ID across all schemas. Used to ensure new columns get unique IDs during schema evolution.
current_schema_id: i32The ID of the current (active) schema.
schemas: Vec<Schema>List of all schemas, forming the schema history. Schemas are immutable once added.
default_spec_id: i32The ID of the default partition spec.
partition_specs: Vec<PartitionSpec>List of partition specs.
current_snapshot_id: Option<i64>The ID of the current snapshot, or None if the table is empty.
snapshots: Vec<Snapshot>List of all snapshots, forming the table’s history.
snapshot_log: Vec<SnapshotLogEntry>Log of snapshot changes for auditing and time travel.
properties: HashMap<String, String>User-defined table properties. Common properties include write format, compression, etc.
metrics: TableMetricsAggregate table metrics.
Implementations§
Source§impl TableMetadata
impl TableMetadata
Sourcepub fn builder(
location: impl Into<String>,
schema: Schema,
) -> TableMetadataBuilder
pub fn builder( location: impl Into<String>, schema: Schema, ) -> TableMetadataBuilder
Creates a new TableMetadataBuilder.
Sourcepub fn current_schema(&self) -> &Schema
pub fn current_schema(&self) -> &Schema
Returns the current schema.
§Panics
Panics if the schema list is empty or the current schema ID is invalid. This should never happen with properly constructed metadata.
Sourcepub fn current_snapshot(&self) -> Option<&Snapshot>
pub fn current_snapshot(&self) -> Option<&Snapshot>
Returns the current snapshot, if any.
Sourcepub fn snapshot_at(&self, timestamp_ms: i64) -> Option<&Snapshot>
pub fn snapshot_at(&self, timestamp_ms: i64) -> Option<&Snapshot>
Returns the snapshot that was current at the given timestamp.
This enables time-travel queries by finding the most recent snapshot that was committed before the specified timestamp.
Sourcepub fn current_partition_spec(&self) -> Option<&PartitionSpec>
pub fn current_partition_spec(&self) -> Option<&PartitionSpec>
Returns the current partition spec.
Sourcepub fn add_partition_spec(&mut self, spec: PartitionSpec)
pub fn add_partition_spec(&mut self, spec: PartitionSpec)
Adds a new partition spec and sets it as the default.
Sourcepub fn increment_sequence(&mut self)
pub fn increment_sequence(&mut self)
Increments the sequence number and updates the timestamp.
This should be called before committing any metadata update.
Sourcepub fn add_snapshot(&mut self, snapshot: Snapshot)
pub fn add_snapshot(&mut self, snapshot: Snapshot)
Adds a new snapshot to the table and makes it current.
This also creates a snapshot log entry for auditing.
Sourcepub fn add_schema(&mut self, schema: Schema)
pub fn add_schema(&mut self, schema: Schema)
Adds a new schema to the table.
The schema ID must be unique. Use next_schema_id() to generate one.
Sourcepub fn next_schema_id(&self) -> i32
pub fn next_schema_id(&self) -> i32
Returns the next available schema ID.
Sourcepub fn next_column_id(&self) -> i32
pub fn next_column_id(&self) -> i32
Returns the next available column ID.
Sourcepub fn next_snapshot_id(&self) -> i64
pub fn next_snapshot_id(&self) -> i64
Returns the next available snapshot ID.
Sourcepub fn set_current_schema(
&mut self,
schema_id: i32,
) -> Result<(), MetadataError>
pub fn set_current_schema( &mut self, schema_id: i32, ) -> Result<(), MetadataError>
Sourcepub fn rollback_to(&mut self, snapshot_id: i64) -> Result<(), MetadataError>
pub fn rollback_to(&mut self, snapshot_id: i64) -> Result<(), MetadataError>
Rolls back the table to a previous snapshot.
This creates a new snapshot log entry pointing to the old snapshot, effectively making it current again without removing history.
§Errors
Returns an error if the snapshot ID doesn’t exist.
Sourcepub fn update_metrics(
&mut self,
added: &[DataFile],
deleted_paths: &HashSet<String>,
)
pub fn update_metrics( &mut self, added: &[DataFile], deleted_paths: &HashSet<String>, )
Updates the aggregate metrics based on added and deleted files.
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 moreSource§impl Debug for TableMetadata
impl Debug for TableMetadata
Source§impl<'de> Deserialize<'de> for TableMetadata
impl<'de> Deserialize<'de> for TableMetadata
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for TableMetadata
impl RefUnwindSafe for TableMetadata
impl Send for TableMetadata
impl Sync for TableMetadata
impl Unpin for TableMetadata
impl UnwindSafe for TableMetadata
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more