Github user holdenk commented on a diff in the pull request:
https://github.com/apache/spark/pull/22295#discussion_r219552522
--- Diff: python/pyspark/sql/tests.py ---
@@ -3654,6 +3654,107 @@ def test_jvm_default_session_already_set(self):
spark.stop()
+class SparkSessionTests2(ReusedSQLTestCase):
+
+ def test_active_session(self):
+ spark = SparkSession.builder \
+ .master("local") \
+ .getOrCreate()
+ try:
+ activeSession = spark.getActiveSession()
+ df = activeSession.createDataFrame([(1, 'Alice')], ['age',
'name'])
+ self.assertEqual(df.collect(), [Row(age=1, name=u'Alice')])
+ finally:
+ spark.stop()
+
+ def test_SparkSession(self):
+ spark = SparkSession.builder \
+ .master("local") \
+ .config("some-config", "v2") \
+ .getOrCreate()
+ try:
+ self.assertEqual(spark.conf.get("some-config"), "v2")
+ self.assertEqual(spark.sparkContext._conf.get("some-config"),
"v2")
+ self.assertEqual(spark.version, spark.sparkContext.version)
+ spark.sql("CREATE DATABASE test_db")
+ spark.catalog.setCurrentDatabase("test_db")
+ self.assertEqual(spark.catalog.currentDatabase(), "test_db")
+ spark.sql("CREATE TABLE table1 (name STRING, age INT) USING
parquet")
+ self.assertEqual(spark.table("table1").columns, ['name',
'age'])
+ self.assertEqual(spark.range(3).count(), 3)
+ finally:
+ spark.stop()
+
+ def test_global_default_session(self):
+ spark = SparkSession.builder \
+ .master("local") \
+ .getOrCreate()
+ try:
+ self.assertEqual(SparkSession.builder.getOrCreate(), spark)
+ finally:
+ spark.stop()
+
+ def test_default_and_active_session(self):
+ spark = SparkSession.builder \
+ .master("local") \
+ .getOrCreate()
+ activeSession = spark._jvm.SparkSession.getActiveSession()
+ defaultSession = spark._jvm.SparkSession.getDefaultSession()
+ try:
+ self.assertEqual(activeSession, defaultSession)
+ finally:
+ spark.stop()
+
+ def test_config_option_propagated_to_existing_SparkSession(self):
+ session1 = SparkSession.builder \
+ .master("local") \
+ .config("spark-config1", "a") \
+ .getOrCreate()
+ self.assertEqual(session1.conf.get("spark-config1"), "a")
+ session2 = SparkSession.builder \
+ .config("spark-config1", "b") \
+ .getOrCreate()
+ try:
+ self.assertEqual(session1, session2)
+ self.assertEqual(session1.conf.get("spark-config1"), "b")
+ finally:
+ session1.stop()
+
+ def test_newSession(self):
+ session = SparkSession.builder \
+ .master("local") \
+ .getOrCreate()
+ newSession = session.newSession()
+ try:
+ self.assertNotEqual(session, newSession)
+ finally:
+ session.stop()
+ newSession.stop()
+
+ def test_create_new_session_if_old_session_stopped(self):
+ session = SparkSession.builder \
+ .master("local") \
+ .getOrCreate()
+ session.stop()
+ newSession = SparkSession.builder \
+ .master("local") \
+ .getOrCreate()
+ try:
+ self.assertNotEqual(session, newSession)
+ finally:
+ newSession.stop()
+
+ def test_create_SparkContext_then_SparkSession(self):
--- End diff --
I don't strongly agree here. I think given that the method names are camel
case in the `SparkSession` & `SparkContext` in Python this naming is perfectly
reasonable.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]