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

Conversation

waynexia
Copy link
Member

@waynexia waynexia commented Jun 21, 2024

Which issue does this PR close?

Follow-up of #10266

Rationale for this change

#10266 tries to provide a default implementation based on static_name(). This propagates the Sized requirement to name() and prohibits it from being called by a trait object.

What changes are included in this PR?

Remove the default implementation of ExecutionPlan::name() and let every implementor implement their own based on static_name() to workaround object safety requirements. This is something like as_any().

This solution is not elegant, but I can only find this way to suit both (1) invoke from trait object and (2) invoke from type name. Please add your suggestion if there is any better way to do so. Thanks in advance!

Are these changes tested?

Are there any user-facing changes?

Yes, for those who implements ExecutionPlan, they need to add a new method on impl

@github-actions github-actions bot added the core Core DataFusion crate label Jun 21, 2024
@matthewmturner
Copy link
Contributor

Could we add a test to show that name can we called within a ExecutionPlanVisitor which i believe is a common use case.

datafusion/physical-plan/src/lib.rs Outdated Show resolved Hide resolved
@@ -116,12 +116,7 @@ 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

waynexia and others added 2 commits June 22, 2024 01:37
@waynexia
Copy link
Member Author

Could we add a test to show that name can we called within a ExecutionPlanVisitor which i believe is a common use case.

Certainly 👍 Add a compilation test use_execution_plan_as_trait_object in a3bc903

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Looks good to me -- thank you @waynexia and @matthewmturner

@@ -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.

👍

@alamb alamb added the api change Changes the API exposed to users of the crate label Jun 22, 2024
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Looks great to me -- thank you @waynexia and @matthewmturner

@alamb alamb merged commit a19fc62 into apache:main Jun 23, 2024
23 checks passed
@waynexia
Copy link
Member Author

Thanks @matthewmturner @alamb ❤️

@waynexia waynexia deleted the improve-static-name branch June 24, 2024 07:27
findepi pushed a commit to findepi/datafusion that referenced this pull request Jul 16, 2024
)

* fix: remove the Sized requirement on ExecutionPlan::name()

Signed-off-by: Ruihang Xia <[email protected]>

* Update datafusion/physical-plan/src/lib.rs

Co-authored-by: Andrew Lamb <[email protected]>

* add document and test

Signed-off-by: Ruihang Xia <[email protected]>

---------

Signed-off-by: Ruihang Xia <[email protected]>
Co-authored-by: Andrew Lamb <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api change Changes the API exposed to users of the crate core Core DataFusion crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants