This is an automated email from the ASF dual-hosted git repository. xudong963 pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push: new 1920771d80 Add relation to alias expr in schema display (#14311) 1920771d80 is described below commit 1920771d8019f9490180571b7db4902a39311cba Author: phisn <31885661+ph...@users.noreply.github.com> AuthorDate: Tue Jan 28 17:30:30 2025 +0100 Add relation to alias expr in schema display (#14311) * Add relation to alias expr in schema display * Add edge case for alias in physical_name --- datafusion/expr/src/expr.rs | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/datafusion/expr/src/expr.rs b/datafusion/expr/src/expr.rs index b8e495ee7a..7070761f63 100644 --- a/datafusion/expr/src/expr.rs +++ b/datafusion/expr/src/expr.rs @@ -2281,6 +2281,11 @@ impl Display for SchemaDisplay<'_> { Ok(()) } // Expr is not shown since it is aliased + Expr::Alias(Alias { + name, + relation: Some(relation), + .. + }) => write!(f, "{relation}.{name}"), Expr::Alias(Alias { name, .. }) => write!(f, "{name}"), Expr::Between(Between { expr, @@ -2769,10 +2774,10 @@ fn fmt_function( /// The name of the column (field) that this `Expr` will produce in the physical plan. /// The difference from [Expr::schema_name] is that top-level columns are unqualified. pub fn physical_name(expr: &Expr) -> Result<String> { - if let Expr::Column(col) = expr { - Ok(col.name.clone()) - } else { - Ok(expr.schema_name().to_string()) + match expr { + Expr::Column(col) => Ok(col.name.clone()), + Expr::Alias(alias) => Ok(alias.name.clone()), + _ => Ok(expr.schema_name().to_string()), } } @@ -3023,6 +3028,30 @@ mod test { ) } + #[test] + fn test_schema_display_alias_with_relation() { + assert_eq!( + format!( + "{}", + SchemaDisplay( + &lit(1).alias_qualified("table_name".into(), "column_name") + ) + ), + "table_name.column_name" + ); + } + + #[test] + fn test_schema_display_alias_without_relation() { + assert_eq!( + format!( + "{}", + SchemaDisplay(&lit(1).alias_qualified(None::<&str>, "column_name")) + ), + "column_name" + ); + } + fn wildcard_options( opt_ilike: Option<IlikeSelectItem>, opt_exclude: Option<ExcludeSelectItem>, --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@datafusion.apache.org For additional commands, e-mail: commits-h...@datafusion.apache.org