use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct DatasetSchema {
pub fields: Vec<SchemaField>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SchemaField {
pub name: String,
pub arrow_type: String,
pub nullable: bool,
}
impl DatasetSchema {
pub fn new() -> Self {
Self::default()
}
pub fn field(
mut self,
name: impl Into<String>,
arrow_type: impl Into<String>,
nullable: bool,
) -> Self {
self.fields.push(SchemaField {
name: name.into(),
arrow_type: arrow_type.into(),
nullable,
});
self
}
pub fn is_empty(&self) -> bool {
self.fields.is_empty()
}
pub fn to_sdp_schema_string(&self) -> Option<String> {
if self.fields.is_empty() {
return None;
}
Some(
self.fields
.iter()
.map(|f| format!("{} {}", f.name, f.arrow_type))
.collect::<Vec<_>>()
.join(", "),
)
}
}