PySpark Programming for Big Data¶
Spark supports multiple programming languages including Java, Scala, Python, and R. In this course, we will use Python as the programming language to work with Spark. The PySpark components are built on top of Spark Core and provide Python APIs to interact with Spark.
We will only briefly introduce how to program in PySpark to manipulate datasets and achieve certain big data processing tasks.
Why PySpark¶
Other languages
Scala
native language for Spark
best performance
concise and powerful language
the language itself is not worth learning as a new language compared to Python
complicated syntax
Java: too verbose
R: not a general-purpose language
Advantages
Easier to install using pip than Scala
You may have learned Python already
Python worth the time to learn
PySpark Basics¶
Concepts
- SparkContext¶
Low-level context for RDD operations. In modern PySpark code, you usually access it from
spark.sparkContext.- SparkSession¶
Primary entry point to PySpark, including DataFrame and Spark SQL APIs.
- RDD (Resilient Distributed Dataset)¶
A fundamental building block of PySpark which is fault-tolerant, immutable distributed collection of objects
- DataFrame¶
A distributed collection of data organized into named columns.
- Dataset API¶
A strongly-typed API available in Scala/Java. In PySpark, DataFrame is the main structured API.
RDD
from Spark Core module
lower-level API
for unstructured data and semi-structured data
DataFrame (and Dataset API in Scala/Java)
from Spark SQL module
higher-level API
for structured data