Skip to content

Commit

Permalink
feat: add static_name() to ExecutionPlan (#10266)
Browse files Browse the repository at this point in the history
* feat: add static_name() to ExecutionPlan

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>

* add test to invoke from type

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>

---------

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
  • Loading branch information
waynexia authored Apr 29, 2024
1 parent b41ef20 commit c963d21
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
21 changes: 19 additions & 2 deletions datafusion/physical-plan/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,27 @@ pub mod udaf {
/// [`required_input_ordering`]: ExecutionPlan::required_input_ordering
pub trait ExecutionPlan: Debug + DisplayAs + Send + Sync {
/// Short name for the ExecutionPlan, such as 'ParquetExec'.
fn name(&self) -> &'static str {
fn name(&self) -> &'static str
where
Self: Sized,
{
Self::static_name()
}

/// Short name for the ExecutionPlan, such as 'ParquetExec'.
/// Like [`name`](ExecutionPlan::name) but can be called without an instance.
fn static_name() -> &'static str
where
Self: Sized,
{
let full_name = std::any::type_name::<Self>();
let maybe_start_idx = full_name.rfind(':');
match maybe_start_idx {
Some(start_idx) => &full_name[start_idx + 1..],
None => "UNKNOWN",
}
}

/// Returns the execution plan as [`Any`] so that it can be
/// downcast to a specific implementation.
fn as_any(&self) -> &dyn Any;
Expand Down Expand Up @@ -873,7 +886,10 @@ mod tests {
}

impl ExecutionPlan for RenamedEmptyExec {
fn name(&self) -> &'static str {
fn static_name() -> &'static str
where
Self: Sized,
{
"MyRenamedEmptyExec"
}

Expand Down Expand Up @@ -918,6 +934,7 @@ mod tests {
let schema2 = Arc::new(Schema::empty());
let renamed_exec = RenamedEmptyExec::new(schema2);
assert_eq!(renamed_exec.name(), "MyRenamedEmptyExec");
assert_eq!(RenamedEmptyExec::static_name(), "MyRenamedEmptyExec");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ type SharedGate = Arc<Gate>;

#[cfg(test)]
mod tests {
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::atomic::AtomicBool;

use futures::{task::ArcWake, FutureExt};

Expand Down

0 comments on commit c963d21

Please sign in to comment.