You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/05/27 20:02:20 UTC

[GitHub] [arrow-datafusion] NGA-TRAN commented on a change in pull request #434: test: display of each query plan during plan generation

NGA-TRAN commented on a change in pull request #434:
URL: https://github.com/apache/arrow-datafusion/pull/434#discussion_r640926298



##########
File path: datafusion/tests/sql.rs
##########
@@ -1573,6 +1575,101 @@ async fn csv_explain() {
     assert_eq!(expected, actual);
 }
 
+#[tokio::test]
+async fn csv_explain_plans() {
+    // This test verify the look of each plan in its full cycle plan creation
+
+    let mut ctx = ExecutionContext::new();
+    register_aggregate_csv_by_sql(&mut ctx).await;
+    let sql = "EXPLAIN SELECT c1 FROM aggregate_test_100 where c2 > 10";
+
+    // Logical plan
+    // Create plan
+    let msg = format!("Creating logical plan for '{}'", sql);
+    let plan = ctx.create_logical_plan(&sql).expect(&msg);
+    let logical_schema = plan.schema();
+    // 
+    println!("SQL: {}", sql);
+    // Verify schema
+    let expected = "Explain [plan_type:Utf8, plan:Utf8]";
+    let actual = format!("{}", plan.display_indent_schema());
+    assert_eq!(expected, actual);
+    // Verify the text format of the plan
+    let expected = "Explain";

Review comment:
       Currently, the output of the logical plan for explain only incldues the word "Explain". Should we add the plan of the explain's select?

##########
File path: datafusion/tests/sql.rs
##########
@@ -1573,6 +1575,101 @@ async fn csv_explain() {
     assert_eq!(expected, actual);
 }
 
+#[tokio::test]
+async fn csv_explain_plans() {
+    // This test verify the look of each plan in its full cycle plan creation
+
+    let mut ctx = ExecutionContext::new();
+    register_aggregate_csv_by_sql(&mut ctx).await;
+    let sql = "EXPLAIN SELECT c1 FROM aggregate_test_100 where c2 > 10";
+
+    // Logical plan
+    // Create plan
+    let msg = format!("Creating logical plan for '{}'", sql);
+    let plan = ctx.create_logical_plan(&sql).expect(&msg);
+    let logical_schema = plan.schema();
+    // 
+    println!("SQL: {}", sql);
+    // Verify schema
+    let expected = "Explain [plan_type:Utf8, plan:Utf8]";
+    let actual = format!("{}", plan.display_indent_schema());
+    assert_eq!(expected, actual);
+    // Verify the text format of the plan
+    let expected = "Explain";
+    let actual = format!("{}", plan.display_indent());
+    assert_eq!(expected, actual);
+    // verify the grahviz format of the plan
+    let expected = "// Begin DataFusion GraphViz Plan (see https://graphviz.org)\n
+    digraph {\n
+      subgraph cluster_1\n
+      {\n
+        graph[label=\"LogicalPlan\"]\n
+        2[shape=box label=\"Explain\"]\n
+      }\n
+      subgraph cluster_3\n
+      {\n
+        graph[label=\"Detailed LogicalPlan\"]\n
+        4[shape=box label=\"Explain\\nSchema: [plan_type:Utf8, plan:Utf8]\"]\n
+      }\n
+    }\n
+    // End DataFusion GraphViz Plan";

Review comment:
       Similarly, the graphviz has nothing but Explain and the explain's schema node. Should it includes full explain of its plan's nodes?
   

##########
File path: datafusion/tests/sql.rs
##########
@@ -1573,6 +1575,101 @@ async fn csv_explain() {
     assert_eq!(expected, actual);
 }
 
+#[tokio::test]
+async fn csv_explain_plans() {
+    // This test verify the look of each plan in its full cycle plan creation
+
+    let mut ctx = ExecutionContext::new();
+    register_aggregate_csv_by_sql(&mut ctx).await;
+    let sql = "EXPLAIN SELECT c1 FROM aggregate_test_100 where c2 > 10";
+
+    // Logical plan
+    // Create plan
+    let msg = format!("Creating logical plan for '{}'", sql);
+    let plan = ctx.create_logical_plan(&sql).expect(&msg);
+    let logical_schema = plan.schema();
+    // 
+    println!("SQL: {}", sql);
+    // Verify schema
+    let expected = "Explain [plan_type:Utf8, plan:Utf8]";
+    let actual = format!("{}", plan.display_indent_schema());
+    assert_eq!(expected, actual);
+    // Verify the text format of the plan
+    let expected = "Explain";
+    let actual = format!("{}", plan.display_indent());
+    assert_eq!(expected, actual);
+    // verify the grahviz format of the plan
+    let expected = "// Begin DataFusion GraphViz Plan (see https://graphviz.org)\n
+    digraph {\n
+      subgraph cluster_1\n
+      {\n
+        graph[label=\"LogicalPlan\"]\n
+        2[shape=box label=\"Explain\"]\n
+      }\n
+      subgraph cluster_3\n
+      {\n
+        graph[label=\"Detailed LogicalPlan\"]\n
+        4[shape=box label=\"Explain\\nSchema: [plan_type:Utf8, plan:Utf8]\"]\n
+      }\n
+    }\n
+    // End DataFusion GraphViz Plan";
+    let actual = format!("{}", plan.display_graphviz());
+    assert_eq!(expected.replace("\t","").replace("\n","").replace(" ",""), actual.replace("\t","").replace("\n","").replace(" ",""));
+    // Optimized logical plan
+    //
+    let msg = format!("Optimizing logical plan for '{}': {:?}", sql, plan);
+    let plan = ctx.optimize(&plan).expect(&msg);
+    let optimized_logical_schema = plan.schema();
+    // Both schema has to be the same
+    assert_eq!(logical_schema.as_ref(), optimized_logical_schema.as_ref());
+    // Verify schema
+    let expected = "Explain [plan_type:Utf8, plan:Utf8]";
+    let actual = format!("{}", plan.display_indent_schema());
+    assert_eq!(expected, actual);
+    // Verify the text format of the plan
+    let expected = "Explain";
+    let actual = format!("{}", plan.display_indent());
+    assert_eq!(expected, actual);
+    // verify the grahviz format of the plan
+    let expected = "// Begin DataFusion GraphViz Plan (see https://graphviz.org)\n
+    digraph {\n
+      subgraph cluster_1\n
+      {\n
+        graph[label=\"LogicalPlan\"]\n
+        2[shape=box label=\"Explain\"]\n
+      }\n
+      subgraph cluster_3\n
+      {\n
+        graph[label=\"Detailed LogicalPlan\"]\n
+        4[shape=box label=\"Explain\\nSchema: [plan_type:Utf8, plan:Utf8]\"]\n
+      }\n
+    }\n
+    // End DataFusion GraphViz Plan";
+    let actual = format!("{}", plan.display_graphviz());
+    assert_eq!(expected.replace("\t","").replace("\n","").replace(" ",""), actual.replace("\t","").replace("\n","").replace(" ",""));
+
+    // Physical plan
+    // Create plan
+    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";
+    let actual = format!("{}", displayable(plan.as_ref()).indent());
+    assert_eq!(expected.replace("\t","").replace("\n","").replace(" ",""), actual.replace("\t","").replace("\n","").replace(" ",""));
+
+    // Execute plan
+    let msg = format!("Executing physical plan for '{}': {:?}", sql, plan);
+    let results = collect(plan).await.expect(&msg);
+    // Compare final explain result from execution output
+    let expected = vec![
+        vec!["logical_plan",
+             "Projection: #c1\n  Filter: #c2 Gt Int64(10)\n    TableScan: aggregate_test_100 projection=None"]];

Review comment:
       The useful info only available after execute the EXPLAIN. Should everything above include this information?

##########
File path: datafusion/tests/sql.rs
##########
@@ -1573,6 +1575,101 @@ async fn csv_explain() {
     assert_eq!(expected, actual);
 }
 
+#[tokio::test]
+async fn csv_explain_plans() {
+    // This test verify the look of each plan in its full cycle plan creation
+
+    let mut ctx = ExecutionContext::new();
+    register_aggregate_csv_by_sql(&mut ctx).await;
+    let sql = "EXPLAIN SELECT c1 FROM aggregate_test_100 where c2 > 10";
+
+    // Logical plan
+    // Create plan
+    let msg = format!("Creating logical plan for '{}'", sql);
+    let plan = ctx.create_logical_plan(&sql).expect(&msg);
+    let logical_schema = plan.schema();
+    // 
+    println!("SQL: {}", sql);
+    // Verify schema
+    let expected = "Explain [plan_type:Utf8, plan:Utf8]";
+    let actual = format!("{}", plan.display_indent_schema());
+    assert_eq!(expected, actual);
+    // Verify the text format of the plan
+    let expected = "Explain";
+    let actual = format!("{}", plan.display_indent());
+    assert_eq!(expected, actual);
+    // verify the grahviz format of the plan
+    let expected = "// Begin DataFusion GraphViz Plan (see https://graphviz.org)\n
+    digraph {\n
+      subgraph cluster_1\n
+      {\n
+        graph[label=\"LogicalPlan\"]\n
+        2[shape=box label=\"Explain\"]\n
+      }\n
+      subgraph cluster_3\n
+      {\n
+        graph[label=\"Detailed LogicalPlan\"]\n
+        4[shape=box label=\"Explain\\nSchema: [plan_type:Utf8, plan:Utf8]\"]\n
+      }\n
+    }\n
+    // End DataFusion GraphViz Plan";
+    let actual = format!("{}", plan.display_graphviz());
+    assert_eq!(expected.replace("\t","").replace("\n","").replace(" ",""), actual.replace("\t","").replace("\n","").replace(" ",""));
+    // Optimized logical plan
+    //
+    let msg = format!("Optimizing logical plan for '{}': {:?}", sql, plan);
+    let plan = ctx.optimize(&plan).expect(&msg);
+    let optimized_logical_schema = plan.schema();
+    // Both schema has to be the same
+    assert_eq!(logical_schema.as_ref(), optimized_logical_schema.as_ref());
+    // Verify schema
+    let expected = "Explain [plan_type:Utf8, plan:Utf8]";
+    let actual = format!("{}", plan.display_indent_schema());
+    assert_eq!(expected, actual);
+    // Verify the text format of the plan
+    let expected = "Explain";
+    let actual = format!("{}", plan.display_indent());
+    assert_eq!(expected, actual);
+    // verify the grahviz format of the plan
+    let expected = "// Begin DataFusion GraphViz Plan (see https://graphviz.org)\n
+    digraph {\n
+      subgraph cluster_1\n
+      {\n
+        graph[label=\"LogicalPlan\"]\n
+        2[shape=box label=\"Explain\"]\n
+      }\n
+      subgraph cluster_3\n
+      {\n
+        graph[label=\"Detailed LogicalPlan\"]\n
+        4[shape=box label=\"Explain\\nSchema: [plan_type:Utf8, plan:Utf8]\"]\n
+      }\n
+    }\n
+    // End DataFusion GraphViz Plan";
+    let actual = format!("{}", plan.display_graphviz());
+    assert_eq!(expected.replace("\t","").replace("\n","").replace(" ",""), actual.replace("\t","").replace("\n","").replace(" ",""));
+
+    // Physical plan
+    // Create plan
+    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";

Review comment:
       Similarly, display of physical plan has no useful info at all

##########
File path: datafusion/tests/sql.rs
##########
@@ -1591,6 +1688,105 @@ async fn csv_explain_verbose() {
     assert!(actual.contains("#c2 Gt Int64(10)"), "Actual: '{}'", actual);
 }
 
+#[tokio::test]
+async fn csv_explain_verbose_plans() {

Review comment:
       Same behavior for explain verbose

##########
File path: datafusion/tests/sql.rs
##########
@@ -1573,6 +1575,101 @@ async fn csv_explain() {
     assert_eq!(expected, actual);
 }
 
+#[tokio::test]
+async fn csv_explain_plans() {
+    // This test verify the look of each plan in its full cycle plan creation
+
+    let mut ctx = ExecutionContext::new();
+    register_aggregate_csv_by_sql(&mut ctx).await;
+    let sql = "EXPLAIN SELECT c1 FROM aggregate_test_100 where c2 > 10";
+
+    // Logical plan
+    // Create plan
+    let msg = format!("Creating logical plan for '{}'", sql);
+    let plan = ctx.create_logical_plan(&sql).expect(&msg);
+    let logical_schema = plan.schema();
+    // 
+    println!("SQL: {}", sql);
+    // Verify schema
+    let expected = "Explain [plan_type:Utf8, plan:Utf8]";
+    let actual = format!("{}", plan.display_indent_schema());
+    assert_eq!(expected, actual);
+    // Verify the text format of the plan
+    let expected = "Explain";
+    let actual = format!("{}", plan.display_indent());
+    assert_eq!(expected, actual);
+    // verify the grahviz format of the plan
+    let expected = "// Begin DataFusion GraphViz Plan (see https://graphviz.org)\n
+    digraph {\n
+      subgraph cluster_1\n
+      {\n
+        graph[label=\"LogicalPlan\"]\n
+        2[shape=box label=\"Explain\"]\n
+      }\n
+      subgraph cluster_3\n
+      {\n
+        graph[label=\"Detailed LogicalPlan\"]\n
+        4[shape=box label=\"Explain\\nSchema: [plan_type:Utf8, plan:Utf8]\"]\n
+      }\n
+    }\n
+    // End DataFusion GraphViz Plan";
+    let actual = format!("{}", plan.display_graphviz());
+    assert_eq!(expected.replace("\t","").replace("\n","").replace(" ",""), actual.replace("\t","").replace("\n","").replace(" ",""));
+    // Optimized logical plan
+    //
+    let msg = format!("Optimizing logical plan for '{}': {:?}", sql, plan);
+    let plan = ctx.optimize(&plan).expect(&msg);
+    let optimized_logical_schema = plan.schema();
+    // Both schema has to be the same
+    assert_eq!(logical_schema.as_ref(), optimized_logical_schema.as_ref());
+    // Verify schema
+    let expected = "Explain [plan_type:Utf8, plan:Utf8]";
+    let actual = format!("{}", plan.display_indent_schema());
+    assert_eq!(expected, actual);
+    // Verify the text format of the plan
+    let expected = "Explain";
+    let actual = format!("{}", plan.display_indent());
+    assert_eq!(expected, actual);
+    // verify the grahviz format of the plan
+    let expected = "// Begin DataFusion GraphViz Plan (see https://graphviz.org)\n
+    digraph {\n
+      subgraph cluster_1\n
+      {\n
+        graph[label=\"LogicalPlan\"]\n
+        2[shape=box label=\"Explain\"]\n
+      }\n
+      subgraph cluster_3\n
+      {\n
+        graph[label=\"Detailed LogicalPlan\"]\n
+        4[shape=box label=\"Explain\\nSchema: [plan_type:Utf8, plan:Utf8]\"]\n
+      }\n
+    }\n

Review comment:
       Similarly, graphviz does not have any useful info

##########
File path: datafusion/tests/sql.rs
##########
@@ -1573,6 +1575,101 @@ async fn csv_explain() {
     assert_eq!(expected, actual);
 }
 
+#[tokio::test]
+async fn csv_explain_plans() {
+    // This test verify the look of each plan in its full cycle plan creation
+
+    let mut ctx = ExecutionContext::new();
+    register_aggregate_csv_by_sql(&mut ctx).await;
+    let sql = "EXPLAIN SELECT c1 FROM aggregate_test_100 where c2 > 10";
+
+    // Logical plan
+    // Create plan
+    let msg = format!("Creating logical plan for '{}'", sql);
+    let plan = ctx.create_logical_plan(&sql).expect(&msg);
+    let logical_schema = plan.schema();
+    // 
+    println!("SQL: {}", sql);
+    // Verify schema
+    let expected = "Explain [plan_type:Utf8, plan:Utf8]";
+    let actual = format!("{}", plan.display_indent_schema());
+    assert_eq!(expected, actual);
+    // Verify the text format of the plan
+    let expected = "Explain";
+    let actual = format!("{}", plan.display_indent());
+    assert_eq!(expected, actual);
+    // verify the grahviz format of the plan
+    let expected = "// Begin DataFusion GraphViz Plan (see https://graphviz.org)\n
+    digraph {\n
+      subgraph cluster_1\n
+      {\n
+        graph[label=\"LogicalPlan\"]\n
+        2[shape=box label=\"Explain\"]\n
+      }\n
+      subgraph cluster_3\n
+      {\n
+        graph[label=\"Detailed LogicalPlan\"]\n
+        4[shape=box label=\"Explain\\nSchema: [plan_type:Utf8, plan:Utf8]\"]\n
+      }\n
+    }\n
+    // End DataFusion GraphViz Plan";
+    let actual = format!("{}", plan.display_graphviz());
+    assert_eq!(expected.replace("\t","").replace("\n","").replace(" ",""), actual.replace("\t","").replace("\n","").replace(" ",""));
+    // Optimized logical plan
+    //
+    let msg = format!("Optimizing logical plan for '{}': {:?}", sql, plan);
+    let plan = ctx.optimize(&plan).expect(&msg);
+    let optimized_logical_schema = plan.schema();
+    // Both schema has to be the same
+    assert_eq!(logical_schema.as_ref(), optimized_logical_schema.as_ref());
+    // Verify schema
+    let expected = "Explain [plan_type:Utf8, plan:Utf8]";
+    let actual = format!("{}", plan.display_indent_schema());
+    assert_eq!(expected, actual);
+    // Verify the text format of the plan
+    let expected = "Explain";

Review comment:
       Similarly, display of optimized logical plan has almost nothing in there




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org