siddubakka commented on code in PR #26723:
URL: https://github.com/apache/datafusion/pull/26723#discussion_r4417704366
##########
datafusion/optimizer/src/scalar_subquery_to_join.rs:
##########
@@ -362,8 +362,41 @@ fn build_join(
.alias(subquery_alias.to_string())?
.build()?;
+ // A HAVING-like condition recorded from a filter above the aggregate can
+ // leave the join ON only when every empty-input default gets a
+ // compensation CASE below: an aggregate whose default is NULL has no CASE
+ // to check such a condition in, so for those it keeps filtering in the
+ // ON as before.
+ let having_in_compensation = match &collected_count_expr_map {
Review Comment:
You were right. Folding over the whole map was too broad, a HAVING-only
`max` shouldn't decide anything for an output column that gets its own
compensation CASE. Switched the gate to look only at the output column as in
your diff and added both queries to `subquery.slt` (`NULL, 1, NULL` and `NULL,
1, 0`). All green: optimizer tests, slt and clippy.
--
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]