Skip to main content

TableSchema

Struct TableSchema 

Source
pub struct TableSchema {
    pub keyspace: String,
    pub table: String,
    pub partition_keys: Vec<KeyColumn>,
    pub clustering_keys: Vec<ClusteringColumn>,
    pub columns: Vec<Column>,
    pub comments: HashMap<String, String>,
    pub dropped_columns: HashMap<String, i64>,
}
Expand description

Table schema definition loaded from JSON

Fields§

§keyspace: String

Keyspace name

§table: String

Table name

§partition_keys: Vec<KeyColumn>

Partition key columns (ordered)

§clustering_keys: Vec<ClusteringColumn>

Clustering key columns (ordered)

§columns: Vec<Column>

All columns in the table

§comments: HashMap<String, String>

Optional metadata

§dropped_columns: HashMap<String, i64>

Dropped-column drop times in microseconds (column name → drop_time_micros).

Populated from the schema-loading surface (JSON dropped_columns, or set programmatically) since drop times are assigned at DDL-execution by the cluster catalog (system_schema.dropped_columns) and are not recorded in local SSTable files or the CQL DROP COLUMN text. Used during compaction to discard cells of a dropped column whose timestamp ≤ the drop time (Cassandra cb34ad47). See issues #904 (this plumbing) and #847 (the merge-side filter).

Scope (#847): this map carries only the drop time, so the dropped column’s pre-drop cells are decoded using its CURRENT type in Self::columns (the decode contract enforced by Self::validate_dropped_columns). That is byte-correct when the column’s type is unchanged — the common case. A column dropped and later RE-ADDED with a DIFFERENT type is out of scope: the historical cells would be decoded with the new type and could misparse. Supporting per-version types requires carrying type metadata here (or decoding from the SSTable serialization-header type) and is follow-up work alongside the element-level representation in #899.

Filtering is also at row-timestamp granularity (the merge stream surfaces only the row write-time per cell); exact per-cell purging is tracked as follow-up #922.

Implementations§

Source§

impl TableSchema

Source

pub fn ordered_partition_keys(&self) -> Vec<&KeyColumn>

Get partition key columns ordered by position.

Returns the same order as a full sort_by_key(position) would, but skips the sort when the keys are already in ascending position order (the common case — see the module docs), so it is no longer re-sorted per call.

Source

pub fn ordered_clustering_keys(&self) -> Vec<&ClusteringColumn>

Get clustering key columns ordered by position.

Same order as before; the sort is skipped when the keys are already ordered.

Source§

impl TableSchema

Source

pub fn get_column_comparator(&self, column_name: &str) -> Result<ComparatorType>

Get ComparatorType for a specific column

Source

pub fn get_all_comparators(&self) -> Result<HashMap<String, ComparatorType>>

Get ComparatorTypes for all columns

Source

pub fn get_partition_key_comparators(&self) -> Result<Vec<ComparatorType>>

Get ComparatorTypes for partition key columns in order

Source

pub fn get_clustering_key_comparators(&self) -> Result<Vec<ComparatorType>>

Get ComparatorTypes for clustering key columns in order

Source

pub fn is_column_type_compatible( &self, column_name: &str, expected_type: &str, ) -> Result<bool>

Check if a column type is compatible with an expected type

Source§

impl TableSchema

Source

pub fn from_sstable_header(header: &SSTableHeader) -> Result<Self>

Extract schema from SSTable header column metadata

This method constructs a TableSchema from the column information embedded in the SSTable header’s SerializationHeader.

Source

pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self>

Load schema from JSON file

Source

pub fn from_json(json: &str) -> Result<Self>

Parse schema from JSON string

Source

pub fn to_file<P: AsRef<Path>>(&self, path: P) -> Result<()>

Save schema to JSON file

Source

pub fn validate(&self) -> Result<()>

Validate schema consistency

Source

pub fn for_compaction_output(&self, retained: &HashSet<String>) -> TableSchema

The post-drop schema that compaction uses to write its output.

The decode schema retains dropped columns (carrying their type) so input cells can be parsed and then purged by the merge filter (see Self::validate_dropped_columns). The compaction output must keep its serialization header / row column bitmap consistent with the cells that actually survive the merge:

  • A dropped column with no surviving cells (all cells were at or before its drop time) is removed from columns so it does not appear in the output header. This lets a natural post-drop reader schema (which omits the column) read the output without the header-column / bitmap-index misalignment that retaining it would cause (roborev #847).
  • A dropped column with surviving cells (re-added: cells written after drop_time) is RETAINED in columns, because the merge still emits those cells and the writer needs a matching header column — otherwise the cell would be serialized with no header entry and corrupt the row.

retained is the set of dropped-column names that had surviving cells (computed by compact_sstables from a merge pre-pass). The returned schema carries an empty dropped_columns map: the purge has already happened, so the output must not re-purge the surviving cells on a later compaction.

Source

pub fn validate_dropped_columns(&self) -> Result<()>

Validate the dropped-column decode contract (#904/#847).

Dropped-column filtering during compaction discards a dropped column’s cells after they are decoded. The schema-driven reader only decodes a column whose name is present in Self::columns (it intersects the on-disk serialization-header columns with the schema); a column absent from columns is skipped without consuming its bytes, so its cells would never reach the filter and surrounding columns could misalign.

Therefore every column named in dropped_columns MUST remain declared in columns (carrying its type) so its cells decode and can be purged. This mirrors Cassandra retaining a dropped column’s type in system_schema.dropped_columns. Decoding a dropped column that is absent from columns (purely from header type metadata) is follow-up work related to #899 and intentionally out of scope here.

Source

pub fn validate_udt_references(&self, registry: &UdtRegistry) -> Result<()>

Validate that every UDT referenced by a column exists in the registry.

This is a schema-load-time pass that fails fast with a schema-category error naming the missing UDT, instead of surfacing the problem later as a confusing parse/deserialization error (issue #761). Nested references are validated recursively: a UDT inside a collection, frozen<>, a tuple, or another UDT is checked just like a top-level reference.

UDTs are looked up in the schema’s own keyspace; the system keyspace is also consulted so built-in/system UDTs resolve regardless of the table’s keyspace.

Source

pub fn get_column(&self, name: &str) -> Option<&Column>

Get column by name

Source

pub fn is_partition_key(&self, name: &str) -> bool

Check if column is a partition key

Source

pub fn is_clustering_key(&self, name: &str) -> bool

Check if column is a clustering key

Trait Implementations§

Source§

impl Clone for TableSchema

Source§

fn clone(&self) -> TableSchema

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl CqlVisitor<TableSchema> for SchemaBuilderVisitor

Source§

impl Debug for TableSchema

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for TableSchema

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for TableSchema

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more