-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: write metrics extension planner
Signed-off-by: Ion Koutsouris <15728914+ion-elgreco@users.noreply.github.com> Signed-off-by: Liam Brannigan <liambrannigan@Liams-MacBook-Pro.local>
- Loading branch information
1 parent
09f05fd
commit 382d9e5
Showing
8 changed files
with
102 additions
and
52 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
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,45 @@ | ||
use std::sync::Arc; | ||
|
||
use async_trait::async_trait; | ||
use datafusion::{ | ||
execution::SessionState, | ||
physical_planner::{ExtensionPlanner, PhysicalPlanner}, | ||
}; | ||
use datafusion_common::Result as DataFusionResult; | ||
use datafusion_expr::{LogicalPlan, UserDefinedLogicalNode}; | ||
use datafusion_physical_plan::{metrics::MetricBuilder, ExecutionPlan}; | ||
|
||
use crate::delta_datafusion::{logical::MetricObserver, physical::MetricObserverExec}; | ||
|
||
pub(crate) const SOURCE_COUNT_ID: &str = "write_source_count"; | ||
pub(crate) const SOURCE_COUNT_METRIC: &str = "num_source_rows"; | ||
|
||
#[derive(Clone, Debug)] | ||
pub(crate) struct WriteMetricExtensionPlanner {} | ||
|
||
#[async_trait] | ||
impl ExtensionPlanner for WriteMetricExtensionPlanner { | ||
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>>> { | ||
if let Some(metric_observer) = node.as_any().downcast_ref::<MetricObserver>() { | ||
if metric_observer.id.eq(SOURCE_COUNT_ID) { | ||
return Ok(Some(MetricObserverExec::try_new( | ||
SOURCE_COUNT_ID.into(), | ||
physical_inputs, | ||
|batch, metrics| { | ||
MetricBuilder::new(metrics) | ||
.global_counter(SOURCE_COUNT_METRIC) | ||
.add(batch.num_rows()); | ||
}, | ||
)?)); | ||
} | ||
} | ||
Ok(None) | ||
} | ||
} |
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
Oops, something went wrong.