Skip to main content

delta_kernel/engine/plans/
mod.rs

1//! This module contains an implementation of the Engine trait that is
2//! backed by a PlanExecutor. The engine delegates handler operations
3//! (e.g. storage, JSON, parquet) to declarative plan execution rather than implementing
4//! each handler independently.
5//!
6//! This allows a PlanExecutor to become the single surface for connector optimizations,
7//! while still allowing kernel to use existing Engine trait APIs.
8//!
9//! ### Arrow Requirement:
10//! The PlanBasedEngine implementation assumes the use of ArrowEngineData during JSON parsing, so it
11//! is only compatible with `PlanExecutor`'s which return ArrowEngineData.
12
13use std::sync::Arc;
14
15pub mod json;
16pub mod parquet;
17pub mod storage;
18
19use json::PlanBasedJsonHandler;
20use parquet::PlanBasedParquetHandler;
21use storage::PlanBasedStorageHandler;
22
23use crate::plans::PlanExecutor;
24use crate::{Engine, EvaluationHandler, JsonHandler, ParquetHandler, StorageHandler};
25
26/// An [`Engine`] that routes operations through a [`PlanExecutor`].
27///
28/// Storage, JSON file reads, and Parquet file reads are converted into
29/// [`Operation`](crate::plans::Operation)s and delegated to the plan executor.
30///
31/// EvaluationHandler capabilities are not supported under plan execution,
32/// so the engine must provide an EvaluationHandler as well.
33pub struct PlanBasedEngine {
34    executor: Arc<dyn PlanExecutor>,
35    evaluation: Arc<dyn EvaluationHandler>,
36    storage: Arc<PlanBasedStorageHandler>,
37    json: Arc<PlanBasedJsonHandler>,
38    parquet: Arc<PlanBasedParquetHandler>,
39}
40
41impl PlanBasedEngine {
42    pub fn new(
43        evaluation_handler: Arc<dyn EvaluationHandler>,
44        plan_executor: Arc<dyn PlanExecutor>,
45    ) -> Self {
46        Self {
47            evaluation: evaluation_handler,
48            storage: Arc::new(PlanBasedStorageHandler::new(plan_executor.clone())),
49            json: Arc::new(PlanBasedJsonHandler::new(plan_executor.clone())),
50            parquet: Arc::new(PlanBasedParquetHandler::new(plan_executor.clone())),
51            executor: plan_executor,
52        }
53    }
54}
55
56impl Engine for PlanBasedEngine {
57    fn evaluation_handler(&self) -> Arc<dyn EvaluationHandler> {
58        self.evaluation.clone()
59    }
60
61    fn storage_handler(&self) -> Arc<dyn StorageHandler> {
62        self.storage.clone()
63    }
64
65    fn json_handler(&self) -> Arc<dyn JsonHandler> {
66        self.json.clone()
67    }
68
69    fn parquet_handler(&self) -> Arc<dyn ParquetHandler> {
70        self.parquet.clone()
71    }
72
73    fn plan_executor(&self) -> Arc<dyn PlanExecutor> {
74        self.executor.clone()
75    }
76}