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

Improve EnforceSorting docs. #14673

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

wiedld
Copy link
Contributor

@wiedld wiedld commented Feb 14, 2025

Which issue does this PR close?

Helps with the docs effort #7013.

Rationale for this change

Noticed while reviewing #14650, that some of the EnforceSorting docs could be improved.

What changes are included in this PR?

Only docs. No code.

Are these changes tested?

N/A

Are there any user-facing changes?

N/A

@github-actions github-actions bot added physical-expr Physical Expressions optimizer Optimizer rules labels Feb 14, 2025
Comment on lines 134 to 136
// TODO(xudong963): the plans are not mutated, only the `data` attribute is set.
// Therefore this should be called before this function.
node_and_ctx.update_plan_from_children()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll update this after @xudong963 's PR #14650 merges.

Copy link
Contributor

Choose a reason for hiding this comment

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

FYI maybe we could do something like I suggest here

To avoid having to remember to call update_plan_from_children as much

Copy link
Contributor Author

@wiedld wiedld Feb 15, 2025

Choose a reason for hiding this comment

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

I removed this TODO comment, since we'll have a race anyways btwn which PR merges first. 😉

@wiedld wiedld changed the title Update EnforceSorting docs. Improve EnforceSorting docs. Feb 14, 2025
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.

Thank you @wiedld -- this looks great

cc @xudong963

/// whether we elect to transform [`CoalescePartitionsExec`] + [`SortExec`] cascades
/// into [`SortExec`] + [`SortPreservingMergeExec`] cascades, which enables us to
/// perform sorting in parallel.
/// If `repartition_sorts` is enabled,
Copy link
Contributor

Choose a reason for hiding this comment

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

😍

Copy link
Contributor

Choose a reason for hiding this comment

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

This is greaet -- thank you @wiedld

I am not sure it will be rendered as a doc if it is listed on the impl -- perhaps it would be better here:

https://github.com/apache/datafusion/blob/a104661a020b895eb155af12575bafe693b8edaf/datafusion/physical-optimizer/src/enforce_sorting/mod.rs#L129-L128

Copy link
Contributor Author

@wiedld wiedld Feb 15, 2025

Choose a reason for hiding this comment

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

I need to fix up these docs more than this, since the flowcharts refer to the parallelize_sorts part of EnforceSorting, and not to everything that this optimization pass does. Done. @alamb you may want to take another look.

Comment on lines 134 to 136
// TODO(xudong963): the plans are not mutated, only the `data` attribute is set.
// Therefore this should be called before this function.
node_and_ctx.update_plan_from_children()
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI maybe we could do something like I suggest here

To avoid having to remember to call update_plan_from_children as much

datafusion/physical-optimizer/src/enforce_sorting/mod.rs Outdated Show resolved Hide resolved
datafusion/physical-optimizer/src/enforce_sorting/mod.rs Outdated Show resolved Hide resolved
datafusion/physical-optimizer/src/enforce_sorting/mod.rs Outdated Show resolved Hide resolved
datafusion/physical-optimizer/src/enforce_sorting/mod.rs Outdated Show resolved Hide resolved
/// A node context object beneficial for writing optimizer rules.
/// This context encapsulating an [`ExecutionPlan`] node with a payload.
///
/// Since each wrapped node has it's children within both the [`PlanContext.plan.children()`],
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

this is indeed quite subtle -- it would be awesome if we could find some way to make it harder to forget to call update_plan_from_children

@alamb alamb added the documentation Improvements or additions to documentation label Feb 14, 2025
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Feb 15, 2025
@wiedld wiedld marked this pull request as ready for review February 15, 2025 05:37
/// whether we elect to transform [`CoalescePartitionsExec`] + [`SortExec`] cascades
/// into [`SortExec`] + [`SortPreservingMergeExec`] cascades, which enables us to
/// perform sorting in parallel.
/// Performs optimizations based upon a series of subrules.
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

/// sort first on a per-partition basis, thereby parallelizing the sort.
///
///
/// The outcome is that plans of the form
Copy link
Contributor

Choose a reason for hiding this comment

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

nice

@alamb alamb added the documentation Improvements or additions to documentation label Feb 15, 2025
Copy link
Member

@xudong963 xudong963 left a comment

Choose a reason for hiding this comment

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

A great reading experience, thanks @wiedld

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation optimizer Optimizer rules physical-expr Physical Expressions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants