Skip to content

Commit

Permalink
[SPARK-13755] Escape quotes in SQL plan visualization node labels
Browse files Browse the repository at this point in the history
When generating Graphviz DOT files in the SQL query visualization we need to escape double-quotes inside node labels. This is a followup to #11309, which fixed a similar graph in Spark Core's DAG visualization.

Author: Josh Rosen <joshrosen@databricks.com>

Closes #11587 from JoshRosen/graphviz-escaping.
  • Loading branch information
JoshRosen committed Mar 9, 2016
1 parent e430614 commit 81f54ac
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import java.util.concurrent.atomic.AtomicLong

import scala.collection.mutable

import org.apache.commons.lang3.StringEscapeUtils

import org.apache.spark.sql.execution.SparkPlanInfo
import org.apache.spark.sql.execution.metric.SQLMetrics

Expand Down Expand Up @@ -136,16 +138,14 @@ private[ui] class SparkPlanGraphNode(
}

if (values.nonEmpty) {
// If there are metrics, display each entry in a separate line. We should use an escaped
// "\n" here to follow the dot syntax.
//
// 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")
builder ++= "\n \n"
builder ++= values.mkString("\n")
}

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

Expand All @@ -162,7 +162,7 @@ private[ui] class SparkPlanGraphCluster(
override def makeDotNode(metricsValue: Map[Long, String]): String = {
s"""
| subgraph cluster${id} {
| label=${name};
| label="${StringEscapeUtils.escapeJava(name)}";
| ${nodes.map(_.makeDotNode(metricsValue)).mkString(" \n")}
| }
""".stripMargin
Expand Down

0 comments on commit 81f54ac

Please sign in to comment.