Skip to content

Commit 81f54ac

Browse files
committed
[SPARK-13755] Escape quotes in SQL plan visualization node labels
When generating Graphviz DOT files in the SQL query visualization we need to escape double-quotes inside node labels. This is a followup to apache#11309, which fixed a similar graph in Spark Core's DAG visualization. Author: Josh Rosen <joshrosen@databricks.com> Closes apache#11587 from JoshRosen/graphviz-escaping.
1 parent e430614 commit 81f54ac

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/ui/SparkPlanGraph.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import java.util.concurrent.atomic.AtomicLong
2121

2222
import scala.collection.mutable
2323

24+
import org.apache.commons.lang3.StringEscapeUtils
25+
2426
import org.apache.spark.sql.execution.SparkPlanInfo
2527
import org.apache.spark.sql.execution.metric.SQLMetrics
2628

@@ -136,16 +138,14 @@ private[ui] class SparkPlanGraphNode(
136138
}
137139

138140
if (values.nonEmpty) {
139-
// If there are metrics, display each entry in a separate line. We should use an escaped
140-
// "\n" here to follow the dot syntax.
141-
//
141+
// If there are metrics, display each entry in a separate line.
142142
// Note: whitespace between two "\n"s is to create an empty line between the name of
143143
// SparkPlan and metrics. If removing it, it won't display the empty line in UI.
144-
builder ++= "\\n \\n"
145-
builder ++= values.mkString("\\n")
144+
builder ++= "\n \n"
145+
builder ++= values.mkString("\n")
146146
}
147147

148-
s""" $id [label="${builder.toString()}"];"""
148+
s""" $id [label="${StringEscapeUtils.escapeJava(builder.toString())}"];"""
149149
}
150150
}
151151

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

0 commit comments

Comments
 (0)