use crate::error::Result;
use crate::execution::relation::Relation;
use arrow::array::ArrayRef;
use arrow::datatypes::Schema;
use arrow::record_batch::RecordBatch;
use std::sync::Arc;
pub(super) struct ScalarRelation {
schema: Arc<Schema>,
value: Vec<ArrayRef>,
emitted: bool,
}
impl ScalarRelation {
pub fn new(schema: Arc<Schema>, value: Vec<ArrayRef>) -> Self {
Self {
schema,
value,
emitted: false,
}
}
}
impl Relation for ScalarRelation {
fn next(&mut self) -> Result<Option<RecordBatch>> {
if self.emitted {
return Ok(None);
}
self.emitted = true;
Ok(Some(RecordBatch::try_new(
self.schema().clone(),
self.value.clone(),
)?))
}
fn schema(&self) -> &Arc<Schema> {
&self.schema
}
}