Skip to content

Commit b348901

Browse files
jose-torresgatorsmile
authored andcommitted
[SPARK-23808][SQL] Set default Spark session in test-only spark sessions.
## What changes were proposed in this pull request? Set default Spark session in the TestSparkSession and TestHiveSparkSession constructors. ## How was this patch tested? new unit tests Author: Jose Torres <[email protected]> Closes apache#20926 from jose-torres/test3.
1 parent a7755fd commit b348901

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ private[spark] class TestSparkSession(sc: SparkContext) extends SparkSession(sc)
3434
this(new SparkConf)
3535
}
3636

37+
SparkSession.setDefaultSession(this)
38+
3739
@transient
3840
override lazy val sessionState: SessionState = {
3941
new TestSQLSessionStateBuilder(this, None).build()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark.sql.test
19+
20+
import org.apache.spark.SparkFunSuite
21+
import org.apache.spark.sql.SparkSession
22+
23+
class TestSparkSessionSuite extends SparkFunSuite {
24+
test("default session is set in constructor") {
25+
val session = new TestSparkSession()
26+
assert(SparkSession.getDefaultSession.contains(session))
27+
session.stop()
28+
}
29+
}

sql/hive/src/main/scala/org/apache/spark/sql/hive/test/TestHive.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ private[hive] class TestHiveSparkSession(
159159
private val loadTestTables: Boolean)
160160
extends SparkSession(sc) with Logging { self =>
161161

162+
// TODO(SPARK-23826): TestHiveSparkSession should set default session the same way as
163+
// TestSparkSession, but doing this the same way breaks many tests in the package. We need
164+
// to investigate and find a different strategy.
165+
162166
def this(sc: SparkContext, loadTestTables: Boolean) {
163167
this(
164168
sc,

0 commit comments

Comments
 (0)