Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sqlglot-integration-tests
8 changes: 8 additions & 0 deletions sqlglot/optimizer/unnest_subqueries.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ def unnest_subqueries(expression: E) -> E:
if not parent:
continue

# Don't hoist anonymous functions because their input-row versus post-aggregation role is unknown.
if isinstance(select.find_ancestor(exp.Anonymous, exp.Select), exp.Anonymous) or (
not _has_plain_explicit_group(parent)
and _is_post_aggregation(select, parent)
and any(find_in_scope(projection, exp.Anonymous) for projection in parent.selects)
):
continue

# Don't hoist a subquery out of a correlated, ungrouped aggregate if it's evaluated after the
# aggregation: the aggregate returns a row even for keys with no input rows, and the hoisted
# MAX(...) would turn the row's value into NULL
Expand Down
Loading