Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add physical plan to the dot file as the graph label #2640

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import org.apache.spark.sql.rapids.tool.profiling._
/**
* Class for writing local files, allows writing to distributed file systems.
*/
class ToolTextFileWriter(finalOutputDir: String, logFileName: String) extends Logging {

case class ToolTextFileWriter(finalOutputDir: String, logFileName: String) extends Logging {
gerashegalov marked this conversation as resolved.
Show resolved Hide resolved
private val textOutputPath = new Path(s"$finalOutputDir/$logFileName")
private val fs = FileSystem.get(textOutputPath.toUri, new Configuration())
// this overwrites existing path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,16 @@ class CollectInformation(apps: ArrayBuffer[ApplicationInfo],
list += row.getLong(1) -> row.getLong(2)
}

for ((sqlID, planInfo) <- app.sqlPlan) {
val sqlPlansMap = app.sqlPlan.map { case (sqlId, sparkPlanInfo) =>
sqlId -> ((sparkPlanInfo, app.physicalPlanDescription(sqlId)))
}
for ((sqlID, (planInfo, physicalPlan)) <- sqlPlansMap) {
val dotFileWriter = new ToolTextFileWriter(outputDirectory,
s"${app.appId}-query-$sqlID.dot")
try {
val metrics = map.getOrElse(sqlID, Seq.empty).toMap
GenerateDot.generateDotGraph(
QueryPlanWithMetrics(planInfo, metrics), None, dotFileWriter, sqlID + ".dot")
GenerateDot.generateDotGraph(QueryPlanWithMetrics(planInfo, metrics),
physicalPlan, None, dotFileWriter, sqlID + ".dot")
} finally {
dotFileWriter.close()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ object GenerateDot {
*/
def generateDotGraph(
plan: QueryPlanWithMetrics,
physicalPlanString: String,
comparisonPlan: Option[QueryPlanWithMetrics],
fileWriter: ToolTextFileWriter,
filename: String): Unit = {
Expand Down Expand Up @@ -166,8 +167,17 @@ object GenerateDot {
}
}

val leftAlignedPlanStr = physicalPlanString.replace("\n", "\\l")
// write the dot graph to a file
fileWriter.write("digraph G {\n")
fileWriter.write(
s"""digraph G {
|
|label="\\l\\l${fileWriter.logFileName}\\l\\l${leftAlignedPlanStr}"
|labelloc=b
|fontname=Courier
|
|""".stripMargin)

writeGraph(fileWriter, plan, comparisonPlan.getOrElse(plan), 0)
fileWriter.write("}\n")
}
Expand Down