title: Can we use spark session object without explicitly creating it, if Submit a job by spark-submit
body: <p>My question is very basic, My code is working fine. But I am not clear with these two points:</p>
  
  <h3>1) when we submit any pyspark job using spark-submit do we need to create spark session object like this ?  in my script:</h3>
  
  <pre><code>from pyspark.sql import SparkSession,SQLContext
  from pyspark.conf import SparkConf
  spark = SparkSession \
      .builder \
      .enableHiveSupport() \
      .appName("test") \
      .getOrCreate()
  print(spark)
  sqlContext = SQLContext(spark)
  </code></pre>
  
  <p>or i can directly access spark session object in my script with out creating it.</p>
  
  <pre><code>from pyspark.sql import SparkSession,SQLContext
  from pyspark.conf import SparkConf
  print(spark) -- this can be ***sc*** not sure I am using spark-2
  sqlContext = SQLContext(spark)
  </code></pre>
  
  <p>and if spark session object is available then how i can add config properties such as below or how to enable hive support. </p>
  
  <pre><code>spark = SparkSession \
  .builder \
  .enableHiveSupport() \
  .config(conf=SparkConf().set("spark.driver.maxResultSize", "2g")) \
  .appName("test") \
  .getOrCreate() 
  </code></pre>
  
  <h3>2) Another approach is without using spark-submit I can write my python code to generate spark-session object and use it like <a href="https://stackoverflow.com/questions/41926219/error-message-when-launching-pyspark-from-jupyter-notebook-on-windows">this</a></h3>
  
  <p>My doubt is if i submit job using spark-submit and creating spark session object as mentioned above am i ending up creating two spark session ?</p>
  
  <p>It would be very helpful if someone can explain me added advantage of using spark-submit over step 2 method. And do i need to create spark-session object if i invoke job using spark-submit from command line</p>