diff --git a/datafusion/physical-plan/src/projection.rs b/datafusion/physical-plan/src/projection.rs index 22d159eb3a8d..3f901311a053 100644 --- a/datafusion/physical-plan/src/projection.rs +++ b/datafusion/physical-plan/src/projection.rs @@ -150,24 +150,33 @@ impl DisplayAs for ProjectionExec { t: DisplayFormatType, f: &mut std::fmt::Formatter, ) -> std::fmt::Result { - let expr: Vec = self - .expr - .iter() - .map(|(e, alias)| { - let e = e.to_string(); - if &e != alias { - format!("{e} as {alias}") - } else { - e - } - }) - .collect(); match t { DisplayFormatType::Default | DisplayFormatType::Verbose => { + let expr: Vec = self + .expr + .iter() + .map(|(e, alias)| { + let e = e.to_string(); + if &e != alias { + format!("{e} as {alias}") + } else { + e + } + }) + .collect(); + write!(f, "ProjectionExec: expr=[{}]", expr.join(", ")) } DisplayFormatType::TreeRender => { - write!(f, "expr=[{}]", expr.join(", ")) + for (i, (e, alias)) in self.expr().iter().enumerate() { + let e = e.to_string(); + if &e == alias { + writeln!(f, "expr{i}={e}")?; + } else { + writeln!(f, "{alias}={e}")?; + } + } + Ok(()) } } } diff --git a/datafusion/sqllogictest/test_files/explain_tree.slt b/datafusion/sqllogictest/test_files/explain_tree.slt index 613726c0eac5..275643ca2517 100644 --- a/datafusion/sqllogictest/test_files/explain_tree.slt +++ b/datafusion/sqllogictest/test_files/explain_tree.slt @@ -531,22 +531,24 @@ physical_plan 01)┌───────────────────────────┐ 02)│ ProjectionExec │ 03)│ -------------------- │ -04)│ expr: │ -05)│ [int_col@0 as int_col, │ -06)│ bigint_col@1 as │ -07)│ bigint_col, CAST │ -08)│ (int_col@0 AS Int64) + │ -09)│ bigint_col@1 as sum_col] │ -10)└─────────────┬─────────────┘ -11)┌─────────────┴─────────────┐ -12)│ RepartitionExec │ -13)└─────────────┬─────────────┘ -14)┌─────────────┴─────────────┐ -15)│ DataSourceExec │ -16)│ -------------------- │ -17)│ files: 1 │ -18)│ format: csv │ -19)└───────────────────────────┘ +04)│ bigint_col: │ +05)│ bigint_col@1 │ +06)│ │ +07)│ int_col: int_col@0 │ +08)│ │ +09)│ sum_col: │ +10)│ CAST(int_col@0 AS Int64) +│ +11)│ bigint_col@1 │ +12)└─────────────┬─────────────┘ +13)┌─────────────┴─────────────┐ +14)│ RepartitionExec │ +15)└─────────────┬─────────────┘ +16)┌─────────────┴─────────────┐ +17)│ DataSourceExec │ +18)│ -------------------- │ +19)│ files: 1 │ +20)│ format: csv │ +21)└───────────────────────────┘ # Query with projection on parquet @@ -560,22 +562,24 @@ physical_plan 01)┌───────────────────────────┐ 02)│ ProjectionExec │ 03)│ -------------------- │ -04)│ expr: │ -05)│ [int_col@0 as int_col, │ -06)│ bigint_col@1 as │ -07)│ bigint_col, CAST │ -08)│ (int_col@0 AS Int64) + │ -09)│ bigint_col@1 as sum_col] │ -10)└─────────────┬─────────────┘ -11)┌─────────────┴─────────────┐ -12)│ RepartitionExec │ -13)└─────────────┬─────────────┘ -14)┌─────────────┴─────────────┐ -15)│ DataSourceExec │ -16)│ -------------------- │ -17)│ files: 1 │ -18)│ format: parquet │ -19)└───────────────────────────┘ +04)│ bigint_col: │ +05)│ bigint_col@1 │ +06)│ │ +07)│ int_col: int_col@0 │ +08)│ │ +09)│ sum_col: │ +10)│ CAST(int_col@0 AS Int64) +│ +11)│ bigint_col@1 │ +12)└─────────────┬─────────────┘ +13)┌─────────────┴─────────────┐ +14)│ RepartitionExec │ +15)└─────────────┬─────────────┘ +16)┌─────────────┴─────────────┐ +17)│ DataSourceExec │ +18)│ -------------------- │ +19)│ files: 1 │ +20)│ format: parquet │ +21)└───────────────────────────┘ # Query with projection on memory @@ -589,20 +593,22 @@ physical_plan 01)┌───────────────────────────┐ 02)│ ProjectionExec │ 03)│ -------------------- │ -04)│ expr: │ -05)│ [int_col@0 as int_col, │ -06)│ bigint_col@1 as │ -07)│ bigint_col, CAST │ -08)│ (int_col@0 AS Int64) + │ -09)│ bigint_col@1 as sum_col] │ -10)└─────────────┬─────────────┘ -11)┌─────────────┴─────────────┐ -12)│ DataSourceExec │ -13)│ -------------------- │ -14)│ bytes: 1560 │ -15)│ format: memory │ -16)│ rows: 1 │ -17)└───────────────────────────┘ +04)│ bigint_col: │ +05)│ bigint_col@1 │ +06)│ │ +07)│ int_col: int_col@0 │ +08)│ │ +09)│ sum_col: │ +10)│ CAST(int_col@0 AS Int64) +│ +11)│ bigint_col@1 │ +12)└─────────────┬─────────────┘ +13)┌─────────────┴─────────────┐ +14)│ DataSourceExec │ +15)│ -------------------- │ +16)│ bytes: 1560 │ +17)│ format: memory │ +18)│ rows: 1 │ +19)└───────────────────────────┘ @@ -617,22 +623,23 @@ physical_plan 01)┌───────────────────────────┐ 02)│ ProjectionExec │ 03)│ -------------------- │ -04)│ expr: │ -05)│ [int_col@1 as int_col, │ -06)│ bigint_col@0 as │ -07)│ bigint_col, int_col │ -08)│ @1 + bigint_col@0 as │ -09)│ sum_col] │ -10)└─────────────┬─────────────┘ -11)┌─────────────┴─────────────┐ -12)│ RepartitionExec │ -13)└─────────────┬─────────────┘ -14)┌─────────────┴─────────────┐ -15)│ DataSourceExec │ -16)│ -------------------- │ -17)│ files: 1 │ -18)│ format: json │ -19)└───────────────────────────┘ +04)│ bigint_col: │ +05)│ bigint_col@0 │ +06)│ │ +07)│ int_col: int_col@1 │ +08)│ │ +09)│ sum_col: │ +10)│ int_col@1 + bigint_col@0 │ +11)└─────────────┬─────────────┘ +12)┌─────────────┴─────────────┐ +13)│ RepartitionExec │ +14)└─────────────┬─────────────┘ +15)┌─────────────┴─────────────┐ +16)│ DataSourceExec │ +17)│ -------------------- │ +18)│ files: 1 │ +19)│ format: json │ +20)└───────────────────────────┘ # Query with projection on arrow @@ -646,22 +653,24 @@ physical_plan 01)┌───────────────────────────┐ 02)│ ProjectionExec │ 03)│ -------------------- │ -04)│ expr: │ -05)│ [int_col@0 as int_col, │ -06)│ bigint_col@1 as │ -07)│ bigint_col, CAST │ -08)│ (int_col@0 AS Int64) + │ -09)│ bigint_col@1 as sum_col] │ -10)└─────────────┬─────────────┘ -11)┌─────────────┴─────────────┐ -12)│ RepartitionExec │ -13)└─────────────┬─────────────┘ -14)┌─────────────┴─────────────┐ -15)│ DataSourceExec │ -16)│ -------------------- │ -17)│ files: 1 │ -18)│ format: arrow │ -19)└───────────────────────────┘ +04)│ bigint_col: │ +05)│ bigint_col@1 │ +06)│ │ +07)│ int_col: int_col@0 │ +08)│ │ +09)│ sum_col: │ +10)│ CAST(int_col@0 AS Int64) +│ +11)│ bigint_col@1 │ +12)└─────────────┬─────────────┘ +13)┌─────────────┴─────────────┐ +14)│ RepartitionExec │ +15)└─────────────┬─────────────┘ +16)┌─────────────┴─────────────┐ +17)│ DataSourceExec │ +18)│ -------------------- │ +19)│ files: 1 │ +20)│ format: arrow │ +21)└───────────────────────────┘ # cleanup statement ok