Skip to content

Unparsing of filter depending on projection generates invalid SQL #25548

Description

@nuno-faria

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

select *
from (
    select random() as x
    from t
)
where x = 1

which is optimized into this plan

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:

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions