peter-toth commented on code in PR #10832:
URL: https://github.com/apache/datafusion/pull/10832#discussion_r1632289500


##########
datafusion/expr/src/expr.rs:
##########
@@ -1133,14 +1133,23 @@ impl Expr {
     }
 
     /// Return `self AS name` alias expression
+    /// Removes existing Alias if exists
+    ///
+    /// # Example
+    /// ```
+    /// # use datafusion_expr::col;
+    /// // `foo as "bar" as "baz"` is resolved to `foo as "baz"`
+    /// let expr = col("foo").alias("bar").alias("baz");
+    /// assert_eq!(expr, col("foo").alias("baz"));
+    /// ```
     pub fn alias(self, name: impl Into<String>) -> Expr {
         match self {
             Expr::Sort(Sort {
                 expr,
                 asc,
                 nulls_first,
             }) => Expr::Sort(Sort::new(Box::new(expr.alias(name)), asc, 
nulls_first)),
-            _ => Expr::Alias(Alias::new(self, None::<&str>, name.into())),
+            _ => Expr::Alias(Alias::new(self.unalias(), None::<&str>, 
name.into())),

Review Comment:
   Is changing how `alias()` works required for this PR?
   I think the change make sense but extracting it to a separate PR might be 
better...



-- 
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]

Reply via email to