nuno-faria commented on issue #17359:
URL: https://github.com/apache/datafusion/issues/17359#issuecomment-3240029311
@jonathanc-n thanks for looking into it. Here is a complete example:
```rust
use datafusion::error::Result;
use datafusion::prelude::SessionContext;
use datafusion::sql::unparser::plan_to_sql;
#[tokio::main]
async fn main() -> Result<()> {
let ctx = SessionContext::new();
ctx.sql("create table j1 (j1_id int, j1_string varchar)")
.await?
.collect()
.await?;
ctx.sql("create table j2 (j2_id int, j2_string varchar)")
.await?
.collect()
.await?;
let df = ctx
.sql(
"select j1.j1_id, j2.j2_string
from j1, j2
where j2.j2_id = 0;",
)
.await?;
// unoptimized
println!("unoptimized: {}", plan_to_sql(df.logical_plan())?);
// optimized
let optimized_plan = df.into_optimized_plan()?;
println!("optimized: {}", plan_to_sql(&optimized_plan)?);
Ok(())
}
```
```sql
unoptimized: SELECT j1.j1_id, j2.j2_string FROM j1 CROSS JOIN j2 WHERE
(j2.j2_id = 0)
optimized: SELECT j1.j1_id, j2.j2_string FROM j1 CROSS JOIN (SELECT
j2.j2_string FROM j2 WHERE (j2.j2_id = 0)) WHERE (j2.j2_id = 0)
```
The problem occurs when unparsing an optimized plan, while unparsing the
original unoptimized plan works well.
Here are the plans for reference:
```sql
-- unoptimized
Projection: j1.j1_id, j2.j2_string
Filter: j2.j2_id = Int64(0)
Cross Join:
TableScan: j1
TableScan: j2
-- optimized
Cross Join:
TableScan: j1 projection=[j1_id]
Projection: j2.j2_string
Filter: j2.j2_id = Int32(0)
TableScan: j2 projection=[j2_id, j2_string]
```
--
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]