Skip to content

Commit 0b427b4

Browse files
author
Matthis Gördel
committed
Minimize sql.SparkSessionBinder stuff
1 parent 749120e commit 0b427b4

3 files changed

Lines changed: 40 additions & 39 deletions

File tree

sql/core/src/test/scala/org/apache/spark/sql/SparkSessionBinder.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ package org.apache.spark.sql
1919

2020
import scala.concurrent.duration._
2121

22-
import org.scalatest.{BeforeAndAfterEach, Suite}
22+
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach, Suite}
2323
import org.scalatest.concurrent.Eventually
2424

25-
import org.apache.spark.{DebugFilesystem, SparkConf}
25+
import org.apache.spark.{DebugFilesystem, SparkConf, SparkFunSuite}
2626
import org.apache.spark.internal.config.UNSAFE_EXCEPTION_ON_MEMORY_LEAK
2727
import org.apache.spark.sql.catalyst.expressions.CodegenObjectFactoryMode
2828
import org.apache.spark.sql.catalyst.optimizer.ConvertToLocalRelation
2929
import org.apache.spark.sql.internal.{SQLConf, StaticSQLConf}
3030
import org.apache.spark.sql.test.TestSparkSession
3131

32-
trait SparkSessionBinder extends QueryTest with SparkSessionBinderBase {
32+
trait SparkSessionBinder extends SparkSessionBinderBase { self: SparkFunSuite =>
3333

3434
/**
3535
* Suites extending this trait are sharing resources (e.g. SparkSession) in their
@@ -56,9 +56,9 @@ trait SparkSessionBinder extends QueryTest with SparkSessionBinderBase {
5656
}
5757

5858
trait SparkSessionBinderBase
59-
extends QueryTestBase
60-
with SparkSessionProvider
59+
extends SparkSessionProvider
6160
with BeforeAndAfterEach
61+
with BeforeAndAfterAll
6262
with Eventually { self: Suite =>
6363

6464
protected def sparkConf = {

sql/core/src/test/scala/org/apache/spark/sql/classic/SparkSessionBinder.scala

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,11 @@
1717

1818
package org.apache.spark.sql.classic
1919

20-
import scala.concurrent.duration._
21-
22-
import org.apache.spark.sql
20+
import org.apache.spark.{sql, SparkFunSuite}
2321

2422
/**
2523
* Overrides [[spark]] to provide a [[SparkSession classic.SparkSession]]
2624
*/
27-
trait SparkSessionBinder extends sql.SparkSessionBinder with QueryTest {
25+
trait SparkSessionBinder extends sql.SparkSessionBinder { self: SparkFunSuite =>
2826
override protected def spark: SparkSession = super.spark.asInstanceOf[SparkSession]
29-
30-
// Runs func (which must trigger exactly one SQL execution) and returns the SQL metrics of that
31-
// execution as a map keyed by (planNodeId, planNodeName, metricName) -> metricValue.
32-
def runAndFetchMetrics(func: => Unit): Map[(Long, String, String), String] = {
33-
val statusStore = spark.sharedState.statusStore
34-
val oldCount = statusStore.executionsList().size
35-
36-
func
37-
38-
// Wait until the new execution is started and being tracked.
39-
eventually(timeout(10.seconds), interval(10.milliseconds)) {
40-
assert(statusStore.executionsCount() >= oldCount)
41-
}
42-
43-
// Wait for listener to finish computing the metrics for the execution.
44-
eventually(timeout(10.seconds), interval(10.milliseconds)) {
45-
assert(statusStore.executionsList().nonEmpty &&
46-
statusStore.executionsList().last.metricValues != null)
47-
}
48-
49-
val exec = statusStore.executionsList().last
50-
val execId = exec.executionId
51-
val sqlMetrics = statusStore.planGraph(execId).allNodes
52-
.flatMap(n => n.metrics.map(m => (m.accumulatorId, (n.id, n.name, m.name))))
53-
.toMap
54-
statusStore.executionMetrics(execId).map { case (k, v) => sqlMetrics(k) -> v }
55-
}
5627
}

sql/core/src/test/scala/org/apache/spark/sql/test/SharedSparkSession.scala

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,50 @@
1717

1818
package org.apache.spark.sql.test
1919

20+
import scala.concurrent.duration._
21+
2022
import org.scalatest.Suite
2123

22-
import org.apache.spark.sql
24+
import org.apache.spark.sql.{QueryTestBase, QueryTest, SparkSessionBinderBase}
2325
import org.apache.spark.sql.classic
2426

2527
@deprecated("Use SparkSessionBinder (or classic.SparkSessionBinder if required) instead", "4.2.0")
26-
trait SharedSparkSession extends classic.SparkSessionBinder
28+
trait SharedSparkSession extends QueryTest with classic.SparkSessionBinder {
29+
30+
// Runs func (which must trigger exactly one SQL execution) and returns the SQL metrics of that
31+
// execution as a map keyed by (planNodeId, planNodeName, metricName) -> metricValue.
32+
def runAndFetchMetrics(func: => Unit): Map[(Long, String, String), String] = {
33+
val statusStore = spark.sharedState.statusStore
34+
val oldCount = statusStore.executionsList().size
35+
36+
func
37+
38+
// Wait until the new execution is started and being tracked.
39+
eventually(timeout(10.seconds), interval(10.milliseconds)) {
40+
assert(statusStore.executionsCount() >= oldCount)
41+
}
42+
43+
// Wait for listener to finish computing the metrics for the execution.
44+
eventually(timeout(10.seconds), interval(10.milliseconds)) {
45+
assert(statusStore.executionsList().nonEmpty &&
46+
statusStore.executionsList().last.metricValues != null)
47+
}
48+
49+
val exec = statusStore.executionsList().last
50+
val execId = exec.executionId
51+
val sqlMetrics = statusStore.planGraph(execId).allNodes
52+
.flatMap(n => n.metrics.map(m => (m.accumulatorId, (n.id, n.name, m.name))))
53+
.toMap
54+
statusStore.executionMetrics(execId).map { case (k, v) => sqlMetrics(k) -> v }
55+
}
56+
}
2757

2858

2959
/**
3060
* Helper trait for SQL test suites where all tests share a single [[TestSparkSession]].
3161
*/
3262
@deprecated("Use SparkSessionBinder (or classic.SparkSessionBinder if required) instead", "4.2.0")
33-
trait SharedSparkSessionBase extends sql.SparkSessionBinderBase { self: Suite =>
63+
trait SharedSparkSessionBase extends QueryTestBase with SparkSessionBinderBase { self: Suite =>
3464

3565
protected override def spark: classic.SparkSession =
3666
super.spark.asInstanceOf[classic.SparkSession]

0 commit comments

Comments
 (0)