Skip to content

Commit 69af842

Browse files
committed
Add testImplicits to SharedSparkSessionBase and TestHiveSingleton
After removing testImplicits from QueryTestBase, it needs to be defined in the session-providing traits instead. Co-authored-by: Isaac
1 parent 4f65ce5 commit 69af842

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import org.apache.spark.internal.config.UNSAFE_EXCEPTION_ON_MEMORY_LEAK
2727
import org.apache.spark.sql.{classic, SparkSession, SparkSessionProvider, SQLContext}
2828
import org.apache.spark.sql.catalyst.expressions.CodegenObjectFactoryMode
2929
import org.apache.spark.sql.catalyst.optimizer.ConvertToLocalRelation
30+
import org.apache.spark.sql.classic.{ClassicConversions, ColumnConversions, ColumnNodeToExpressionConverter, SQLImplicits}
3031
import org.apache.spark.sql.internal.{SQLConf, StaticSQLConf}
3132

3233
trait SharedSparkSession extends SQLTestUtils with SharedSparkSessionBase {
@@ -87,6 +88,23 @@ trait SharedSparkSessionBase
8788
with BeforeAndAfterEach
8889
with Eventually { self: Suite =>
8990

91+
/**
92+
* A helper object for importing SQL implicits.
93+
*
94+
* Note that the alternative of importing `spark.implicits._` is not possible here.
95+
* This is because we create the `SparkSession` immediately before the first test is run,
96+
* but the implicits import is needed in the constructor.
97+
*/
98+
protected object testImplicits
99+
extends SQLImplicits
100+
with ClassicConversions
101+
with ColumnConversions {
102+
private def classicSession: classic.SparkSession =
103+
self.spark.asInstanceOf[classic.SparkSession]
104+
override protected def session: classic.SparkSession = classicSession
105+
override protected def converter: ColumnNodeToExpressionConverter = classicSession.converter
106+
}
107+
90108
protected def sparkConf = {
91109
val conf = new SparkConf()
92110
.set("spark.hadoop.fs.file.impl", classOf[DebugFilesystem].getName)

sql/hive/src/test/scala/org/apache/spark/sql/hive/test/TestHiveSingleton.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,23 @@ package org.apache.spark.sql.hive.test
1919

2020
import org.apache.spark.SparkFunSuite
2121
import org.apache.spark.sql.SparkSessionProvider
22-
import org.apache.spark.sql.classic.SparkSession
22+
import org.apache.spark.sql.classic
23+
import org.apache.spark.sql.classic.{ClassicConversions, ColumnConversions, ColumnNodeToExpressionConverter, SQLImplicits, SparkSession}
2324
import org.apache.spark.sql.hive.HiveExternalCatalog
2425
import org.apache.spark.sql.hive.client.HiveClient
2526

2627

2728
trait TestHiveSingleton extends SparkFunSuite with SparkSessionProvider {
2829
override protected val enableAutoThreadAudit = false
2930
override protected val spark: SparkSession = TestHive.sparkSession
31+
32+
protected object testImplicits
33+
extends SQLImplicits
34+
with ClassicConversions
35+
with ColumnConversions {
36+
override protected def session: SparkSession = TestHiveSingleton.this.spark
37+
override protected def converter: ColumnNodeToExpressionConverter = session.converter
38+
}
3039
protected val hiveContext: TestHiveContext = TestHive
3140
protected val hiveClient: HiveClient =
3241
spark.sharedState.externalCatalog.unwrapped.asInstanceOf[HiveExternalCatalog].client

0 commit comments

Comments
 (0)