use std::cell::RefCell;
use std::rc::Rc;
use std::sync::Arc;
use arrow::datatypes::Schema;
use arrow::record_batch::RecordBatch;
use super::datasource::DataSource;
use super::error::Result;
pub trait Relation {
fn next(&mut self) -> Result<Option<RecordBatch>>;
fn schema(&self) -> &Arc<Schema>;
}
pub struct DataSourceRelation {
schema: Arc<Schema>,
ds: Rc<RefCell<DataSource>>,
}
impl DataSourceRelation {
pub fn new(ds: Rc<RefCell<DataSource>>) -> Self {
let schema = ds.borrow().schema().clone();
Self { ds, schema }
}
}
impl Relation for DataSourceRelation {
fn next(&mut self) -> Result<Option<RecordBatch>> {
self.ds.borrow_mut().next()
}
fn schema(&self) -> &Arc<Schema> {
&self.schema
}
}