認識 SparkContext
SparkContext 是進入 Spark 功能的入口,就像車子的鑰匙一樣。當我們執行任何 Spark 應用程式時,會啟動一個 driver 程式,其中包含 main 函式,而你的 SparkContext 也會在這裡初始化。PySpark 會在 PySpark shell 中自動為你建立 SparkContext(所以你不必自己建立),並透過變數 sc 提供存取。
在這個簡單的練習中,你將在 PySpark shell 中找出 SparkContext 的各種屬性。接下來的課程你都會用到它們。
本練習屬於課程
使用 PySpark 的 Big Data 基礎
練習說明
- 在 PySpark shell 中印出 SparkContext 的版本。
- 在 PySpark shell 中印出 SparkContext 的 Python 版本。
- 在 PySpark shell 中的 SparkContext,master 是什麼?
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Print the version of SparkContext
print("The version of Spark Context in the PySpark shell is", sc.____)
# Print the Python version of SparkContext
print("The Python version of Spark Context in the PySpark shell is", ____.pythonVer)
# Print the master of SparkContext
print("The master of Spark Context in the PySpark shell is", ____.____)