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/06/01 15:46:35 UTC

[GitHub] [arrow-datafusion] NGA-TRAN commented on a change in pull request #434: fix: display the content of debug explain

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



##########
File path: datafusion/tests/sql.rs
##########
@@ -1573,6 +1575,173 @@ 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]\n
+      Projection: #c1 [c1:Utf8]\n
+          Filter: #c2 Gt Int64(10) [c1:Utf8, c2:Int32, c3:Int16, c4:Int16, c5:Int32, c6:Int64, c7:Int16, c8:Int32, c9:Int64, c10:Utf8, c11:Float32, c12:Float64, c13:Utf8]\n
+                TableScan: aggregate_test_100 projection=None [c1:Utf8, c2:Int32, c3:Int16, c4:Int16, c5:Int32, c6:Int64, c7:Int16, c8:Int32, c9:Int64, c10:Utf8, c11:Float32, c12:Float64, c13:Utf8]";
+    let actual = format!("{}", plan.display_indent_schema());
+    assert_eq!(
+        expected
+            .replace("\t", "")
+            .replace("\n", "")
+            .replace(" ", ""),
+        actual.replace("\t", "").replace("\n", "").replace(" ", "")
+    );
+    //
+    // Verify the text format of the plan
+    let expected = "Explain\n  Projection: #c1\n
+        Filter: #c2 Gt Int64(10)\n
+              TableScan: aggregate_test_100 projection=None";
+    let actual = format!("{}", plan.display_indent());
+    assert_eq!(
+        expected
+            .replace("\t", "")
+            .replace("\n", "")
+            .replace(" ", ""),
+        actual.replace("\t", "").replace("\n", "").replace(" ", "")
+    );
+    //
+    // 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
+                    3[shape=box label=\"Projection: #c1\"]\n
+                    2 -> 3 [arrowhead=none, arrowtail=normal, dir=back]\n
+                    4[shape=box label=\"Filter: #c2 Gt Int64(10)\"]\n
+                    3 -> 4 [arrowhead=none, arrowtail=normal, dir=back]\n
+                    5[shape=box label=\"TableScan: aggregate_test_100 projection=None\"]\n
+                    4 -> 5 [arrowhead=none, arrowtail=normal, dir=back]\n
+            }\n
+         subgraph cluster_6\n
+            {\n
+                graph[label=\"Detailed LogicalPlan\"]\n
+                    7[shape=box label=\"Explain\\nSchema: [plan_type:Utf8, plan:Utf8]\"]\n
+                    8[shape=box label=\"Projection: #c1\\nSchema: [c1:Utf8]\"]\n
+                    7 -> 8 [arrowhead=none, arrowtail=normal, dir=back]\n
+                    9[shape=box label=\"Filter: #c2 Gt Int64(10)\\nSchema: [c1:Utf8, c2:Int32, c3:Int16, c4:Int16, c5:Int32, c6:Int64, c7:Int16, c8:Int32, c9:Int64, c10:Utf8, c11:Float32, c12:Float64, c13:Utf8]\"]\n
+                    8 -> 9 [arrowhead=none, arrowtail=normal, dir=back]\n
+                    10[shape=box label=\"TableScan: aggregate_test_100 projection=None\\nSchema: [c1:Utf8, c2:Int32, c3:Int16, c4:Int16, c5:Int32, c6:Int64, c7:Int16, c8:Int32, c9:Int64, c10:Utf8, c11:Float32, c12:Float64, c13:Utf8]\"]\n
+                    9 -> 10 [arrowhead=none, arrowtail=normal, dir=back]\n
+            }\n
+    }\n
+    // End DataFusion GraphViz Plan\n";
+    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]\n
+      Projection: #c1 [c1:Utf8]\n
+          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!(

Review comment:
       Addressed




-- 
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