Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove the Sized requirement on ExecutionPlan::name() #11047

Merged
merged 3 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions datafusion/core/src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,10 @@ impl DisplayAs for StatisticsExec {
}

impl ExecutionPlan for StatisticsExec {
fn name(&self) -> &'static str {
Self::static_name()
}

fn as_any(&self) -> &dyn Any {
self
}
Expand Down
4 changes: 4 additions & 0 deletions datafusion/core/src/test_util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ impl DisplayAs for UnboundedExec {
}

impl ExecutionPlan for UnboundedExec {
fn name(&self) -> &'static str {
Self::static_name()
}

fn as_any(&self) -> &dyn Any {
self
}
Expand Down
4 changes: 4 additions & 0 deletions datafusion/core/tests/custom_sources_cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ impl DisplayAs for CustomExecutionPlan {
}

impl ExecutionPlan for CustomExecutionPlan {
fn name(&self) -> &'static str {
Self::static_name()
}

fn as_any(&self) -> &dyn Any {
self
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ impl DisplayAs for CustomPlan {
}

impl ExecutionPlan for CustomPlan {
fn name(&self) -> &'static str {
Self::static_name()
}

fn as_any(&self) -> &dyn std::any::Any {
self
}
Expand Down
4 changes: 4 additions & 0 deletions datafusion/core/tests/custom_sources_cases/statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ impl DisplayAs for StatisticsValidation {
}

impl ExecutionPlan for StatisticsValidation {
fn name(&self) -> &'static str {
Self::static_name()
}

fn as_any(&self) -> &dyn Any {
self
}
Expand Down
4 changes: 4 additions & 0 deletions datafusion/core/tests/user_defined/user_defined_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,10 @@ impl DisplayAs for TopKExec {

#[async_trait]
impl ExecutionPlan for TopKExec {
fn name(&self) -> &'static str {
Self::static_name()
}

/// Return a reference to Any that can be used for downcasting
fn as_any(&self) -> &dyn Any {
self
Expand Down
29 changes: 23 additions & 6 deletions datafusion/physical-plan/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,13 @@ 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'.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we can also update the doc string to include a note about using static_name if desired to help people migrate

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point 👍 I add an implementation note section in doc string

fn name(&self) -> &'static str
where
Self: Sized,
{
Self::static_name()
}
///
/// Implementation note: this method can just proxy to
/// [`static_name`](ExecutionPlan::static_name) if no special action is
/// needed. It doesn't provide a default implementation like that because
/// this method doesn't require the `Sized` constrain to allow a wilder
/// range of use cases.
fn name(&self) -> &str;

/// Short name for the ExecutionPlan, such as 'ParquetExec'.
/// Like [`name`](ExecutionPlan::name) but can be called without an instance.
Expand Down Expand Up @@ -829,6 +830,10 @@ mod tests {
}

impl ExecutionPlan for EmptyExec {
fn name(&self) -> &'static str {
Self::static_name()
}

fn as_any(&self) -> &dyn Any {
self
}
Expand Down Expand Up @@ -881,6 +886,10 @@ mod tests {
}

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

fn static_name() -> &'static str
where
Self: Sized,
Expand Down Expand Up @@ -931,6 +940,14 @@ mod tests {
assert_eq!(renamed_exec.name(), "MyRenamedEmptyExec");
assert_eq!(RenamedEmptyExec::static_name(), "MyRenamedEmptyExec");
}

/// A compilation test to ensure that the `ExecutionPlan::name()` method can
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

/// be called from a trait object.
/// Related ticket: https://github.com/apache/datafusion/pull/11047
#[allow(dead_code)]
fn use_execution_plan_as_trait_object(plan: &dyn ExecutionPlan) {
let _ = plan.name();
}
}

pub mod test;
24 changes: 24 additions & 0 deletions datafusion/physical-plan/src/test/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ impl DisplayAs for MockExec {
}

impl ExecutionPlan for MockExec {
fn name(&self) -> &'static str {
Self::static_name()
}

fn as_any(&self) -> &dyn Any {
self
}
Expand Down Expand Up @@ -335,6 +339,10 @@ impl DisplayAs for BarrierExec {
}

impl ExecutionPlan for BarrierExec {
fn name(&self) -> &'static str {
Self::static_name()
}

fn as_any(&self) -> &dyn Any {
self
}
Expand Down Expand Up @@ -444,6 +452,10 @@ impl DisplayAs for ErrorExec {
}

impl ExecutionPlan for ErrorExec {
fn name(&self) -> &'static str {
Self::static_name()
}

fn as_any(&self) -> &dyn Any {
self
}
Expand Down Expand Up @@ -527,6 +539,10 @@ impl DisplayAs for StatisticsExec {
}

impl ExecutionPlan for StatisticsExec {
fn name(&self) -> &'static str {
Self::static_name()
}

fn as_any(&self) -> &dyn Any {
self
}
Expand Down Expand Up @@ -619,6 +635,10 @@ impl DisplayAs for BlockingExec {
}

impl ExecutionPlan for BlockingExec {
fn name(&self) -> &'static str {
Self::static_name()
}

fn as_any(&self) -> &dyn Any {
self
}
Expand Down Expand Up @@ -760,6 +780,10 @@ impl DisplayAs for PanicExec {
}

impl ExecutionPlan for PanicExec {
fn name(&self) -> &'static str {
Self::static_name()
}

fn as_any(&self) -> &dyn Any {
self
}
Expand Down