Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions datafusion/physical-plan/src/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,24 +150,33 @@ impl DisplayAs for ProjectionExec {
t: DisplayFormatType,
f: &mut std::fmt::Formatter,
) -> std::fmt::Result {
let expr: Vec<String> = 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<String> = 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(())
}
}
}
Expand Down
165 changes: 87 additions & 78 deletions datafusion/sqllogictest/test_files/explain_tree.slt
Original file line number Diff line number Diff line change
Expand Up @@ -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: │
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is to make each expr its own print item

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your potential suggestions, i will merge into my pr.

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
Expand All @@ -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
Expand All @@ -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)└───────────────────────────┘



Expand All @@ -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
Expand All @@ -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
Expand Down