maropu commented on a change in pull request #28173: [SPARK-31389][SQL][TESTS] 
Ensure all tests in SQLMetricsSuite run with both codegen on and off
URL: https://github.com/apache/spark/pull/28173#discussion_r408800570
 
 

 ##########
 File path: 
sql/core/src/test/scala/org/apache/spark/sql/execution/metric/SQLMetricsTestUtils.scala
 ##########
 @@ -214,14 +214,16 @@ trait SQLMetricsTestUtils extends SQLTestUtils {
   protected def testSparkPlanMetrics(
       df: DataFrame,
       expectedNumOfJobs: Int,
-      expectedMetrics: Map[Long, (String, Map[String, Any])]): Unit = {
+      expectedMetrics: Map[Long, (String, Map[String, Any])],
+      enableWholeStage: Boolean = false): Unit = {
     val expectedMetricsPredicates = expectedMetrics.mapValues { case 
(nodeName, nodeMetrics) =>
       (nodeName, nodeMetrics.mapValues(expectedMetricValue =>
         (actualMetricValue: Any) => {
           actualMetricValue.toString.matches(expectedMetricValue.toString)
         }))
     }
-    testSparkPlanMetricsWithPredicates(df, expectedNumOfJobs, 
expectedMetricsPredicates)
+    testSparkPlanMetricsWithPredicates(df, expectedNumOfJobs, 
expectedMetricsPredicates,
 
 Review comment:
   But, we should avoid duplicate code where possible.
   How about this?
   ```
     protected def testSparkPlanMetrics(
         df: _ => DataFrame,  // To make `df` fresh as you said.
         expectedNumOfJobs: Int,
         expectedMetrics: Map[Long, (String, Map[String, Any])],
         testWithWholeStage: Boolean = false): Unit = {
       val expectedMetricsPredicates = expectedMetrics.mapValues { case 
(nodeName, nodeMetrics) =>
         (nodeName, nodeMetrics.mapValues(expectedMetricValue =>
           (actualMetricValue: Any) => {
             actualMetricValue.toString.matches(expectedMetricValue.toString)
           }))
       }
       testSparkPlanMetricsWithPredicates(
         df(), expectedNumOfJobs, expectedMetricsPredicates, false)
   
       // If testWithWholeStage=true, run the second test with codegen enabled
       if (testWithWholeStage) {
         testSparkPlanMetricsWithPredicates(
           df(), expectedNumOfJobs, expectedMetricsPredicates, true)
       }
     }
   ```

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to