cetra3 opened a new issue, #22955:
URL: https://github.com/apache/datafusion/issues/22955

   ### 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:
   
   ```sql
   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_


-- 
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]

Reply via email to