Skip to content

Commit f8f872e

Browse files
authored
Merge pull request #1 from alamb/alamb/proj_exec_suggestion
Propose a different projection formatting
2 parents 767643a + ed5ca43 commit f8f872e

File tree

2 files changed

+109
-91
lines changed

2 files changed

+109
-91
lines changed

datafusion/physical-plan/src/projection.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,24 +150,33 @@ impl DisplayAs for ProjectionExec {
150150
t: DisplayFormatType,
151151
f: &mut std::fmt::Formatter,
152152
) -> std::fmt::Result {
153-
let expr: Vec<String> = self
154-
.expr
155-
.iter()
156-
.map(|(e, alias)| {
157-
let e = e.to_string();
158-
if &e != alias {
159-
format!("{e} as {alias}")
160-
} else {
161-
e
162-
}
163-
})
164-
.collect();
165153
match t {
166154
DisplayFormatType::Default | DisplayFormatType::Verbose => {
155+
let expr: Vec<String> = self
156+
.expr
157+
.iter()
158+
.map(|(e, alias)| {
159+
let e = e.to_string();
160+
if &e != alias {
161+
format!("{e} as {alias}")
162+
} else {
163+
e
164+
}
165+
})
166+
.collect();
167+
167168
write!(f, "ProjectionExec: expr=[{}]", expr.join(", "))
168169
}
169170
DisplayFormatType::TreeRender => {
170-
write!(f, "expr=[{}]", expr.join(", "))
171+
for (i, (e, alias)) in self.expr().iter().enumerate() {
172+
let e = e.to_string();
173+
if &e == alias {
174+
writeln!(f, "expr{i}={e}")?;
175+
} else {
176+
writeln!(f, "{alias}={e}")?;
177+
}
178+
}
179+
Ok(())
171180
}
172181
}
173182
}

datafusion/sqllogictest/test_files/explain_tree.slt

Lines changed: 87 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -531,22 +531,24 @@ physical_plan
531531
01)┌───────────────────────────┐
532532
02)│ ProjectionExec │
533533
03)│ -------------------- │
534-
04)│ expr: │
535-
05)│ [int_col@0 as int_col, │
536-
06)│ bigint_col@1 as │
537-
07)│ bigint_col, CAST │
538-
08)│ (int_col@0 AS Int64) + │
539-
09)│ bigint_col@1 as sum_col] │
540-
10)└─────────────┬─────────────┘
541-
11)┌─────────────┴─────────────┐
542-
12)│ RepartitionExec │
543-
13)└─────────────┬─────────────┘
544-
14)┌─────────────┴─────────────┐
545-
15)│ DataSourceExec │
546-
16)│ -------------------- │
547-
17)│ files: 1 │
548-
18)│ format: csv │
549-
19)└───────────────────────────┘
534+
04)│ bigint_col: │
535+
05)│ bigint_col@1 │
536+
06)│ │
537+
07)│ int_col: int_col@0 │
538+
08)│ │
539+
09)│ sum_col: │
540+
10)│ CAST(int_col@0 AS Int64) +│
541+
11)│ bigint_col@1 │
542+
12)└─────────────┬─────────────┘
543+
13)┌─────────────┴─────────────┐
544+
14)│ RepartitionExec │
545+
15)└─────────────┬─────────────┘
546+
16)┌─────────────┴─────────────┐
547+
17)│ DataSourceExec │
548+
18)│ -------------------- │
549+
19)│ files: 1 │
550+
20)│ format: csv │
551+
21)└───────────────────────────┘
550552

551553

552554
# Query with projection on parquet
@@ -560,22 +562,24 @@ physical_plan
560562
01)┌───────────────────────────┐
561563
02)│ ProjectionExec │
562564
03)│ -------------------- │
563-
04)│ expr: │
564-
05)│ [int_col@0 as int_col, │
565-
06)│ bigint_col@1 as │
566-
07)│ bigint_col, CAST │
567-
08)│ (int_col@0 AS Int64) + │
568-
09)│ bigint_col@1 as sum_col] │
569-
10)└─────────────┬─────────────┘
570-
11)┌─────────────┴─────────────┐
571-
12)│ RepartitionExec │
572-
13)└─────────────┬─────────────┘
573-
14)┌─────────────┴─────────────┐
574-
15)│ DataSourceExec │
575-
16)│ -------------------- │
576-
17)│ files: 1 │
577-
18)│ format: parquet │
578-
19)└───────────────────────────┘
565+
04)│ bigint_col: │
566+
05)│ bigint_col@1 │
567+
06)│ │
568+
07)│ int_col: int_col@0 │
569+
08)│ │
570+
09)│ sum_col: │
571+
10)│ CAST(int_col@0 AS Int64) +│
572+
11)│ bigint_col@1 │
573+
12)└─────────────┬─────────────┘
574+
13)┌─────────────┴─────────────┐
575+
14)│ RepartitionExec │
576+
15)└─────────────┬─────────────┘
577+
16)┌─────────────┴─────────────┐
578+
17)│ DataSourceExec │
579+
18)│ -------------------- │
580+
19)│ files: 1 │
581+
20)│ format: parquet │
582+
21)└───────────────────────────┘
579583

