What tools to use to visualize logical and physical query plans?

孤人 提交于 2021-01-04 05:35:18

问题


I am familiar explain() (also WebUI). I was curious whether there are any tools that generate an image of the tree structure of the logical/physical plan before/after optimizations. That is the information returned by explain() as an image.


回答1:


A picture like a PNG or JPG? Never heard of one myself, but you can see the physical plan using web UI (that you've already mentioned).

The other phases of query execution are available using TreeNode methods which (among many methods that could help you out) give you my favorite numberedTreeString.

scala> println(q.queryExecution.analyzed.numberedTreeString)
00 Range (0, 5, step=1, splits=Some(8))

scala> println(q.queryExecution.executedPlan.numberedTreeString)
00 *Range (0, 5, step=1, splits=8)

You can save the output as JSON using toJSON or prettyJson to generate PNG (but I've never tried it out myself).

scala> println(q.queryExecution.executedPlan.prettyJson)
[ {
  "class" : "org.apache.spark.sql.execution.WholeStageCodegenExec",
  "num-children" : 1,
  "child" : 0
}, {
  "class" : "org.apache.spark.sql.execution.RangeExec",
  "num-children" : 0,
  "range" : [ {
    "class" : "org.apache.spark.sql.catalyst.plans.logical.Range",
    "num-children" : 0,
    "start" : 0,
    "end" : 5,
    "step" : 1,
    "numSlices" : 8,
    "output" : [ [ {
      "class" : "org.apache.spark.sql.catalyst.expressions.AttributeReference",
      "num-children" : 0,
      "name" : "id",
      "dataType" : "long",
      "nullable" : false,
      "metadata" : { },
      "exprId" : {
        "product-class" : "org.apache.spark.sql.catalyst.expressions.ExprId",
        "id" : 0,
        "jvmId" : "cb497d01-3b90-42a7-9ebf-ebe85578f763"
      },
      "isGenerated" : false
    } ] ]
  } ]
} ]


来源:https://stackoverflow.com/questions/44242201/what-tools-to-use-to-visualize-logical-and-physical-query-plans

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!