goldmedal opened a new issue, #12154:
URL: https://github.com/apache/datafusion/issues/12154
### Is your feature request related to a problem or challenge?
Consider the following case:
```rust
let ctx = SessionContext::new();
ctx.sql("create table t1 (a int, b int)").await?;
ctx.sql("insert into t1 values (1, 2), (3, 4)").await?;
let plan = ctx.sql(r#"select s1.a from (select s1.a, s1.b from (select
a, b from t1) s1) s1"#).await?.into_optimized_plan()?;
println!("optimized plan: {plan}");
let unparse = plan_to_sql(&plan)?.to_string();
println!("{}", format!("Unparsed SQL: {}", unparse));
```
The output result is
```
Optimized plan: SubqueryAlias: s1
SubqueryAlias: s1
TableScan: t1 projection=[a]
Unparsed SQL: SELECT * FROM t1 AS s1
```
The unparsing isn't equal to the original SQL. I think it should be
```
select * from (select a from t1) s1
```
### Describe the solution you'd like
Handle the pushdown projection at `Unparser:select_to_sql_recursively`
https://github.com/apache/datafusion/blob/23ccca9cd9bdf1791985f2b4abb6d5d8a4fc5ece/datafusion/sql/src/unparser/plan.rs#L240-L243
### Describe alternatives you've considered
_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]