viirya commented on a change in pull request #27610: 
[SPARK-30856][SQL][PySpark] Fix SQLContext.getOrCreate() when SparkContext is 
restarted
URL: https://github.com/apache/spark/pull/27610#discussion_r381008674
 
 

 ##########
 File path: python/pyspark/sql/tests/test_session.py
 ##########
 @@ -225,6 +225,24 @@ def test_get_active_session_after_create_dataframe(self):
                 session2.stop()
 
 
+class SparkSessionTests5(ReusedSQLTestCase):
+
+    def test_sqlcontext_with_stopped_sparkcontext(self):
+        # SPARK-30856: test that SQLContext.getOrCreate() returns a usable 
instance after
+        # the SparkContext is restarted.
+        self.spark.stop()
+        sc = SparkContext('local[4]', self.sc.appName)
+        spark = SparkSession(sc)  # Instantiate the underlying SQLContext
+        ctx_spark = SQLContext.getOrCreate(sc).sparkSession
+        self.assertIs(ctx_spark, spark)
+        try:
+            df = ctx_spark.createDataFrame([(1, 2)], ['c', 'c'])
+            df.collect()
+        finally:
+            spark.stop()
 
 Review comment:
   nit: We can assert if SQLContext._instantiatedContext is None now.

----------------------------------------------------------------
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