580584

581585
# Query with projection on memory
@@ -589,20 +593,22 @@ physical_plan
589593
01)┌───────────────────────────┐
590594
02)│ ProjectionExec │
591595
03)│ -------------------- │
592-
04)│ expr: │
593-
05)│ [int_col@0 as int_col, │
594-
06)│ bigint_col@1 as │
595-
07)│ bigint_col, CAST │
596-
08)│ (int_col@0 AS Int64) + │
597-
09)│ bigint_col@1 as sum_col] │
598-
10)└─────────────┬─────────────┘
599-
11)┌─────────────┴─────────────┐
600-
12)│ DataSourceExec │
601-
13)│ -------------------- │
602-
14)│ bytes: 1560 │
603-
15)│ format: memory │
604-
16)│ rows: 1 │
605-
17)└───────────────────────────┘
596+
04)│ bigint_col: │
597+
05)│ bigint_col@1 │
598+
06)│ │
599+
07)│ int_col: int_col@0 │
600+
08)│ │
601+
09)│ sum_col: │
602+
10)│ CAST(int_col@0 AS Int64) +│
603+
11)│ bigint_col@1 │
604+
12)└─────────────┬─────────────┘
605+
13)┌─────────────┴─────────────┐
606+
14)│ DataSourceExec │
607+
15)│ -------------------- │
608+
16)│ bytes: 1560 │
609+
17)│ format: memory │
610+
18)│ rows: 1 │
611+
19)└───────────────────────────┘
606612

607613

608614

@@ -617,22 +623,23 @@ physical_plan
617623
01)┌───────────────────────────┐
618624
02)│ ProjectionExec │
619625
03)│ -------------------- │
620-
04)│ expr: │
621-
05)│ [int_col@1 as int_col, │
622-
06)│ bigint_col@0 as │
623-
07)│ bigint_col, int_col │
624-
08)│ @1 + bigint_col@0 as │
625-
09)│ sum_col] │
626-
10)└─────────────┬─────────────┘
627-
11)┌─────────────┴─────────────┐
628-
12)│ RepartitionExec │
629-
13)└─────────────┬─────────────┘
630-
14)┌─────────────┴─────────────┐
631-
15)│ DataSourceExec │
632-
16)│ -------------------- │
633-
17)│ files: 1 │
634-
18)│ format: json │
635-
19)└───────────────────────────┘
626+
04)│ bigint_col: │
627+
05)│ bigint_col@0 │
628+
06)│ │
629+
07)│ int_col: int_col@1 │
630+
08)│ │
631+
09)│ sum_col: │
632+
10)│ int_col@1 + bigint_col@0 │
633+
11)└─────────────┬─────────────┘
634+
12)┌─────────────┴─────────────┐
635+
13)│ RepartitionExec │
636+
14)└─────────────┬─────────────┘
637+
15)┌─────────────┴─────────────┐
638+
16)│ DataSourceExec │
639+
17)│ -------------------- │
640+
18)│ files: 1 │
641+
19)│ format: json │
642+
20)└───────────────────────────┘
636643

637644

638645
# Query with projection on arrow
@@ -646,22 +653,24 @@ physical_plan
646653
01)┌───────────────────────────┐
647654
02)│ ProjectionExec │
648655
03)│ -------------------- │
649-
04)│ expr: │
650-
05)│ [int_col@0 as int_col, │
651-
06)│ bigint_col@1 as │
652-
07)│ bigint_col, CAST │
653-
08)│ (int_col@0 AS Int64) + │
654-
09)│ bigint_col@1 as sum_col] │
655-
10)└─────────────┬─────────────┘
656-
11)┌─────────────┴─────────────┐
657-
12)│ RepartitionExec │
658-
13)└─────────────┬─────────────┘
659-
14)┌─────────────┴─────────────┐
660-
15)│ DataSourceExec │
661-
16)│ -------------------- │
662-
17)│ files: 1 │
663-
18)│ format: arrow │
664-
19)└───────────────────────────┘
656+
04)│ bigint_col: │
657+
05)│ bigint_col@1 │
658+
06)│ │
659+
07)│ int_col: int_col@0 │
660+
08)│ │
661+
09)│ sum_col: │
662+
10)│ CAST(int_col@0 AS Int64) +│
663+
11)│ bigint_col@1 │
664+
12)└─────────────┬─────────────┘
665+
13)┌─────────────┴─────────────┐
666+
14)│ RepartitionExec │
667+
15)└─────────────┬─────────────┘
668+
16)┌─────────────┴─────────────┐
669+
17)│ DataSourceExec │
670+
18)│ -------------------- │
671+
19)│ files: 1 │
672+
20)│ format: arrow │
673+
21)└───────────────────────────┘
665674

666675
# cleanup
667676
statement ok

0 commit comments

Comments
 (0)