comphead commented on code in PR #26544:
URL: https://github.com/apache/datafusion/pull/26544#discussion_r4338795873
##########
datafusion/optimizer/src/decorrelate.rs:
##########
@@ -505,6 +505,12 @@ impl TreeNodeRewriter for PullUpCorrelatedExpr {
if !is_distinct {
self.can_pull_up = self.can_pull_up &&
self.can_pull_over_aggregation;
}
+ // A pulled up scalar aggregate below gives no row for
unmatched
+ // outer rows, so this aggregate would see an empty input.
+ // See https://github.com/apache/datafusion/issues/26508
+ if self.pulled_up_scalar_agg {
+ self.can_pull_up = false;
+ }
Review Comment:
The check moved to the top of the `Aggregate` branch. It now sets
`can_pull_up = false` and returns early with `TreeNodeRecursion::Stop`, which
fixes the schema error jayzhan211 found (details in the top-level comment).
That leaves no second update of `can_pull_up` to fold. The check is still
outside the `is_distinct` block. I also added the doc comment on
`pulled_up_scalar_agg`.
--
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]