nuno-faria opened a new issue, #25548:
URL: https://github.com/apache/datafusion/issues/25548
### Describe the bug
When a filter is based on a projected expression, the unparsing of the
optimized plan can generate invalid SQL.
### To Reproduce
The filter in the query below depends on a newly generated column
```sql
select *
from (
select random() as x
from t
)
where x = 1
```
which is optimized into this plan
```sql
Filter: x = Float64(1)
Projection: random() AS x
TableScan: t projection=[]
```
The unparsing of this plan puts the filter and the projection at the same
level, which is invalid:
```sql
SELECT random() AS x FROM t WHERE (x = 1.0) -- Schema error: No field named
x. Valid fields are t.a.
```
### 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]