Skip to content

Commit

Permalink
Make Expr::alias and alias_qualified smarter by calling unalias
Browse files Browse the repository at this point in the history
I can't imagine a use case where we want to have double aliasing
  • Loading branch information
joroKr21 committed Feb 20, 2025
1 parent 2f40f6c commit 7ca35e8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions datafusion/expr/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,7 @@ impl Expr {

/// Return `self AS name` alias expression
pub fn alias(self, name: impl Into<String>) -> Expr {
Expr::Alias(Alias::new(self, None::<&str>, name.into()))
Expr::Alias(Alias::new(self.unalias(), None::<TableReference>, name))
}

/// Return `self AS name` alias expression with a specific qualifier
Expand All @@ -1285,7 +1285,7 @@ impl Expr {
relation: Option<impl Into<TableReference>>,
name: impl Into<String>,
) -> Expr {
Expr::Alias(Alias::new(self, relation, name.into()))
Expr::Alias(Alias::new(self.unalias(), relation, name))
}

/// Remove an alias from an expression if one exists.
Expand Down
2 changes: 1 addition & 1 deletion datafusion/optimizer/src/analyzer/type_coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ fn project_with_column_index(
.enumerate()
.map(|(i, e)| match e {
Expr::Alias(Alias { ref name, .. }) if name != schema.field(i).name() => {
Ok(e.unalias().alias(schema.field(i).name()))
Ok(e.alias(schema.field(i).name()))
}
Expr::Column(Column {
relation: _,
Expand Down

0 comments on commit 7ca35e8

Please sign in to comment.