alamb commented on code in PR #27772:
URL: https://github.com/apache/datafusion/pull/27772#discussion_r4731251444
##########
datafusion/physical-optimizer/src/window_topn.rs:
##########
@@ -317,16 +318,27 @@ impl PhysicalOptimizerRule for WindowTopN {
return Ok(plan);
}
- plan.transform_down(|node| {
+ let rewritten = Arc::clone(&plan).transform_down(|node| {
Ok(
if let Some(transformed) = WindowTopN::try_transform(&node) {
Transformed::yes(transformed)
} else {
Transformed::no(node)
},
)
- })
- .data()
+ })?;
+ // `PartitionedTopKExec` emits its rows ordered by the partition keys
in
+ // the default sort options, whatever order its input had. Once
+ // `EnsureRequirements` has made the plan's requirements hold, an
+ // operator above may rely on the order the window had, and nothing
+ // would restore it.
Review Comment:
I found this second sentence confusing -- specifically the mention of
EnsureRequirements
I think the key point is that "WindowTopN must ensure the output remains
sorted in the same way as it was originally"
##########
datafusion/physical-optimizer/src/window_topn.rs:
##########
@@ -317,16 +318,27 @@ impl PhysicalOptimizerRule for WindowTopN {
return Ok(plan);
}
- plan.transform_down(|node| {
+ let rewritten = Arc::clone(&plan).transform_down(|node| {
Ok(
if let Some(transformed) = WindowTopN::try_transform(&node) {
Transformed::yes(transformed)
} else {
Transformed::no(node)
},
)
- })
- .data()
+ })?;
+ // `PartitionedTopKExec` emits its rows ordered by the partition keys
in
+ // the default sort options, whatever order its input had. Once
+ // `EnsureRequirements` has made the plan's requirements hold, an
+ // operator above may rely on the order the window had, and nothing
+ // would restore it.
+ if rewritten.transformed
+ && input_requirements_hold(&plan)
+ && !input_requirements_hold(&rewritten.data)
+ {
+ return Ok(plan);
Review Comment:
given the comment and my understanding, i would have expected this should be
checking the parent of `plan` (as rewriting plan may have changed its output
requirements). I don't understand why this is checking the input requirements 🤔
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]