#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TimeUnit {
Second,
Millisecond,
Microsecond,
Nanosecond,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TimeZone {
Naive,
Utc,
Iana(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum LogicalType {
Bool,
Int8,
Int16,
Int32,
Int64,
UInt8,
UInt16,
UInt32,
UInt64,
Float32,
Float64,
Decimal { precision: u16, scale: i16 },
Timestamp { unit: TimeUnit, timezone: TimeZone },
Utf8,
Categorical { ordered: bool },
Binary,
FixedBinary { byte_width: u32 },
Date32,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Column {
id: u32,
name: String,
logical_type: LogicalType,
nullable: bool,
}
impl Column {
pub fn new(
id: u32,
name: impl Into<String>,
logical_type: LogicalType,
nullable: bool,
) -> Self {
Self {
id,
name: name.into(),
logical_type,
nullable,
}
}
pub fn id(&self) -> u32 {
self.id
}
pub fn name(&self) -> &str {
&self.name
}
pub fn logical_type(&self) -> &LogicalType {
&self.logical_type
}
pub fn is_nullable(&self) -> bool {
self.nullable
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Schema {
schema_id: u64,
columns: Vec<Column>,
primary_column_id: Option<u32>,
}
impl Schema {
pub fn new(schema_id: u64, columns: Vec<Column>, primary_column_id: Option<u32>) -> Self {
Self {
schema_id,
columns,
primary_column_id,
}
}
pub fn schema_id(&self) -> u64 {
self.schema_id
}
pub fn columns(&self) -> &[Column] {
&self.columns
}
pub fn column_count(&self) -> usize {
self.columns.len()
}
pub fn primary_column(&self) -> Option<&Column> {
self.primary_column_id.and_then(|id| self.column_by_id(id))
}
pub fn primary_column_id(&self) -> Option<u32> {
self.primary_column_id
}
pub fn column_by_id(&self, id: u32) -> Option<&Column> {
self.columns.iter().find(|column| column.id == id)
}
pub fn column_by_name(&self, name: &str) -> Option<&Column> {
self.columns.iter().find(|column| column.name == name)
}
}