neilconway opened a new issue, #21198: URL: https://github.com/apache/datafusion/issues/21198
### Describe the bug This currently doesn't work. The issue: * For normal LATERAL subqueries without HAVING (but with COUNT(*) or a similar agg), we rewrite the LATERAL subquery into a grouped agg subquery and LEFT JOIN against it. We add a `CASE ... WHEN __always_true` construct to convert unmatched outer rows from `NULL` to the agg's default value (0 for count). * When the LATERAL subquery has a HAVING clause, there's another possibility: an outer row might be unmatched because the entire group was excluded because it failed the HAVING clause. So the correct behavior is to elide the entire outer row, not substitute a 0 for the NULL count value. We can fix this by * Pulling the HAVING clause out of the subquery and evaluating it over the subquery's results instead. This requires rewriting it in terms of the post-join schema. * Arrange to omit rows from the final result set that don't satisfy the rewritten HAVING clause This is similar to what we already do in `scalar_subquery_to_join`, except slightly different because we want to omit the row entirely, not return NULL. ### To Reproduce _No response_ ### Expected behavior _No response_ ### Additional context _No response_ -- 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]
