理解 SparkContext
SparkContext 是访问 Spark 功能的入口,就像您汽车的钥匙。当我们运行任何 Spark 应用时,会启动一个 driver 程序,它包含主函数,您的 SparkContext 也在这里初始化。PySpark 会在 PySpark shell 中自动为您创建一个 SparkContext(因此您无需手动创建),并通过变量 sc 提供访问。
在这个小练习中,您将查看 PySpark shell 中 SparkContext 的各个属性。接下来整个课程都会用到它们。
本练习是课程的一部分
使用 PySpark 的大数据基础
练习说明
- 在 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", ____.____)