-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix: display the content of debug explain #434
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
Conversation
datafusion/tests/sql.rs
Outdated
| let actual = format!("{}", plan.display_indent_schema()); | ||
| assert_eq!(expected, actual); | ||
| // Verify the text format of the plan | ||
| let expected = "Explain"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, the output of the logical plan for explain only incldues the word "Explain". Should we add the plan of the explain's select?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think including the plan tree like
Explain
Project
Filter
Scan
Makes more sense than the current output of:
Explain
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. I actually made this happen in a different branch but want to verify with you first. Will bring it in here
datafusion/tests/sql.rs
Outdated
| 4[shape=box label=\"Explain\\nSchema: [plan_type:Utf8, plan:Utf8]\"]\n | ||
| }\n | ||
| }\n | ||
| // End DataFusion GraphViz Plan"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, the graphviz has nothing but Explain and the explain's schema node. Should it includes full explain of its plan's nodes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should include the actual plan that is being explained
datafusion/tests/sql.rs
Outdated
| let actual = format!("{}", plan.display_indent_schema()); | ||
| assert_eq!(expected, actual); | ||
| // Verify the text format of the plan | ||
| let expected = "Explain"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, display of optimized logical plan has almost nothing in there
datafusion/tests/sql.rs
Outdated
| graph[label=\"Detailed LogicalPlan\"]\n | ||
| 4[shape=box label=\"Explain\\nSchema: [plan_type:Utf8, plan:Utf8]\"]\n | ||
| }\n | ||
| }\n |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, graphviz does not have any useful info
datafusion/tests/sql.rs
Outdated
| let msg = format!("Creating physical plan for '{}': {:?}", sql, plan); | ||
| let plan = ctx.create_physical_plan(&plan).expect(&msg); | ||
| // Verify the text format of the plan | ||
| let expected = "ExplainExec"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, display of physical plan has no useful info at all
alamb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think including the input to the Explain node makes sense. Any thoughts @Dandandan or @andygrove ?
datafusion/tests/sql.rs
Outdated
| let actual = format!("{}", plan.display_indent_schema()); | ||
| assert_eq!(expected, actual); | ||
| // Verify the text format of the plan | ||
| let expected = "Explain"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think including the plan tree like
Explain
Project
Filter
Scan
Makes more sense than the current output of:
Explain
datafusion/tests/sql.rs
Outdated
| 4[shape=box label=\"Explain\\nSchema: [plan_type:Utf8, plan:Utf8]\"]\n | ||
| }\n | ||
| }\n | ||
| // End DataFusion GraphViz Plan"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should include the actual plan that is being explained
Makes sense to me |
| } | ||
| true | ||
| } | ||
| LogicalPlan::Explain { plan, .. } => plan.accept(visitor)?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the fix that enables LogicalPlan's display_... functions to show all info of the plan. The newly added tests capture this fix.
| LogicalPlan::Limit { input, .. } => vec![input], | ||
| LogicalPlan::Extension { node } => node.inputs(), | ||
| LogicalPlan::Union { inputs, .. } => inputs.iter().collect(), | ||
| LogicalPlan::Explain { plan, .. } => vec![plan], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the fix that progpagates the optimization down the plan explain
| LogicalPlan::Explain { .. } => { | ||
| // push the optimization to the plan of this explain | ||
| push_down(&state, plan) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is related to the fix to propagate the optimization down
alamb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code changes look good to me @NGA-TRAN -- thank you.
I had a suggestion on how to make the tests perhaps easier to maintain (and easier to see what was different)
datafusion/src/logical_plan/plan.rs
Outdated
| | LogicalPlan::EmptyRelation { .. } | ||
| | LogicalPlan::CreateExternalTable { .. } | ||
| | LogicalPlan::Explain { .. } => vec![], | ||
| //| LogicalPlan::Explain { .. } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| //| LogicalPlan::Explain { .. } |
I think we can remove this line entirely (no need to leave it in)
| Filter: #c2 Gt Int64(10) [c1:Utf8, c2:Int32]\n | ||
| TableScan: aggregate_test_100 projection=Some([0, 1]) [c1:Utf8, c2:Int32]"; | ||
| let actual = format!("{}", plan.display_indent_schema()); | ||
| assert_eq!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests look somewhat challenging to maintain. What do you think about the following pattern (mostly copied from assert_batches_eq!:
let expected_lines = vec![
"Explain [plan_type:Utf8, plan:Utf8]",
" Projection: #c1 [c1:Utf8]",
...
];
let formatted = plan.display_indent_schema().to_string();
let actual_lines: Vec<&str> = formatted.trim().lines().collect();
assert_eq!(
expected_lines, actual_lines,
"\n\nexpected:\n\n{:#?}\nactual:\n\n{:#?}\n\n",
expected_lines, actual_lines
);There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed
NGA-TRAN
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @alamb for your review comments. I have addressed them.
| Filter: #c2 Gt Int64(10) [c1:Utf8, c2:Int32]\n | ||
| TableScan: aggregate_test_100 projection=Some([0, 1]) [c1:Utf8, c2:Int32]"; | ||
| let actual = format!("{}", plan.display_indent_schema()); | ||
| assert_eq!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed
alamb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is looking great @NGA-TRAN -- thank you
jorgecarleitao
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Impressive testing, @NGA-TRAN 💯
|
@NGA-TRAN it looks like this may have failed on windows: https://github.com/apache/arrow-datafusion/pull/434/checks?check_run_id=2720284528 |
|
| @NGA-TRAN it looks like this may have failed on windows: https://github.com/apache/arrow-datafusion/pull/434/checks?check_run_id=2720284528 Silly me. Working on it. Thanks @alamb |
Codecov Report
@@ Coverage Diff @@
## master #434 +/- ##
==========================================
+ Coverage 75.72% 75.84% +0.11%
==========================================
Files 143 153 +10
Lines 23910 25872 +1962
==========================================
+ Hits 18107 19622 +1515
- Misses 5803 6250 +447
Continue to review full report at Codecov.
|
|
@alamb Finally all checks have passed :) |
Which issue does this PR close?
Closes #430
Rationale for this change
What changes are included in this PR?
There are 2 main changes:
display_functions to have them display the plan content for not only executing plans but also theexplainonesexplainAre there any user-facing changes?
. Number 1 won't because they are currently used for debug only
. Number 2 will help other TableProvider to push their predicate down correctly (ref: https://github.com/influxdata/influxdb_iox/issues/1538)