Skip to content

Commit 22a0fdb

Browse files
authored
doc: add comments for LocalLimitExec and GlobalLimitExec (#25993)
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Closes #. ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. Please explain the problem you are trying to solve in terms of the user-visible behavior, rather than the implementation. For example, "The code in `foo.rs` doesn't handle nulls" is a symptom of the implementation. "COUNT(DISTINCT) returns wrong results when the column contains nulls" is the user-visible problem. --> More comments to explain the difference between local/global limit ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here, but it is sometimes worth providing a summary of the individual changes in this PR. --> comments only ## What is the testing strategy for this PR? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code Briefly describe how this PR is tested, and point to the specific tests you added. For example: 'This new feature is covered by the `sqllogictest` cases added in `foo.slt`'. If this PR does not add tests, explain why. For example, if the change is already covered by existing tests, please mention it. You should also check the `codecov` bot reply on this PR to confirm the changed code is exercised. --> ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. If there are any breaking changes to public APIs, please add the `api change` label. -->
1 parent de4e344 commit 22a0fdb

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

‎datafusion/physical-plan/src/limit.rs‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,20 @@ use datafusion_physical_expr::{LexOrdering, PhysicalExpr};
4545
use futures::stream::{Stream, StreamExt};
4646
use log::trace;
4747

48-
/// Limit execution plan
48+
/// Applies a limit to the entire result.
49+
///
50+
/// Requires a single input partition; otherwise, plan validation or execution fails.
51+
/// For input with multiple partitions, merge them before applying the limit:
52+
/// (For SQL interface, coalescing will be enforced automatically in physical
53+
/// optimizer through [`ExecutionPlan::required_input_distribution`])
54+
///
55+
/// ```text
56+
/// GlobalLimitExec: skip=0, fetch=10
57+
/// CoalescePartitionsExec <--- combine to 1 partition output
58+
/// DataSourceExec: partitions=4 <--- 4 parallel scan partitions
59+
/// ```
60+
///
61+
/// To enforce a per-partition limit, use [`LocalLimitExec`].
4962
#[derive(Debug, Clone)]
5063
pub struct GlobalLimitExec {
5164
/// Input execution plan
@@ -352,7 +365,17 @@ impl GlobalLimitExec {
352365
}
353366
}
354367

355-
/// LocalLimitExec applies a limit to a single partition
368+
/// Applies a limit independently to each input partition.
369+
///
370+
/// Preserves input partitioning. With four partitions, a limit of 10 allows
371+
/// up to 40 rows in total:
372+
///
373+
/// ```text
374+
/// LocalLimitExec: fetch=10
375+
/// DataSourceExec: partitions=4
376+
/// ```
377+
///
378+
/// To enforce a limit on the entire result, use [`GlobalLimitExec`].
356379
#[derive(Debug, Clone)]
357380
pub struct LocalLimitExec {
358381
/// Input execution plan

0 commit comments

Comments
 (0)