class_docstr: Lazy loading, memoizing, instantiation of SparkSessions.
  
  Useful when you want to defer SparkSession instantiation and provide access to the same
  instance throughout the application.
class_docstr_tok: ["Lazy","loading",",","memoizing",",","instantiation","of","SparkSessions",".","Useful","when","you","want","to","defer","SparkSession","instantiation","and","provide","access","to","the","same","instance","throughout","the","application","."]
docstr: Instantiate a new SparkSession or return the existing one.
docstr_tok: ["Instantiate","a","new","SparkSession","or","return","the","existing","one","."]
code: def spark_session(self) -> SparkSession:
      """Instantiate a new SparkSession or return the existing one."""
      is_training_job = self.environment_helper.is_training_job()
      instance_count = self.environment_helper.get_instance_count()
  
      spark_configs = self._get_spark_configs(is_training_job)
      spark_conf = (
          SparkConf().setAll(spark_configs).setAppName(SPARK_APP_NAME)
      )
  
      if instance_count == 1:
          spark_conf.setMaster("local[*]")
  
      sc = SparkContext.getOrCreate(conf=spark_conf)
  
      jsc = sc._jsc  # Java Spark Context (JVM SparkContext)
      for cfg in self._get_jsc_hadoop_configs():
          jsc.hadoopConfiguration().set(cfg[0], cfg[1])
  
      return SparkSession(sparkContext=sc)
  
file_path: sagemaker-python-sdk/src/sagemaker/feature_store/feature_processor/_spark_factory.py
imports: from __future__ import absolute_import
  from functools import lru_cache
  from typing import List, Tuple, Dict
  import feature_store_pyspark
  import feature_store_pyspark.FeatureStoreManager
  from pyspark.conf import SparkConf
  from pyspark.context import SparkContext
  from pyspark.sql import SparkSession
  from sagemaker.feature_store.feature_processor._env import EnvironmentHelper
label_desc: Use image node_id 2 for calling the SparkSessionFactory obj's underlying member method code with example usage: obj.spark_session() and returns: SparkSession