Question 1easy#Fundamentals#RDD
What are RDDs, and how are they different from DataFrames and Datasets?
Say your answer out loud first, the way you would in the room.
In shortAn RDD (resilient distributed dataset) is Spark's original low-level abstraction: an immutable, partitioned collection of objects that Spark can process in parallel and rebuild from its lineage if a partition is lost.
An RDD (resilient distributed dataset) is Spark's original low-level abstraction: an immutable, partitioned collection of objects that Spark can process in parallel and rebuild from its lineage if a partition is lost. DataFrames and Datasets are built on top of it and add a schema, which lets Spark's optimizer plan the work.
| RDD | DataFrame | Dataset | |
|---|---|---|---|
| Data | Any objects | Rows with named, typed columns | Typed objects (Scala case classes, Java beans) |
| Schema | None known to Spark | Yes | Yes |
| Optimisation | None: runs your functions as written | Catalyst optimizer and Tungsten code generation | Same as DataFrame |
| Type checks | At runtime | At runtime (column errors at analysis) | At compile time |
| Languages | Scala, Java, Python | Scala, Java, Python, R, SQL | Scala and Java only |
| API style | Functional: map, filter, reduceByKey | Declarative: select, groupBy, SQL | Both |
Why DataFrames are the default
- Spark understands column operations, so it can push filters to the source, read only needed columns, choose join strategies and generate efficient code.
- In Python, RDD functions run in Python worker processes with data serialised back and forth, which is slow; DataFrame operations run in the JVM.
- In Python a DataFrame is the equivalent of a Dataset of rows; there is no typed Dataset API.
When an RDD still fits Low-level control over partitioning, or processing unstructured data that doesn't fit a table. Even then, most code converts to a DataFrame quickly. Spark Connect, used by serverless compute and many newer setups, doesn't offer the RDD API at all.