Skip to content

fix(optimizer): Fix field resolution for nested aggregations across DT boundaries#1071

Open
peterenescu wants to merge 1 commit intofacebookincubator:mainfrom
peterenescu:export-D96821235
Open

fix(optimizer): Fix field resolution for nested aggregations across DT boundaries#1071
peterenescu wants to merge 1 commit intofacebookincubator:mainfrom
peterenescu:export-D96821235

Conversation

@peterenescu
Copy link
Contributor

Summary:
Adds a check to see if inner aliased aggregate functions have already been resolved, rather than attempting to re-resolve it in the outer query. This will prevent the optimizer from re-expanding the aliases after the aggregate no longer exists, resulting in "Field not found" errors.

As an example:

WITH t AS (
  SELECT reduce(array_agg(ARRAY[v]), null, (s,x)->x, s->s) AS a
  FROM (VALUES (1)) t(v)
)
SELECT sum(cardinality(a)) FROM t;

Differential Revision: D96821235

…T boundaries

Summary:
Adds a check to see if inner aliased aggregate functions have already been resolved, rather than attempting to re-resolve it in the outer query. This will prevent the optimizer from re-expanding the aliases *after* the aggregate no longer exists, resulting in "Field not found" errors.

As an example:
```sql
WITH t AS (
  SELECT reduce(array_agg(ARRAY[v]), null, (s,x)->x, s->s) AS a
  FROM (VALUES (1)) t(v)
)
SELECT sum(cardinality(a)) FROM t;
```

Differential Revision: D96821235
@meta-codesync
Copy link

meta-codesync bot commented Mar 17, 2026

@peterenescu has exported this pull request. If you are a Meta employee, you can view the originating Diff in D96821235.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. fb-exported meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant