siddubakka commented on code in PR #26723:
URL: https://github.com/apache/datafusion/pull/26723#discussion_r4385350432
##########
datafusion/optimizer/src/scalar_subquery_to_join.rs:
##########
@@ -399,6 +399,33 @@ fn build_join(
// introduced is the untyped `Null` of the HAVING arm. The expressions
// themselves come from a plan `TypeCoercion` has already coerced.
let mut expr_rewrite = TypeCoercionRewriter::new(new_plan.schema());
+ // Evaluate the HAVING-like conditions (recorded during decorrelation
+ // from filters sitting above the aggregate) against the empty-input
+ // aggregate defaults: `count(*)` becomes `0`, and so on.
+ let having_on_default =
+ match conjunction(pull_up.having_like_join_filters.clone()) {
+ Some(combined) => {
+ let requalified = replace_qualified_name(
+ combined,
+ &all_correlated_cols,
+ subquery_alias,
+ )?;
+ let substituted = requalified
+ .transform_up(|e| {
+ if let Expr::Column(Column { name, .. }) = &e
+ && let Some(default_val) = expr_map.get(name)
Review Comment:
Ah, good catch — I only had the aggregate output in mind there. Switched
the
match to require `relation: Some(relation)` with
`relation.table() == subquery_alias` like you suggested, so an outer `x.n` is
left alone. Added your query to `subquery.slt` — (5, 9) gives 0 now, (0, 9)
stays NULL.
--
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]