Skip to content

optimize_projections fails on leaf-expression pushdown over a view with an unconsumed column #22955

Closed

Description

@cetra3

Describe the bug

When a leaf-pushable expression (e.g. get_field / col['key']) appears in both the SELECT list and the WHERE clause, the bare base column is also projected, and the source is a view/SubqueryAlias that projects a column the outer query doesn't use, the leaf-expression-pushdown passes produce an inconsistent plan and optimization fails.

To Reproduce

Run the following SQL via datafusion-cli:

CREATE TABLE base AS SELECT named_struct('status', 'active') AS s, 1 AS id;
CREATE VIEW v AS SELECT s, id, id + 1 AS synth FROM base;
SELECT s['status'], s, id FROM v WHERE s['status'] IS NOT NULL;

It outputs with the following:

Optimizer rule 'optimize_projections' failed
caused by
Schema error: No field named __datafusion_extracted_2. Did you mean 'v.__datafusion_extracted_1'?

Expected behavior

This doesn't fail

Additional context

No response

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