use arrow::datatypes::SchemaRef;
use std::collections::HashMap;
use std::sync::Arc;
use crate::distributed::expr::ExprSchema;
use crate::error::{Error, Result};
pub struct SchemaValidator {
schemas: HashMap<String, ExprSchema>,
}
impl SchemaValidator {
pub fn new() -> Self {
Self {
schemas: HashMap::new(),
}
}
pub fn register_schema(&mut self, name: impl Into<String>, schema: ExprSchema) -> &mut Self {
self.schemas.insert(name.into(), schema);
self
}
#[cfg(feature = "distributed")]
pub fn register_arrow_schema(
&mut self,
name: impl Into<String>,
schema: SchemaRef,
) -> Result<&mut Self> {
let expr_schema = ExprSchema::from_arrow_schema(schema.as_ref())?;
self.schemas.insert(name.into(), expr_schema);
Ok(self)
}
pub fn schema(&self, name: &str) -> Option<&ExprSchema> {
self.schemas.get(name)
}
pub fn schemas(&self) -> &HashMap<String, ExprSchema> {
&self.schemas
}
}