Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show column names instead of indices in query plans #2690

Merged
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
58 changes: 29 additions & 29 deletions datafusion/core/src/datasource/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,15 @@ mod tests {
.await?;

let expected = vec![
"+---------------+--------------------------------------------------------+",
"| plan_type | plan |",
"+---------------+--------------------------------------------------------+",
"| logical_plan | CreateView: \"xyz\" |",
"| | Projection: #abc.column1, #abc.column2, #abc.column3 |",
"| | TableScan: abc projection=Some([0, 1, 2]) |",
"| physical_plan | EmptyExec: produce_one_row=false |",
"| | |",
"+---------------+--------------------------------------------------------+",
"+---------------+-----------------------------------------------------------------+",
"| plan_type | plan |",
"+---------------+-----------------------------------------------------------------+",
"| logical_plan | CreateView: \"xyz\" |",
"| | Projection: #abc.column1, #abc.column2, #abc.column3 |",
"| | TableScan: abc projection=Some([column1, column2, column3]) |",
"| physical_plan | EmptyExec: produce_one_row=false |",
"| | |",
"+---------------+-----------------------------------------------------------------+",
];

assert_batches_eq!(expected, &results);
Expand All @@ -282,16 +282,16 @@ mod tests {
.await?;

let expected = vec![
"+---------------+--------------------------------------------------------+",
"| plan_type | plan |",
"+---------------+--------------------------------------------------------+",
"| logical_plan | CreateView: \"xyz\" |",
"| | Projection: #abc.column1, #abc.column2, #abc.column3 |",
"| | Filter: #abc.column2 = Int64(5) |",
"| | TableScan: abc projection=Some([0, 1, 2]) |",
"| physical_plan | EmptyExec: produce_one_row=false |",
"| | |",
"+---------------+--------------------------------------------------------+",
"+---------------+-------------------------------------------------------------------+",
"| plan_type | plan |",
"+---------------+-------------------------------------------------------------------+",
"| logical_plan | CreateView: \"xyz\" |",
"| | Projection: #abc.column1, #abc.column2, #abc.column3 |",
"| | Filter: #abc.column2 = Int64(5) |",
"| | TableScan: abc projection=Some([column1, column2, column3]) |",
"| physical_plan | EmptyExec: produce_one_row=false |",
"| | |",
"+---------------+-------------------------------------------------------------------+",
];

assert_batches_eq!(expected, &results);
Expand All @@ -303,16 +303,16 @@ mod tests {
.await?;

let expected = vec![
"+---------------+----------------------------------------------+",
"| plan_type | plan |",
"+---------------+----------------------------------------------+",
"| logical_plan | CreateView: \"xyz\" |",
"| | Projection: #abc.column1, #abc.column2 |",
"| | Filter: #abc.column2 = Int64(5) |",
"| | TableScan: abc projection=Some([0, 1]) |",
"| physical_plan | EmptyExec: produce_one_row=false |",
"| | |",
"+---------------+----------------------------------------------+",
"+---------------+----------------------------------------------------------+",
"| plan_type | plan |",
"+---------------+----------------------------------------------------------+",
"| logical_plan | CreateView: \"xyz\" |",
"| | Projection: #abc.column1, #abc.column2 |",
"| | Filter: #abc.column2 = Int64(5) |",
"| | TableScan: abc projection=Some([column1, column2]) |",
"| physical_plan | EmptyExec: produce_one_row=false |",
"| | |",
"+---------------+----------------------------------------------------------+",
];

assert_batches_eq!(expected, &results);
Expand Down
8 changes: 4 additions & 4 deletions datafusion/core/src/logical_plan/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ mod tests {

let expected = "Projection: #employee_csv.id\
\n Filter: #employee_csv.state = Utf8(\"CO\")\
\n TableScan: employee_csv projection=Some([0, 3])";
\n TableScan: employee_csv projection=Some([id, state])";

assert_eq!(expected, format!("{}", plan.display_indent()));
}
Expand All @@ -143,7 +143,7 @@ mod tests {

let expected = "Projection: #employee_csv.id [id:Int32]\
\n Filter: #employee_csv.state = Utf8(\"CO\") [id:Int32, state:Utf8]\
\n TableScan: employee_csv projection=Some([0, 3]) [id:Int32, state:Utf8]";
\n TableScan: employee_csv projection=Some([id, state]) [id:Int32, state:Utf8]";

assert_eq!(expected, format!("{}", plan.display_indent_schema()));
}
Expand All @@ -165,12 +165,12 @@ mod tests {
);
assert!(
graphviz.contains(
r#"[shape=box label="TableScan: employee_csv projection=Some([0, 3])"]"#
r#"[shape=box label="TableScan: employee_csv projection=Some([id, state])"]"#
),
"\n{}",
plan.display_graphviz()
);
assert!(graphviz.contains(r#"[shape=box label="TableScan: employee_csv projection=Some([0, 3])\nSchema: [id:Int32, state:Utf8]"]"#),
assert!(graphviz.contains(r#"[shape=box label="TableScan: employee_csv projection=Some([id, state])\nSchema: [id:Int32, state:Utf8]"]"#),
"\n{}", plan.display_graphviz());
assert!(
graphviz.contains(r#"// End DataFusion GraphViz Plan"#),
Expand Down
2 changes: 1 addition & 1 deletion datafusion/core/tests/custom_sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ async fn custom_source_dataframe() -> Result<()> {

let expected = format!(
"Projection: #{}.c2\
\n TableScan: {} projection=Some([1])",
\n TableScan: {} projection=Some([c2])",
UNNAMED_TABLE, UNNAMED_TABLE
);
assert_eq!(format!("{:?}", optimized_plan), expected);
Expand Down
2 changes: 1 addition & 1 deletion datafusion/core/tests/sql/avro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ async fn avro_explain() {
"logical_plan",
"Projection: #COUNT(UInt8(1))\
\n Aggregate: groupBy=[[]], aggr=[[COUNT(UInt8(1))]]\
\n TableScan: alltypes_plain projection=Some([0])",
\n TableScan: alltypes_plain projection=Some([id])",
],
vec![
"physical_plan",
Expand Down
26 changes: 13 additions & 13 deletions datafusion/core/tests/sql/explain_analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ async fn csv_explain_plans() {
"Explain [plan_type:Utf8, plan:Utf8]",
" Projection: #aggregate_test_100.c1 [c1:Utf8]",
" Filter: #aggregate_test_100.c2 > Int64(10) [c1:Utf8, c2:Int32]",
" TableScan: aggregate_test_100 projection=Some([0, 1]), partial_filters=[#aggregate_test_100.c2 > Int64(10)] [c1:Utf8, c2:Int32]",
" TableScan: aggregate_test_100 projection=Some([c1, c2]), partial_filters=[#aggregate_test_100.c2 > Int64(10)] [c1:Utf8, c2:Int32]",
];
let formatted = plan.display_indent_schema().to_string();
let actual: Vec<&str> = formatted.trim().lines().collect();
Expand All @@ -284,7 +284,7 @@ async fn csv_explain_plans() {
"Explain",
" Projection: #aggregate_test_100.c1",
" Filter: #aggregate_test_100.c2 > Int64(10)",
" TableScan: aggregate_test_100 projection=Some([0, 1]), partial_filters=[#aggregate_test_100.c2 > Int64(10)]",
" TableScan: aggregate_test_100 projection=Some([c1, c2]), partial_filters=[#aggregate_test_100.c2 > Int64(10)]",
];
let formatted = plan.display_indent().to_string();
let actual: Vec<&str> = formatted.trim().lines().collect();
Expand All @@ -306,7 +306,7 @@ async fn csv_explain_plans() {
" 2 -> 3 [arrowhead=none, arrowtail=normal, dir=back]",
" 4[shape=box label=\"Filter: #aggregate_test_100.c2 > Int64(10)\"]",
" 3 -> 4 [arrowhead=none, arrowtail=normal, dir=back]",
" 5[shape=box label=\"TableScan: aggregate_test_100 projection=Some([0, 1]), partial_filters=[#aggregate_test_100.c2 > Int64(10)]\"]",
" 5[shape=box label=\"TableScan: aggregate_test_100 projection=Some([c1, c2]), partial_filters=[#aggregate_test_100.c2 > Int64(10)]\"]",
" 4 -> 5 [arrowhead=none, arrowtail=normal, dir=back]",
" }",
" subgraph cluster_6",
Expand All @@ -317,7 +317,7 @@ async fn csv_explain_plans() {
" 7 -> 8 [arrowhead=none, arrowtail=normal, dir=back]",
" 9[shape=box label=\"Filter: #aggregate_test_100.c2 > Int64(10)\\nSchema: [c1:Utf8, c2:Int32]\"]",
" 8 -> 9 [arrowhead=none, arrowtail=normal, dir=back]",
" 10[shape=box label=\"TableScan: aggregate_test_100 projection=Some([0, 1]), partial_filters=[#aggregate_test_100.c2 > Int64(10)]\\nSchema: [c1:Utf8, c2:Int32]\"]",
" 10[shape=box label=\"TableScan: aggregate_test_100 projection=Some([c1, c2]), partial_filters=[#aggregate_test_100.c2 > Int64(10)]\\nSchema: [c1:Utf8, c2:Int32]\"]",
" 9 -> 10 [arrowhead=none, arrowtail=normal, dir=back]",
" }",
"}",
Expand Down Expand Up @@ -467,7 +467,7 @@ async fn csv_explain_verbose_plans() {
"Explain [plan_type:Utf8, plan:Utf8]",
" Projection: #aggregate_test_100.c1 [c1:Utf8]",
" Filter: #aggregate_test_100.c2 > Int64(10) [c1:Utf8, c2:Int32]",
" TableScan: aggregate_test_100 projection=Some([0, 1]), partial_filters=[#aggregate_test_100.c2 > Int64(10)] [c1:Utf8, c2:Int32]",
" TableScan: aggregate_test_100 projection=Some([c1, c2]), partial_filters=[#aggregate_test_100.c2 > Int64(10)] [c1:Utf8, c2:Int32]",
];
let formatted = plan.display_indent_schema().to_string();
let actual: Vec<&str> = formatted.trim().lines().collect();
Expand All @@ -482,7 +482,7 @@ async fn csv_explain_verbose_plans() {
"Explain",
" Projection: #aggregate_test_100.c1",
" Filter: #aggregate_test_100.c2 > Int64(10)",
" TableScan: aggregate_test_100 projection=Some([0, 1]), partial_filters=[#aggregate_test_100.c2 > Int64(10)]",
" TableScan: aggregate_test_100 projection=Some([c1, c2]), partial_filters=[#aggregate_test_100.c2 > Int64(10)]",
];
let formatted = plan.display_indent().to_string();
let actual: Vec<&str> = formatted.trim().lines().collect();
Expand All @@ -504,7 +504,7 @@ async fn csv_explain_verbose_plans() {
" 2 -> 3 [arrowhead=none, arrowtail=normal, dir=back]",
" 4[shape=box label=\"Filter: #aggregate_test_100.c2 > Int64(10)\"]",
" 3 -> 4 [arrowhead=none, arrowtail=normal, dir=back]",
" 5[shape=box label=\"TableScan: aggregate_test_100 projection=Some([0, 1]), partial_filters=[#aggregate_test_100.c2 > Int64(10)]\"]",
" 5[shape=box label=\"TableScan: aggregate_test_100 projection=Some([c1, c2]), partial_filters=[#aggregate_test_100.c2 > Int64(10)]\"]",
" 4 -> 5 [arrowhead=none, arrowtail=normal, dir=back]",
" }",
" subgraph cluster_6",
Expand All @@ -515,7 +515,7 @@ async fn csv_explain_verbose_plans() {
" 7 -> 8 [arrowhead=none, arrowtail=normal, dir=back]",
" 9[shape=box label=\"Filter: #aggregate_test_100.c2 > Int64(10)\\nSchema: [c1:Utf8, c2:Int32]\"]",
" 8 -> 9 [arrowhead=none, arrowtail=normal, dir=back]",
" 10[shape=box label=\"TableScan: aggregate_test_100 projection=Some([0, 1]), partial_filters=[#aggregate_test_100.c2 > Int64(10)]\\nSchema: [c1:Utf8, c2:Int32]\"]",
" 10[shape=box label=\"TableScan: aggregate_test_100 projection=Some([c1, c2]), partial_filters=[#aggregate_test_100.c2 > Int64(10)]\\nSchema: [c1:Utf8, c2:Int32]\"]",
" 9 -> 10 [arrowhead=none, arrowtail=normal, dir=back]",
" }",
"}",
Expand Down Expand Up @@ -628,12 +628,12 @@ order by
\n Inner Join: #customer.c_nationkey = #nation.n_nationkey\
\n Inner Join: #orders.o_orderkey = #lineitem.l_orderkey\
\n Inner Join: #customer.c_custkey = #orders.o_custkey\
\n TableScan: customer projection=Some([0, 1, 2, 3, 4, 5, 7])\
\n TableScan: customer projection=Some([c_custkey, c_name, c_address, c_nationkey, c_phone, c_acctbal, c_comment])\
\n Filter: #orders.o_orderdate >= Date32(\"8674\") AND #orders.o_orderdate < Date32(\"8766\")\
\n TableScan: orders projection=Some([0, 1, 4]), partial_filters=[#orders.o_orderdate >= Date32(\"8674\"), #orders.o_orderdate < Date32(\"8766\")]\
\n TableScan: orders projection=Some([o_orderkey, o_custkey, o_orderdate]), partial_filters=[#orders.o_orderdate >= Date32(\"8674\"), #orders.o_orderdate < Date32(\"8766\")]\
\n Filter: #lineitem.l_returnflag = Utf8(\"R\")\
\n TableScan: lineitem projection=Some([0, 5, 6, 8]), partial_filters=[#lineitem.l_returnflag = Utf8(\"R\")]\
\n TableScan: nation projection=Some([0, 1])";
\n TableScan: lineitem projection=Some([l_orderkey, l_extendedprice, l_discount, l_returnflag]), partial_filters=[#lineitem.l_returnflag = Utf8(\"R\")]\
\n TableScan: nation projection=Some([n_nationkey, n_name])";
assert_eq!(format!("{:?}", plan.unwrap()), expected);

Ok(())
Expand Down Expand Up @@ -753,7 +753,7 @@ async fn csv_explain() {
"logical_plan",
"Projection: #aggregate_test_100.c1\
\n Filter: #aggregate_test_100.c2 > Int64(10)\
\n TableScan: aggregate_test_100 projection=Some([0, 1]), partial_filters=[#aggregate_test_100.c2 > Int64(10)]"
\n TableScan: aggregate_test_100 projection=Some([c1, c2]), partial_filters=[#aggregate_test_100.c2 > Int64(10)]"
],
vec!["physical_plan",
"ProjectionExec: expr=[c1@0 as c1]\
Expand Down
2 changes: 1 addition & 1 deletion datafusion/core/tests/sql/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async fn json_explain() {
"logical_plan",
"Projection: #COUNT(UInt8(1))\
\n Aggregate: groupBy=[[]], aggr=[[COUNT(UInt8(1))]]\
\n TableScan: t1 projection=Some([0])",
\n TableScan: t1 projection=Some([a])",
],
vec![
"physical_plan",
Expand Down
4 changes: 2 additions & 2 deletions datafusion/core/tests/sql/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ async fn projection_on_table_scan() -> Result<()> {
}

let expected = "Projection: #test.c2\
\n TableScan: test projection=Some([1])";
\n TableScan: test projection=Some([c2])";
assert_eq!(format!("{:?}", optimized_plan), expected);

let physical_plan = ctx.create_physical_plan(&optimized_plan).await?;
Expand Down Expand Up @@ -264,7 +264,7 @@ async fn projection_on_memory_scan() -> Result<()> {

let expected = format!(
"Projection: #{}.b\
\n TableScan: {} projection=Some([1])",
\n TableScan: {} projection=Some([b])",
UNNAMED_TABLE, UNNAMED_TABLE
);
assert_eq!(format!("{:?}", optimized_plan), expected);
Expand Down
2 changes: 1 addition & 1 deletion datafusion/core/tests/sql/udf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async fn scalar_udf() -> Result<()> {

assert_eq!(
format!("{:?}", plan),
"Projection: #t.a, #t.b, my_add(#t.a, #t.b)\n TableScan: t projection=Some([0, 1])"
"Projection: #t.a, #t.b, my_add(#t.a, #t.b)\n TableScan: t projection=Some([a, b])"
);

let plan = ctx.optimize(&plan)?;
Expand Down
2 changes: 1 addition & 1 deletion datafusion/core/tests/user_defined_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ async fn topk_plan() -> Result<()> {
let mut expected = vec![
"| logical_plan after topk | TopK: k=3 |",
"| | Projection: #sales.customer_id, #sales.revenue |",
"| | TableScan: sales projection=Some([0, 1]) |",
"| | TableScan: sales projection=Some([customer_id, revenue]) |",
].join("\n");

let explain_query = format!("EXPLAIN VERBOSE {}", QUERY);
Expand Down
14 changes: 7 additions & 7 deletions datafusion/expr/src/logical_plan/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ mod tests {

let expected = "Projection: #employee_csv.id\
\n Filter: #employee_csv.state = Utf8(\"CO\")\
\n TableScan: employee_csv projection=Some([0, 3])";
\n TableScan: employee_csv projection=Some([id, state])";

assert_eq!(expected, format!("{:?}", plan));

Expand Down Expand Up @@ -1024,7 +1024,7 @@ mod tests {
\n Limit: 10\
\n Projection: #employee_csv.state, #total_salary\
\n Aggregate: groupBy=[[#employee_csv.state]], aggr=[[SUM(#employee_csv.salary) AS total_salary]]\
\n TableScan: employee_csv projection=Some([3, 4])";
\n TableScan: employee_csv projection=Some([state, salary])";

assert_eq!(expected, format!("{:?}", plan));

Expand All @@ -1050,7 +1050,7 @@ mod tests {
.build()?;

let expected = "Sort: #employee_csv.state ASC NULLS FIRST, #employee_csv.salary DESC NULLS LAST\
\n TableScan: employee_csv projection=Some([3, 4])";
\n TableScan: employee_csv projection=Some([state, salary])";

assert_eq!(expected, format!("{:?}", plan));

Expand Down Expand Up @@ -1090,10 +1090,10 @@ mod tests {

// output has only one union
let expected = "Union\
\n TableScan: employee_csv projection=Some([3, 4])\
\n TableScan: employee_csv projection=Some([3, 4])\
\n TableScan: employee_csv projection=Some([3, 4])\
\n TableScan: employee_csv projection=Some([3, 4])";
\n TableScan: employee_csv projection=Some([state, salary])\
\n TableScan: employee_csv projection=Some([state, salary])\
\n TableScan: employee_csv projection=Some([state, salary])\
\n TableScan: employee_csv projection=Some([state, salary])";

assert_eq!(expected, format!("{:?}", plan));

Expand Down
Loading