Skip to content

Commit b15d1f4

Browse files
committed
Stop copying LogicalPlan and Exprs in OptimizeProjections
1 parent fad16e7 commit b15d1f4

5 files changed

Lines changed: 471 additions & 386 deletions

File tree

datafusion/expr/src/expr.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,34 @@ impl Expr {
10791079
}
10801080
}
10811081

1082+
/// Recursively potentially multiple aliases from an expression.
1083+
///
1084+
/// If the expression is not an alias, the expression is returned unchanged.
1085+
/// This method removes directly nested aliases, but not other nested
1086+
/// aliases.
1087+
///
1088+
/// # Example
1089+
/// ```
1090+
/// # use datafusion_expr::col;
1091+
/// // `foo as "bar"` is unaliased to `foo`
1092+
/// let expr = col("foo").alias("bar");
1093+
/// assert_eq!(expr.unalias_nested(), col("foo"));
1094+
///
1095+
/// // `foo as "bar" + baz` is not unaliased
1096+
/// let expr = col("foo").alias("bar") + col("baz");
1097+
/// assert_eq!(expr.clone().unalias_nested(), expr);
1098+
///
1099+
/// // `foo as "bar" as "baz" is unalaised to foo
1100+
/// let expr = col("foo").alias("bar").alias("baz");
1101+
/// assert_eq!(expr.unalias_nested(), col("foo"));
1102+
/// ```
1103+
pub fn unalias_nested(self) -> Expr {
1104+
match self {
1105+
Expr::Alias(alias) => alias.expr.unalias_nested(),
1106+
_ => self,
1107+
}
1108+
}
1109+
10821110
/// Return `self IN <list>` if `negated` is false, otherwise
10831111
/// return `self NOT IN <list>`.a
10841112
pub fn in_list(self, list: Vec<Expr>, negated: bool) -> Expr {

0 commit comments

Comments
 (0)