-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ca0de0
commit 6488b82
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//! Custom planners for datafusion so that you can convert custom nodes, can be used | ||
//! to trace custom metrics in an operation | ||
//! | ||
//! # Example | ||
//! | ||
//! #[derive(Clone)] | ||
//! struct MergeMetricExtensionPlanner {} | ||
//! | ||
//! #[async_trait] | ||
//! impl ExtensionPlanner for MergeMetricExtensionPlanner { | ||
//! async fn plan_extension( | ||
//! &self, | ||
//! planner: &dyn PhysicalPlanner, | ||
//! node: &dyn UserDefinedLogicalNode, | ||
//! _logical_inputs: &[&LogicalPlan], | ||
//! physical_inputs: &[Arc<dyn ExecutionPlan>], | ||
//! session_state: &SessionState, | ||
//! ) -> DataFusionResult<Option<Arc<dyn ExecutionPlan>>> {} | ||
//! | ||
//! let merge_planner = DeltaPlanner::<MergeMetricExtensionPlanner> { | ||
//! extension_planner: MergeMetricExtensionPlanner {} | ||
//! }; | ||
//! | ||
//! let state = state.with_query_planner(Arc::new(merge_planner)); | ||
use std::sync::Arc; | ||
|
||
use crate::delta_datafusion::DataFusionResult; | ||
use async_trait::async_trait; | ||
use datafusion::physical_planner::PhysicalPlanner; | ||
use datafusion::{ | ||
execution::{context::QueryPlanner, session_state::SessionState}, | ||
physical_plan::ExecutionPlan, | ||
physical_planner::{DefaultPhysicalPlanner, ExtensionPlanner}, | ||
}; | ||
use datafusion_expr::LogicalPlan; | ||
|
||
/// Deltaplanner | ||
pub struct DeltaPlanner<T: ExtensionPlanner> { | ||
/// custom extension planner | ||
pub extension_planner: T, | ||
} | ||
|
||
#[async_trait] | ||
impl<T: ExtensionPlanner + std::marker::Send + Sync + 'static + Clone> QueryPlanner | ||
for DeltaPlanner<T> | ||
{ | ||
async fn create_physical_plan( | ||
&self, | ||
logical_plan: &LogicalPlan, | ||
session_state: &SessionState, | ||
) -> DataFusionResult<Arc<dyn ExecutionPlan>> { | ||
let planner = Arc::new(Box::new(DefaultPhysicalPlanner::with_extension_planners( | ||
vec![Arc::new(self.extension_planner.clone())], | ||
))); | ||
planner | ||
.create_physical_plan(logical_plan, session_state) | ||
.await | ||
} | ||
} |