You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "andygrove (via GitHub)" <gi...@apache.org> on 2025/09/30 17:08:10 UTC

[PR] chore: Improve test assertions in plan stability suite [datafusion-comet]

andygrove opened a new pull request, #2505:
URL: https://github.com/apache/datafusion-comet/pull/2505

   ## Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   N/A
   
   ## Rationale for this change
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   In the plan stability suite, there is a check that the expected and actual simplified and explain plans match, but only the simplified plan gets logged. This means that when the actual vs expected explain plan is different, no information is logged to show the difference. I discovered this while working on https://github.com/apache/datafusion-comet/pull/2492
   
   ## What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   ## How are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] chore: Improve test assertions in plan stability suite [datafusion-comet]

Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #2505:
URL: https://github.com/apache/datafusion-comet/pull/2505#discussion_r2396171328


##########
spark/src/test/scala/org/apache/spark/sql/comet/CometPlanStabilitySuite.scala:
##########
@@ -274,13 +259,16 @@ trait CometPlanStabilitySuite extends DisableAdaptiveExecutionSuite with TPCDSBa
       val qe = sql(queryString).queryExecution
       val plan = qe.executedPlan
       val explain = normalizeLocation(normalizeIds(qe.explainString(FormattedMode)))
-
+      val simplified = getSimplifiedPlan(plan)
       assert(ValidateRequirements.validate(plan))
 
+      val name = query + suffix
+      val dir = getDirForTest(name)
+
       if (regenerateGoldenFiles) {
-        generateGoldenFile(plan, query + suffix, explain)
+        generateGoldenFile(dir, simplified, explain)

Review Comment:
   the name (query + suffix) was previously used in `generateGoldenFile` to create the `dir` but now we just pass that in, since it has already been computed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] chore: Improve test assertions in plan stability suite [datafusion-comet]

Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #2505:
URL: https://github.com/apache/datafusion-comet/pull/2505#discussion_r2395655089


##########
spark/src/test/scala/org/apache/spark/sql/comet/CometPlanStabilitySuite.scala:
##########
@@ -274,13 +259,16 @@ trait CometPlanStabilitySuite extends DisableAdaptiveExecutionSuite with TPCDSBa
       val qe = sql(queryString).queryExecution
       val plan = qe.executedPlan
       val explain = normalizeLocation(normalizeIds(qe.explainString(FormattedMode)))
-
+      val simplified = getSimplifiedPlan(plan)
       assert(ValidateRequirements.validate(plan))
 
+      val name = query + suffix
+      val dir = getDirForTest(name)
+
       if (regenerateGoldenFiles) {
-        generateGoldenFile(plan, query + suffix, explain)
+        generateGoldenFile(dir, simplified, explain)

Review Comment:
   `generateGoldenFile` doesn't refer to `name`? prev implementaton referred to `query + suffix`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] chore: Improve test assertions in plan stability suite [datafusion-comet]

Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #2505:
URL: https://github.com/apache/datafusion-comet/pull/2505#discussion_r2393330944


##########
spark/src/test/scala/org/apache/spark/sql/comet/CometPlanStabilitySuite.scala:
##########
@@ -131,38 +133,54 @@ trait CometPlanStabilitySuite extends DisableAdaptiveExecutionSuite with TPCDSBa
     }
   }
 
