-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-32466][SQL][FOLLOW-UP] Normalize Location info in explain plan #29537
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,6 +94,8 @@ trait PlanStabilitySuite extends TPCDSBase with DisableAdaptiveExecutionSuite { | |
| private val referenceRegex = "#\\d+".r | ||
| private val normalizeRegex = "#\\d+L?".r | ||
|
|
||
| private val clsName = this.getClass.getCanonicalName | ||
|
|
||
| def goldenFilePath: String | ||
|
|
||
| private def getDirForTest(name: String): File = { | ||
|
|
@@ -102,8 +104,8 @@ trait PlanStabilitySuite extends TPCDSBase with DisableAdaptiveExecutionSuite { | |
|
|
||
| private def isApproved(dir: File, actualSimplifiedPlan: String): Boolean = { | ||
| val file = new File(dir, "simplified.txt") | ||
| val approved = FileUtils.readFileToString(file, StandardCharsets.UTF_8) | ||
| approved == actualSimplifiedPlan | ||
| val expected = FileUtils.readFileToString(file, StandardCharsets.UTF_8) | ||
| expected == actualSimplifiedPlan | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Address the comment from #29270 (comment) |
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -115,7 +117,7 @@ trait PlanStabilitySuite extends TPCDSBase with DisableAdaptiveExecutionSuite { | |
| * @param explain the full explain output; this is saved to help debug later as the simplified | ||
| * plan is not too useful for debugging | ||
| */ | ||
| private def generateApprovedPlanFile(plan: SparkPlan, name: String, explain: String): Unit = { | ||
| private def generateGoldenFile(plan: SparkPlan, name: String, explain: String): Unit = { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Address the comment from #29270 (comment) |
||
| val dir = getDirForTest(name) | ||
| val simplified = getSimplifiedPlan(plan) | ||
| val foundMatch = dir.exists() && isApproved(dir, simplified) | ||
|
|
@@ -207,7 +209,7 @@ trait PlanStabilitySuite extends TPCDSBase with DisableAdaptiveExecutionSuite { | |
| * WholeStageCodegen | ||
| * Project [c_customer_id] | ||
| */ | ||
| def getSimplifiedPlan(node: SparkPlan, depth: Int): String = { | ||
| def simplifyNode(node: SparkPlan, depth: Int): String = { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Address the comment from #29270 (comment) |
||
| val padding = " " * depth | ||
| var thisNode = node.nodeName | ||
| if (node.references.nonEmpty) { | ||
|
|
@@ -220,19 +222,24 @@ trait PlanStabilitySuite extends TPCDSBase with DisableAdaptiveExecutionSuite { | |
| if (id > 0) { | ||
| thisNode += s" #$id" | ||
| } | ||
| val childrenSimplified = node.children.map(getSimplifiedPlan(_, depth + 1)) | ||
| val subqueriesSimplified = node.subqueries.map(getSimplifiedPlan(_, depth + 1)) | ||
| val childrenSimplified = node.children.map(simplifyNode(_, depth + 1)) | ||
| val subqueriesSimplified = node.subqueries.map(simplifyNode(_, depth + 1)) | ||
| s"$padding$thisNode\n${subqueriesSimplified.mkString("")}${childrenSimplified.mkString("")}" | ||
| } | ||
|
|
||
| getSimplifiedPlan(plan, 0) | ||
| simplifyNode(plan, 0) | ||
| } | ||
|
|
||
| private def normalizeIds(query: String): String = { | ||
| private def normalizeIds(plan: String): String = { | ||
| val map = new mutable.HashMap[String, String]() | ||
| normalizeRegex.findAllMatchIn(query).map(_.toString) | ||
| normalizeRegex.findAllMatchIn(plan).map(_.toString) | ||
| .foreach(map.getOrElseUpdate(_, (map.size + 1).toString)) | ||
| normalizeRegex.replaceAllIn(query, regexMatch => s"#${map(regexMatch.toString)}") | ||
| normalizeRegex.replaceAllIn(plan, regexMatch => s"#${map(regexMatch.toString)}") | ||
| } | ||
|
|
||
| private def normalizeLocation(plan: String): String = { | ||
| plan.replaceAll(s"Location.*$clsName/", | ||
| "Location [not included in comparison]/{warehouse_dir}/") | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -244,10 +251,10 @@ trait PlanStabilitySuite extends TPCDSBase with DisableAdaptiveExecutionSuite { | |
| classLoader = Thread.currentThread().getContextClassLoader) | ||
| val qe = sql(queryString).queryExecution | ||
| val plan = qe.executedPlan | ||
| val explain = normalizeIds(qe.explainString(FormattedMode)) | ||
| val explain = normalizeLocation(normalizeIds(qe.explainString(FormattedMode))) | ||
|
|
||
| if (regenerateGoldenFiles) { | ||
| generateApprovedPlanFile(plan, query + suffix, explain) | ||
| generateGoldenFile(plan, query + suffix, explain) | ||
| } else { | ||
| checkWithApproved(plan, query + suffix, explain) | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.