-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Is your feature request related to a problem or challenge?
In the current optimization of Datafusion, we often use Expr::Alias instances for purposes:
- make the
parent planto correctly access the corresponding column. - ensure that the column name remains unchanged.
- prevent changes to the schema.
However, there is a vulnerability in this point 3. When an alias contains a qualifier, the schema cannot remain unchanged.
Here's an example:
Original Expr: column: t.c1 (field: qualifier: t, name: c1)
New Expr: 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
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 alias is Cast(t1.a as int)
So, I proposal to add a DFField in Expr::Alias, so we will get DFField of Expr::Alias directly
Describe alternatives you've considered
No response
Additional context
I find it in this PR #6595 (comment)
jiangzhx
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request