-  private def checkWithApproved(plan: SparkPlan, name: String, explain: String): Unit = {
+  private def checkWithApproved(plan: SparkPlan, name: String, actualExplain: String): Unit = {
     val dir = getDirForTest(name)
     val tempDir = FileUtils.getTempDirectory
     val actualSimplified = getSimplifiedPlan(plan)
-    val foundMatch = isApproved(dir, actualSimplified, explain)
+    val foundMatch = isApproved(dir, actualSimplified, actualExplain)
 
     if (!foundMatch) {
-      // show diff with last approved
+      // read approved files
       val approvedSimplifiedFile = new File(dir, "simplified.txt")
       val approvedExplainFile = new File(dir, "explain.txt")
+      val approvedSimplified =
+        FileUtils.readFileToString(approvedSimplifiedFile, StandardCharsets.UTF_8)
+      val approvedExplain =
+        FileUtils.readFileToString(approvedExplainFile, StandardCharsets.UTF_8)
 
+      // write actual files out for debugging
       val actualSimplifiedFile = new File(tempDir, s"$name.actual.simplified.txt")
       val actualExplainFile = new File(tempDir, s"$name.actual.explain.txt")
-
-      val approvedSimplified =
-        FileUtils.readFileToString(approvedSimplifiedFile, StandardCharsets.UTF_8)
-      // write out for debugging
       FileUtils.writeStringToFile(actualSimplifiedFile, actualSimplified, StandardCharsets.UTF_8)
-      FileUtils.writeStringToFile(actualExplainFile, explain, StandardCharsets.UTF_8)
-
-      fail(s"""
-           |Plans did not match:
-           |last approved simplified plan: ${approvedSimplifiedFile.getAbsolutePath}
-           |last approved explain plan: ${approvedExplainFile.getAbsolutePath}
-           |
-           |$approvedSimplified
-           |
-           |actual simplified plan: ${actualSimplifiedFile.getAbsolutePath}
-           |actual explain plan: ${actualExplainFile.getAbsolutePath}
-           |
-           |$actualSimplified
-        """.stripMargin)
+      FileUtils.writeStringToFile(actualExplainFile, actualExplain, StandardCharsets.UTF_8)
+
+      comparePlans(
+        "simplified",
+        approvedSimplified,
+        actualSimplified,
+        approvedSimplifiedFile,
+        actualSimplifiedFile)
+
+      comparePlans(
+        "explain",
+        approvedExplain,
+        actualExplain,
+        approvedExplainFile,
+        actualExplainFile)
+    }
+  }
+
+  private def comparePlans(
+      planType: String,
+      expected: String,
+      actual: String,
+      expectedFile: File,
+      actualFile: File): Unit = {
+    if (expected != actual) {
+      val message =
+        s"Expected $planType plan in ${expectedFile.getAbsolutePath} did not match " +
+          s"actual $planType plan in ${actualFile.getAbsolutePath}"
+      throw new ComparisonFailure(message, expected, actual)

Review Comment:
   Thanks. I reverted to the previous approach of calling `fail` with the formatted plans
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] chore: Improve test assertions in plan stability suite [datafusion-comet]

Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove merged PR #2505:
URL: https://github.com/apache/datafusion-comet/pull/2505


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] chore: Improve test assertions in plan stability suite [datafusion-comet]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #2505:
URL: https://github.com/apache/datafusion-comet/pull/2505#issuecomment-3353140165

   ## [Codecov](https://app.codecov.io/gh/apache/datafusion-comet/pull/2505?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :white_check_mark: All modified and coverable lines are covered by tests.
   :white_check_mark: Project coverage is 10.48%. Comparing base ([`f09f8af`](https://app.codecov.io/gh/apache/datafusion-comet/commit/f09f8af64c6599255e116a376f4f008f2fd63b43?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`efa1680`](https://app.codecov.io/gh/apache/datafusion-comet/commit/efa1680d589a92143d50ef105431e825c70ada02?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 561 commits behind head on main.
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@              Coverage Diff              @@
   ##               main    #2505       +/-   ##
   =============================================
   - Coverage     56.12%   10.48%   -45.64%     
   + Complexity      976      232      -744     
   =============================================
     Files           119      146       +27     
     Lines         11743    13500     +1757     
     Branches       2251     2333       +82     
   =============================================
   - Hits           6591     1416     -5175     
   - Misses         4012    11907     +7895     
   + Partials       1140      177      -963     
   ```
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/datafusion-comet/pull/2505?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] chore: Improve test assertions in plan stability suite [datafusion-comet]

Posted by "parthchandra (via GitHub)" <gi...@apache.org>.
parthchandra commented on code in PR #2505:
URL: https://github.com/apache/datafusion-comet/pull/2505#discussion_r2393020129


##########
spark/src/test/scala/org/apache/spark/sql/comet/CometPlanStabilitySuite.scala:
##########
@@ -131,38 +133,54 @@ trait CometPlanStabilitySuite extends DisableAdaptiveExecutionSuite with TPCDSBa
     }
   }
 
-  private def checkWithApproved(plan: SparkPlan, name: String, explain: String): Unit = {
+  private def checkWithApproved(plan: SparkPlan, name: String, actualExplain: String): Unit = {
     val dir = getDirForTest(name)
     val tempDir = FileUtils.getTempDirectory
     val actualSimplified = getSimplifiedPlan(plan)
-    val foundMatch = isApproved(dir, actualSimplified, explain)
+    val foundMatch = isApproved(dir, actualSimplified, actualExplain)
 
     if (!foundMatch) {
-      // show diff with last approved
+      // read approved files
       val approvedSimplifiedFile = new File(dir, "simplified.txt")
       val approvedExplainFile = new File(dir, "explain.txt")
+      val approvedSimplified =
+        FileUtils.readFileToString(approvedSimplifiedFile, StandardCharsets.UTF_8)
+      val approvedExplain =
+        FileUtils.readFileToString(approvedExplainFile, StandardCharsets.UTF_8)
 
+      // write actual files out for debugging
       val actualSimplifiedFile = new File(tempDir, s"$name.actual.simplified.txt")
       val actualExplainFile = new File(tempDir, s"$name.actual.explain.txt")
-
-      val approvedSimplified =
-        FileUtils.readFileToString(approvedSimplifiedFile, StandardCharsets.UTF_8)
-      // write out for debugging
       FileUtils.writeStringToFile(actualSimplifiedFile, actualSimplified, StandardCharsets.UTF_8)
-      FileUtils.writeStringToFile(actualExplainFile, explain, StandardCharsets.UTF_8)
-
-      fail(s"""
-           |Plans did not match:
-           |last approved simplified plan: ${approvedSimplifiedFile.getAbsolutePath}
-           |last approved explain plan: ${approvedExplainFile.getAbsolutePath}
-           |
-           |$approvedSimplified
-           |
-           |actual simplified plan: ${actualSimplifiedFile.getAbsolutePath}
-           |actual explain plan: ${actualExplainFile.getAbsolutePath}
-           |
-           |$actualSimplified
-        """.stripMargin)
+      FileUtils.writeStringToFile(actualExplainFile, actualExplain, StandardCharsets.UTF_8)
+
+      comparePlans(
+        "simplified",
+        approvedSimplified,
+        actualSimplified,
+        approvedSimplifiedFile,
+        actualSimplifiedFile)
+
+      comparePlans(
+        "explain",
+        approvedExplain,
+        actualExplain,
+        approvedExplainFile,
+        actualExplainFile)
+    }
+  }
+
+  private def comparePlans(
+      planType: String,
+      expected: String,
+      actual: String,
+      expectedFile: File,
+      actualFile: File): Unit = {
+    if (expected != actual) {
+      val message =
+        s"Expected $planType plan in ${expectedFile.getAbsolutePath} did not match " +
+          s"actual $planType plan in ${actualFile.getAbsolutePath}"
+      throw new ComparisonFailure(message, expected, actual)

Review Comment:
   One problem with `ComparisonFailure` may be that it logs everything in a single string. Perhaps if the `expected` and `actual` had some newlines at the beginning and at the end, then the output might be slightly easier to read? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org