Usage
Who this is for:
Architecture / Concept Overview: Usage
PySpark wraps the JVM-based Spark engine, translating Python API calls into JVM operations. DataFrame operations execute entirely on the JVM, with Python used only for defining the computation graph and handling driver-side logic.
%%{init: {"theme":"base","themeVariables":{"background":"#0B0E14","primaryTextColor":"#E0E6ED","lineColor":"#5D6470","darkMode":true,"primaryColor":"#2E4A4A","secondaryColor":"#374151","secondaryTextColor":"#E0E6ED","tertiaryColor":"#111827","tertiaryTextColor":"#E0E6ED","edgeLabelBackground":"#1f2937"}}}%%
flowchart LR
classDef source fill:#3F4B59,stroke:#9CA3AF,stroke-width:2px,rx:8,ry:8,color:#E0E6ED
classDef ingestion fill:#5A4B36,stroke:#C9A86B,stroke-width:2px,rx:8,ry:8,color:#E0E6ED
classDef processing fill:#535072,stroke:#8E82B4,stroke-width:2px,rx:8,ry:8,color:#E0E6ED
classDef storage fill:#2E4A4A,stroke:#5FAFA8,stroke-width:2px,rx:8,ry:8,color:#E0E6ED
classDef serving fill:#3D5550,stroke:#6BB7AA,stroke-width:2px,rx:8,ry:8,color:#E0E6ED
classDef governance fill:#5A3F52,stroke:#C28BB0,stroke-width:2px,rx:8,ry:8,color:#E0E6ED
PYCODE[PySpark Code]:::source --> PYAPI[Python API Layer]:::processing
PYAPI --> |Py4J Bridge| JVM[JVM - Catalyst + Tungsten]:::processing
JVM --> PLAN[Optimized Execution Plan]:::processing
PLAN --> EXE[Distributed Executors]:::serving
EXE --> DELTA[Delta Lake]:::storage
*PySpark code translates through Py4J to the JVM where Catalyst optimizes and executors process the data.*
%%{init: {"theme":"base","themeVariables":{"background":"#0B0E14","primaryTextColor":"#E0E6ED","lineColor":"#5D6470","darkMode":true,"primaryColor":"#2E4A4A","secondaryColor":"#374151","secondaryTextColor":"#E0E6ED","tertiaryColor":"#111827","tertiaryTextColor":"#E0E6ED","edgeLabelBackground":"#1f2937"}}}%%
graph TD
classDef source fill:#3F4B59,stroke:#9CA3AF,stroke-width:2px,rx:8,ry:8,color:#E0E6ED
classDef ingestion fill:#5A4B36,stroke:#C9A86B,stroke-width:2px,rx:8,ry:8,color:#E0E6ED
classDef processing fill:#535072,stroke:#8E82B4,stroke-width:2px,rx:8,ry:8,color:#E0E6ED
classDef storage fill:#2E4A4A,stroke:#5FAFA8,stroke-width:2px,rx:8,ry:8,color:#E0E6ED
classDef serving fill:#3D5550,stroke:#6BB7AA,stroke-width:2px,rx:8,ry:8,color:#E0E6ED
classDef governance fill:#5A3F52,stroke:#C28BB0,stroke-width:2px,rx:8,ry:8,color:#E0E6ED
PS[PySpark Modules]:::processing
PS --> SQL[pyspark.sql - DataFrames & SQL]:::processing
PS --> FUNC[pyspark.sql.functions - Built-in Functions]:::processing
PS --> TYPES[pyspark.sql.types - Schema Types]:::storage
PS --> WIN[pyspark.sql.window - Window Functions]:::serving
PS --> SS[pyspark.sql.streaming - Structured Streaming]:::ingestion
PS --> DELTA[delta.tables - Delta Lake API]:::storage
*Key PySpark modules for data engineering.*
Key Terms
Prerequisites and Setup
- Databricks notebook with Python kernel.
- Cluster running Databricks Runtime 13.3 LTS or later.
- Familiarity with Python data types and basic Pandas concepts.
Step-by-Step Implementation
Configuration Reference
| Parameter | Description | Default |
|---|---|---|
spark.sql.shuffle.partitions | Shuffle partition count | 200 |
spark.sql.execution.arrow.pyspark.enabled | Enable Arrow for toPandas() | true |
spark.sql.execution.arrow.pyspark.fallback.enabled | Fall back if Arrow conversion fails | true |
spark.python.worker.reuse | Reuse Python workers | true |
spark.sql.adaptive.enabled | Enable AQE | true |