There is no need to use both SparkContext and SparkSession to initialize Spark. SparkSession is a new, recommended use.
To initialize your environment, simply do:
spark = SparkSession\ .builder\ .appName("test_import")\ .getOrCreate()
You can run SQL commands by doing the following:
spark.sql(...)
Prior to Spark 2.0.0, three separate objects were used: SparkContext , SQLContext and HiveContext . They were used separately depending on what you wanted to do and the data types used.
With the introduction of the Dataset / DataFrame abstractions, the SparkSession object SparkSession become the main entry point into the Spark environment. You can still access other objects by first initializing SparkSession (say, in a variable called spark ), and then make spark.sparkContext / spark.sqlContext .
source share