InterviewSolution
Saved Bookmarks
| 1. |
How to create SparkSession? |
|
Answer» To create SparkSession, we use the builder pattern. The SparkSession class from the pyspark.sql library has the getOrCreate() method which creates a new SparkSession if there is none or else it returns the existing SparkSession object. The following code is an example for creating SparkSession: import pysparkfrom pyspark.sql import SparkSessionspark = SparkSession.builder.master("local[1]") .appName('InterviewBitSparkSession') .getOrCreate()Here,
If we want to create a new SparkSession object every TIME, we can use the newSession method as SHOWN below: import pysparkfrom pyspark.sql import SparkSessionspark_session = SparkSession.newSession |
|