Creating a SparkSession
We've already created a SparkSession for you called spark, but what if you're not sure there already is one? Creating multiple SparkSessions and SparkContexts can cause issues, so it's best practice to use the SparkSession.builder.getOrCreate() method. This returns an existing SparkSession if there's already one in the environment, or creates a new one if necessary!
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Foundations of PySpark
คำแนะนำการฝึกหัด
- Import
SparkSessionfrompyspark.sql. - Make a new
SparkSessioncalledmy_sparkusingSparkSession.builder.getOrCreate(). - Print
my_sparkto the console to verify it's aSparkSession.
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Import SparkSession from pyspark.sql
from ____ import ____
# Create my_spark
my_spark = ____
# Print my_spark
print(____)