pub struct MeasurementSchema { /* private fields */ }Expand description
Schema for a single measurement (table).
Contains an ordered list of column definitions. The first column is always
the timestamp. Tags and fields follow. Columns are private to preserve
invariants — use add_tag() and
add_field() for modification.
Implementations§
Source§impl MeasurementSchema
impl MeasurementSchema
Sourcepub fn new(measurement: impl Into<String>) -> Self
pub fn new(measurement: impl Into<String>) -> Self
Create a new schema with just the timestamp column.
Sourcepub fn measurement(&self) -> &str
pub fn measurement(&self) -> &str
Returns the measurement name.
Sourcepub fn columns(&self) -> &[ColumnDef]
pub fn columns(&self) -> &[ColumnDef]
Returns the column definitions (timestamp first, then tags, then fields).
Sourcepub fn add_tag(&mut self, name: &str) -> bool
pub fn add_tag(&mut self, name: &str) -> bool
Add a tag column if it doesn’t already exist.
Returns true if the tag was newly added, false if it already
exists as a tag. Logs a warning if the name conflicts
with an existing field column.
Sourcepub fn add_field(
&mut self,
name: &str,
field_value: &FieldValue,
) -> Result<bool, SchemaError>
pub fn add_field( &mut self, name: &str, field_value: &FieldValue, ) -> Result<bool, SchemaError>
Add a field column if it doesn’t already exist.
§Errors
Returns SchemaError::TypeConflict if the field already exists with a
different type.
Sourcepub fn declare_field(
&mut self,
name: &str,
column_type: ColumnType,
) -> Result<bool, SchemaError>
pub fn declare_field( &mut self, name: &str, column_type: ColumnType, ) -> Result<bool, SchemaError>
Add a field column with an explicit type.
The type-first form of add_field: it is how a
decimal column gets the scale it needs before the first value
arrives, and how a batch that introduces a decimal field creates the
column at the widest scale the batch carries rather than at whatever
scale the first point happened to have.
Returns true if the column was newly added, false if it already
existed with exactly this type.
§Errors
SchemaError::TypeConflict if the name already exists as a tag or
with a different type — including a decimal with a different scale,
which is a different type.
Sourcepub fn column(&self, name: &str) -> Option<&ColumnDef>
pub fn column(&self, name: &str) -> Option<&ColumnDef>
Look up a column by name — O(1) via the column index.
Sourcepub fn push_column(&mut self, col: ColumnDef)
pub fn push_column(&mut self, col: ColumnDef)
Push a pre-built column definition (e.g. during WAL replay).
Silently ignores duplicates.
Sourcepub fn field_count(&self) -> usize
pub fn field_count(&self) -> usize
Returns the number of field columns.
Sourcepub fn field_names(&self) -> Vec<&str>
pub fn field_names(&self) -> Vec<&str>
Returns the names of all field columns.
Trait Implementations§
Source§impl Clone for MeasurementSchema
impl Clone for MeasurementSchema
Source§fn clone(&self) -> MeasurementSchema
fn clone(&self) -> MeasurementSchema
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more