raghavyadav01 commented on code in PR #26874:
URL: https://github.com/apache/datafusion/pull/26874#discussion_r4505047939
##########
datafusion/optimizer/src/decorrelate_lateral_join.rs:
##########
@@ -88,6 +88,21 @@ fn rewrite_internal(join: Join) ->
Result<Transformed<LogicalPlan>> {
let subquery_plan = subquery.subquery.as_ref();
let original_join_filter = join.filter.clone();
+ // A HAVING over an ungrouped aggregate can remove the aggregate's only
+ // row. The rewrite below handles neither case correctly, so leave the join
+ // correlated and let the query error instead of returning wrong rows.
+ // <https://github.com/apache/datafusion/issues/21198>
+ // - An inner lateral join becomes an outer join that keeps every outer
row,
+ // so an outer row whose row the HAVING removes comes back with NULLs.
+ // - A HAVING that reads an outer column is moved into the join condition,
+ // where the count bug handling turns its unmatched rows into a count of
0,
+ // for a left lateral join too.
+ if let Some(having) = having_over_ungrouped_aggregate(subquery_plan)
Review Comment:
Thanks @jayzhan211, good catch. Applied the `pulled_up_scalar_agg` gate,
added both tests (they fail on the old head and pass now), and merged the two
`Filter` arms.
--
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]