goldmedal opened a new issue, #11551:
URL: https://github.com/apache/datafusion/issues/11551
### Is your feature request related to a problem or challenge?
After #10995, we have `parse_sql_expr()` to create a logical expression from
the SQL string. This API allows creating the expression with a `Schema`. I
tried to create the expression with a qualified schema:
```rust
let sql = "a < 5 OR a = 8";
let expr = col("t.a").lt(lit(5_i64)).or(col("t.a").eq(lit(8_i64)));
// provide type information that `a` is an Int32
let schema = Schema::new(vec![Field::new("a", DataType::Int32, true)]);
let df_schema = DFSchema::try_from_qualified_schema("t", &schema).unwrap();
let ctx = SessionContext::new();
let parsed_expr = ctx.parse_sql_expr(sql, &df_schema)?;
assert_eq!(parsed_expr, expr);
```
I expected the identifier to be `col("t.a")`, but it is actually `col("a")`.
I think the behavior can be aligned with the planning for the SQL statement:
```rust
ctx.register_batch("t", a_batch());
let df = ctx.sql("SELECT a < 5 OR a = 8 FROM
t").await?.into_optimized_plan()?;
dbg!(&df);
```
The result would be:
```
[datafusion-examples/examples/parse_sql_expr.rs:89:5] &df = Projection: t.a
< Int32(5) OR t.a = Int32(8) AS t.a < Int64(5) OR t.a = Int64(8)
TableScan: t projection=[a]
```
All of the identifiers are qualified.
### Describe the solution you'd like
I think we can find the field by `qualified_field_with_unqualified_name`,
and pass the qualifier when planning a column at
https://github.com/apache/datafusion/blob/28fa74bf0fb69f46fd03ef97eb301090de23b5f5/datafusion/sql/src/expr/identifier.rs#L50-L57
### 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]