File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed
Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change 3535if os .environ .get ("SPARK_EXECUTOR_URI" ):
3636 SparkContext .setSystemProperty ("spark.executor.uri" , os .environ ["SPARK_EXECUTOR_URI" ])
3737
38- sc = SparkContext ()
39- atexit .register (lambda : sc .stop ())
38+ SparkContext ._ensure_initialized ()
4039
4140try :
4241 # Try to access HiveConf, it will raise exception if Hive is not added
43- sc ._jvm .org .apache .hadoop .hive .conf .HiveConf ()
42+ SparkContext ._jvm .org .apache .hadoop .hive .conf .HiveConf ()
4443 spark = SparkSession .builder \
4544 .enableHiveSupport ()\
4645 .getOrCreate ()
4948except TypeError :
5049 spark = SparkSession (sc )
5150
51+ sc = spark .sparkContext
52+ atexit .register (lambda : sc .stop ())
53+
5254# for compatibility
5355sqlContext = spark ._wrapped
5456sqlCtx = sqlContext
Original file line number Diff line number Diff line change @@ -191,6 +191,12 @@ def newSession(self):
191191 """
192192 return self .__class__ (self ._sc , self ._jsparkSession .newSession ())
193193
194+ @property
195+ @since (2.0 )
196+ def sparkContext (self ):
197+ """Returns the underlying :class:`SparkContext`."""
198+ return self ._sc
199+
194200 @property
195201 @since (2.0 )
196202 def conf (self ):
You can’t perform that action at this time.
0 commit comments