pub mod ir;
pub mod proto;
mod query_builder;
use bytes::Bytes;
pub use ir::{IoOperation, Operation};
pub use query_builder::QueryPlanBuilder;
use crate::{
AsAny, DeltaResult, DeltaResultIteratorStatic, EngineData, Error, FileMeta, ParquetFooter,
};
pub trait PlanExecutor: AsAny {
fn execute_op(&self, op: Operation) -> DeltaResult<PlanResult>;
}
impl PlanExecutor for () {
fn execute_op(&self, _op: Operation) -> DeltaResult<PlanResult> {
Err(Error::unsupported(
"this engine does not provide a PlanExecutor",
))
}
}
pub enum PlanResult {
Data(DeltaResultIteratorStatic<Box<dyn EngineData>>),
FileMeta(DeltaResultIteratorStatic<FileMeta>),
Bytes(DeltaResultIteratorStatic<Bytes>),
ParquetFooter(ParquetFooter),
Unit,
}
impl PlanResult {
pub fn into_data(self) -> DeltaResult<DeltaResultIteratorStatic<Box<dyn EngineData>>> {
match self {
Self::Data(iter) => Ok(iter),
other => Err(other.type_mismatch("Data")),
}
}
pub fn into_file_meta(self) -> DeltaResult<DeltaResultIteratorStatic<FileMeta>> {
match self {
Self::FileMeta(iter) => Ok(iter),
other => Err(other.type_mismatch("FileMeta")),
}
}
pub fn into_bytes(self) -> DeltaResult<DeltaResultIteratorStatic<Bytes>> {
match self {
Self::Bytes(iter) => Ok(iter),
other => Err(other.type_mismatch("Bytes")),
}
}
pub fn into_parquet_footer(self) -> DeltaResult<ParquetFooter> {
match self {
Self::ParquetFooter(footer) => Ok(footer),
other => Err(other.type_mismatch("ParquetFooter")),
}
}
pub fn into_unit(self) -> DeltaResult<()> {
match self {
Self::Unit => Ok(()),
other => Err(other.type_mismatch("Unit")),
}
}
fn variant_name(&self) -> &'static str {
match self {
Self::Data(_) => "Data",
Self::FileMeta(_) => "FileMeta",
Self::Bytes(_) => "Bytes",
Self::ParquetFooter(_) => "ParquetFooter",
Self::Unit => "Unit",
}
}
fn type_mismatch(&self, expected: &'static str) -> Error {
Error::plan_result_type_mismatch(expected, self.variant_name())
}
}