Skip to content

Commit

Permalink
[SPARK-30684 ][WEBUI][FollowUp] A new approach for SPARK-30684
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?

Simplify the changes for adding metrics description for WholeStageCodegen in apache#27405

### Why are the changes needed?

In apache#27405, the UI changes can be made without using the function `adjustPositionOfOperationName` to adjust the position of operation name and mark as an operation-name class.

I suggest we make simpler changes so that it would be easier for future development.

### Does this PR introduce any user-facing change?

No

### How was this patch tested?

Manual test with the queries provided in apache#27405
```
sc.parallelize(1 to 10).toDF.sort("value").filter("value > 1").selectExpr("value * 2").show
sc.parallelize(1 to 10).toDF.sort("value").filter("value > 1").selectExpr("value * 2").write.format("json").mode("overwrite").save("/tmp/test_output")
sc.parallelize(1 to 10).toDF.write.format("json").mode("append").save("/tmp/test_output")
```
![image](https://user-images.githubusercontent.com/1097932/74073629-e3f09f00-49bf-11ea-90dc-1edb5ca29e5e.png)

Closes apache#27490 from gengliangwang/wholeCodegenUI.

Authored-by: Gengliang Wang <gengliang.wang@databricks.com>
Signed-off-by: Gengliang Wang <gengliang.wang@databricks.com>
  • Loading branch information
gengliangwang committed Feb 9, 2020
1 parent 339c0f9 commit b877aac
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#plan-viz-graph .label {
font-weight: normal;
text-shadow: none;
color: black;
}

#plan-viz-graph svg g.cluster rect {
Expand All @@ -32,13 +33,8 @@
stroke-width: 1px;
}

/* This declaration is needed to define the width of rectangles */
#plan-viz-graph svg text :first-child {
font-weight: bold;
}

/* Highlight the SparkPlan node name */
#plan-viz-graph svg text .operator-name {
#plan-viz-graph svg text :first-child {
font-weight: bold;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ function renderPlanViz() {
preprocessGraphLayout(g);
var renderer = new dagreD3.render();
renderer(graph, g);
adjustPositionOfOperationName();

// Round corners on rectangles
svg
Expand Down Expand Up @@ -82,7 +81,7 @@ function setupTooltipForSparkPlanNode(nodeId) {
* and sizes of graph elements, e.g. padding, font style, shape.
*/
function preprocessGraphLayout(g) {
g.graph().ranksep = "90";
g.graph().ranksep = "70";
var nodes = g.nodes();
for (var i = 0; i < nodes.length; i++) {
var node = g.node(nodes[i]);
Expand Down Expand Up @@ -129,34 +128,6 @@ function resizeSvg(svg) {
.attr("height", height);
}


/* Helper function to adjust the position of operation name and mark as a operation-name class. */
function adjustPositionOfOperationName() {
$("#plan-viz-graph svg text")
.each(function() {
var tspans = $(this).find("tspan");

if (tspans[0].textContent.trim() !== "") {
var isOperationNameOnly =
$(tspans).filter(function(i, n) {
return i !== 0 && n.textContent.trim() !== "";
}).length === 0;

if (isOperationNameOnly) {
// If the only text in a node is operation name,
// vertically centering the position of operation name.
var operationName = tspans[0].textContent;
var half = parseInt(tspans.length / 2);
tspans[0].textContent = tspans[half].textContent;
tspans[half].textContent = operationName;
$(tspans[half]).addClass("operator-name");
} else {
tspans.first().addClass("operator-name");
}
}
});
}

/* Helper function to convert attributes to numeric values. */
function toFloat(f) {
if (f) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,18 @@ private[ui] class SparkPlanGraphNode(
metric.name + ": " + value
}

// If there are metrics, display each entry in a separate line.
// Note: whitespace between two "\n"s is to create an empty line between the name of
// SparkPlan and metrics. If removing it, it won't display the empty line in UI.
builder ++= "\n \n"

if (values.nonEmpty) {
// If there are metrics, display each entry in a separate line.
// Note: whitespace between two "\n"s is to create an empty line between the name of
// SparkPlan and metrics. If removing it, it won't display the empty line in UI.
builder ++= "\n \n"
builder ++= values.mkString("\n")
s""" $id [label="${StringEscapeUtils.escapeJava(builder.toString())}"];"""
} else {
// A certain level of height is needed for a rect as a node in a sub-graph
// to avoid layout collapse for sub-graphs.
builder ++= " "
// SPARK-30684: when there is no metrics, add empty lines to increase the height of the node,
// so that there won't be gaps between an edge and a small node.
s""" $id [labelType="html" label="<br><b>$name</b><br><br>"];"""
}

s""" $id [label="${StringEscapeUtils.escapeJava(builder.toString())}"];"""
}
}

Expand Down

0 comments on commit b877aac

Please sign in to comment.