Start a session, give your data a real schema, survive broken records and write Parquet without wiping the table.
SparkSession is the entry point to the DataFrame and SQL APIs: readers, spark.sql(), the catalog and runtime configuration all hang off it. builder collects settings and getOrCreate() returns the active session if there is one, or starts a new application.
In notebooks, the pyspark shell and Glue jobs a session already exists, so getOrCreate() hands you that one. SQL options such as spark.sql.shuffle.partitions can be changed later with spark.conf.set; resource settings like executor memory and cores must be set before the application starts.
from pyspark.sql import SparkSession
spark = (SparkSession.builder
.appName("orders-ingest")
.config("spark.sql.shuffle.partitions", "64")
.config("spark.sql.session.timeZone", "UTC")
.getOrCreate())
# SQL settings can change at runtime...
spark.conf.set("spark.sql.shuffle.partitions", "200")
# ...executor sizing is fixed once the application has started
print(spark.version)Reach the last step for the run summary: the key takeaways from this lesson.