jackwener opened a new issue, #6681:
URL: https://github.com/apache/arrow-datafusion/issues/6681
### Is your feature request related to a problem or challenge?
In the current optimization of Datafusion, we often use Expr::Alias
instances for purposes:
1. allow the parent plan to correctly access the corresponding column.
2. ensure that the column name remains unchanged.
3. prevent changes to the schema.
4.
However, there is a vulnerability in this process. When an alias contains a
qualifier, the schema cannot remain unchanged.
Here's an example:
Original column: t.c1 (field: qualifier: t, name: c1)
New column: c2 as t.c1 (its field will be: field: qualifier: None, name:
t.c1)
### Describe the solution you'd like
I try to match Expr::Alias and handle it in `to_field()`.
such as
```rust
fn to_field(&self, input_schema: &DFSchema) -> Result<DFField> {
match self {
Expr::Alias(e, alias) if alias.contains('.') => {
let index = alias.rfind('.').unwrap();
let qualifier = alias[..index].to_string();
let name = alias[index + 1..].to_string();
Ok(DFField::new(
Some(qualifier),
&name,
e.get_type(input_schema)?,
e.nullable(input_schema)?,
))
}
Expr::Column(c) => Ok(DFField::new(
c.relation.clone(),
&c.name,
self.get_type(input_schema)?,
self.nullable(input_schema)?,
)),
```
but I failed, because `alias` can be complex, we hard to parse it and
separate qualifier and name.
such as above code will fail in expr like `Cast(t1.a as int)`
So, I propose to add a `schema` in Expr::Alias, so we will get schema of
Expr::Alias directly
### 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]