<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Dataset_(Spark)</id>
	<title>Dataset (Spark) - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Dataset_(Spark)"/>
	<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Dataset_(Spark)&amp;action=history"/>
	<updated>2026-12-06T00:08:20Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>https://openlakehouse.io/w/index.php?title=Dataset_(Spark)&amp;diff=137&amp;oldid=prev</id>
		<title>Open Lakehouse Wiki sync: Sync from open-lakehouse/wiki@7c9abaa</title>
		<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Dataset_(Spark)&amp;diff=137&amp;oldid=prev"/>
		<updated>2026-11-25T00:52:38Z</updated>

		<summary type="html">&lt;p&gt;Sync from open-lakehouse/wiki@7c9abaa&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Infobox concept&lt;br /&gt;
| name            = Dataset (Spark)&lt;br /&gt;
| also_known_as   = Typed Dataset, &amp;lt;code&amp;gt;Dataset[T]&amp;lt;/code&amp;gt;&lt;br /&gt;
| field           = Data processing APIs&lt;br /&gt;
| introduced      = Spark 1.6.0&lt;br /&gt;
| key_parts       = A JVM type &amp;lt;code&amp;gt;T&amp;lt;/code&amp;gt;, an [[Encoder (Spark)|encoder]] for that type, a logical plan&lt;br /&gt;
| implementations = [[Apache Spark]] (Scala and Java APIs)&lt;br /&gt;
| related         = [[DataFrame]], [[Encoder (Spark)]], [[RDD]], [[Spark Connect]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (Dataset.scala, package.scala, Encoder.scala, docs/sql-programming-guide.md, docs/sql-getting-started.md, docs/sql-migration-guide.md, docs/spark-connect-overview.md) and the Spark 1.6.0 and 2.0.0 release notes}}&lt;br /&gt;
&lt;br /&gt;
In [[Apache Spark]], a &amp;#039;&amp;#039;&amp;#039;Dataset&amp;#039;&amp;#039;&amp;#039; is a strongly typed, distributed collection of objects of one JVM type &amp;lt;code&amp;gt;T&amp;lt;/code&amp;gt; that can be transformed in parallel with functional operations such as &amp;lt;code&amp;gt;map&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;filter&amp;lt;/code&amp;gt; or with relational operations such as &amp;lt;code&amp;gt;select&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;groupBy&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;dataset&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/api/src/main/scala/org/apache/spark/sql/Dataset.scala |title=Dataset.scala (tag v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; It combines the typed lambdas of the [[RDD]] API with the optimized execution engine of Spark SQL.&amp;lt;ref name=&amp;quot;guide&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-programming-guide.html |title=Spark SQL, DataFrames and Datasets Guide (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The Dataset API exists only in Scala and Java; a [[DataFrame]] is the untyped Dataset of &amp;lt;code&amp;gt;Row&amp;lt;/code&amp;gt; objects, and it is the only form available in Python and R.&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How is a Dataset different from a DataFrame? ==&lt;br /&gt;
A DataFrame is a Dataset whose element type is the generic &amp;lt;code&amp;gt;Row&amp;lt;/code&amp;gt;. In Scala the alias is declared in the &amp;lt;code&amp;gt;org.apache.spark.sql&amp;lt;/code&amp;gt; package object as &amp;lt;code&amp;gt;type DataFrame = Dataset[Row]&amp;lt;/code&amp;gt;; in Java the type is written &amp;lt;code&amp;gt;Dataset&amp;lt;Row&amp;gt;&amp;lt;/code&amp;gt;.&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/api/src/main/scala/org/apache/spark/sql/package.scala |title=package.scala (tag v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both forms share one class, so both kinds of operation are available on any Dataset. The Spark documentation calls column-based operations such as &amp;lt;code&amp;gt;select&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;groupBy&amp;lt;/code&amp;gt; &amp;quot;untyped transformations&amp;quot;, and operations that take a lambda over &amp;lt;code&amp;gt;T&amp;lt;/code&amp;gt;, such as &amp;lt;code&amp;gt;map&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;filter&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;groupByKey&amp;lt;/code&amp;gt;, &amp;quot;typed transformations&amp;quot;.&amp;lt;ref name=&amp;quot;started&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-getting-started.html |title=Getting Started (Spark SQL, Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;migration&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-migration-guide.html |title=Migration Guide: SQL, Datasets and DataFrame (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; A DataFrame becomes a typed Dataset with &amp;lt;code&amp;gt;as[T]&amp;lt;/code&amp;gt;, which maps columns to fields by name.&amp;lt;ref name=&amp;quot;dataset&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Like a DataFrame, a Dataset is lazy. It represents a logical plan, transformations return new Datasets, and an action such as &amp;lt;code&amp;gt;count&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;show&amp;lt;/code&amp;gt; or a write runs the optimized physical plan on the [[executor|executors]].&amp;lt;ref name=&amp;quot;dataset&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What does a Dataset need an encoder for? ==&lt;br /&gt;
{{Main|Encoder (Spark)}}&lt;br /&gt;
Every Dataset needs an [[Encoder (Spark)|encoder]] for its type. The encoder maps &amp;lt;code&amp;gt;T&amp;lt;/code&amp;gt; to Spark&amp;#039;s internal type system, and Spark uses it to generate code that serializes objects into a compact binary form.&amp;lt;ref name=&amp;quot;dataset&amp;quot; /&amp;gt; Spark can filter, sort and hash data in that form without turning the bytes back into objects, which is the difference from Java or Kryo serialization of RDD elements.&amp;lt;ref name=&amp;quot;started&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Scala, &amp;lt;code&amp;gt;import spark.implicits._&amp;lt;/code&amp;gt; supplies encoders for primitive types and case classes. In Java, encoders come from static methods on &amp;lt;code&amp;gt;Encoders&amp;lt;/code&amp;gt;, such as &amp;lt;code&amp;gt;Encoders.bean(Person.class)&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;encoder&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/api/src/main/scala/org/apache/spark/sql/Encoder.scala |title=Encoder.scala (tag v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
This Scala example is adapted from the Spark SQL examples at v4.3.0. It reads a JSON file into a DataFrame, converts it to a typed Dataset of a case class, and applies a typed and an untyped transformation.&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/examples/src/main/scala/org/apache/spark/examples/sql/SparkSQLExample.scala |title=SparkSQLExample.scala (tag v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;scala&amp;quot;&amp;gt;&lt;br /&gt;
import org.apache.spark.sql.{Dataset, SparkSession}&lt;br /&gt;
&lt;br /&gt;
case class Person(name: String, age: Option[Long])&lt;br /&gt;
&lt;br /&gt;
val spark = SparkSession.builder().getOrCreate()&lt;br /&gt;
import spark.implicits._&lt;br /&gt;
&lt;br /&gt;
val people: Dataset[Person] =&lt;br /&gt;
  spark.read.json(&amp;quot;examples/src/main/resources/people.json&amp;quot;).as[Person]&lt;br /&gt;
&lt;br /&gt;
val adultNames: Dataset[String] =&lt;br /&gt;
  people.filter(p =&amp;gt; p.age.exists(_ &amp;gt;= 21)).map(_.name)   // typed&lt;br /&gt;
&lt;br /&gt;
val byAge = people.groupBy(&amp;quot;age&amp;quot;).count()                   // untyped, returns a DataFrame&lt;br /&gt;
byAge.show()&lt;br /&gt;
adultNames.show()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same query in PySpark uses a DataFrame and column expressions, because Python has no typed Dataset:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from pyspark.sql import functions as F&lt;br /&gt;
&lt;br /&gt;
people = spark.read.json(&amp;quot;examples/src/main/resources/people.json&amp;quot;)&lt;br /&gt;
adult_names = people.filter(F.col(&amp;quot;age&amp;quot;) &amp;gt;= 21).select(&amp;quot;name&amp;quot;)&lt;br /&gt;
adult_names.show()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Why does PySpark have no Dataset API? ==&lt;br /&gt;
The Dataset&amp;#039;s value is compile-time type safety: the compiler checks that a lambda receives a &amp;lt;code&amp;gt;Person&amp;lt;/code&amp;gt; and returns a &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt;. When Spark 2.0 unified the two APIs, the migration guide noted that compile-time type safety is not a language feature of Python and R, so the Dataset concept does not apply to them and the DataFrame stays their main abstraction.&amp;lt;ref name=&amp;quot;migration&amp;quot; /&amp;gt; The programming guide adds that, because Python is dynamic, many of the Dataset&amp;#039;s benefits are already available there; for example, a field of a &amp;lt;code&amp;gt;Row&amp;lt;/code&amp;gt; can be read by name as &amp;lt;code&amp;gt;row.columnName&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PySpark code that needs per-row Python logic uses a [[User-defined function (Spark)|user-defined function]] or &amp;lt;code&amp;gt;mapInPandas&amp;lt;/code&amp;gt;, which maps an iterator of pandas DataFrames to another, rather than a typed &amp;lt;code&amp;gt;map&amp;lt;/code&amp;gt;.&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/docs/source/tutorial/sql/arrow_pandas.rst |title=Apache Arrow in PySpark (arrow_pandas.rst at v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Does Spark Connect support Datasets? ==&lt;br /&gt;
Yes. The Spark Connect Scala client supports most Scala APIs since Spark 3.5, including &amp;lt;code&amp;gt;Dataset&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;KeyValueGroupedDataset&amp;lt;/code&amp;gt;. User-defined functions, which typed transformations rely on, work by default in the shell and need extra set-up in standalone applications.&amp;lt;ref name=&amp;quot;connect&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/spark-connect-overview.html |title=Spark Connect Overview (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; See [[Spark Connect]].&lt;br /&gt;
&lt;br /&gt;
== Is the Dataset API deprecated? ==&lt;br /&gt;
No. The &amp;lt;code&amp;gt;Dataset&amp;lt;/code&amp;gt; class is annotated &amp;lt;code&amp;gt;@Stable&amp;lt;/code&amp;gt; at the v4.3.0 tag, and the Spark 4.3.0 documentation presents it as a current API for Scala and Java.&amp;lt;ref name=&amp;quot;dataset&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
Spark 1.6.0 added the Dataset API (SPARK-9999) as a new API, similar to RDDs, for working with custom objects and lambda functions while using the Spark SQL execution engine.&amp;lt;ref&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-1-6-0.html |title=Spark Release 1.6.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Spark 2.0.0 unified DataFrame and Dataset in Scala and Java, so that DataFrame became a type alias for &amp;lt;code&amp;gt;Dataset[Row]&amp;lt;/code&amp;gt;, and introduced a typed &amp;lt;code&amp;gt;Aggregator&amp;lt;/code&amp;gt; API for Datasets.&amp;lt;ref&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-2-0-0.html |title=Spark Release 2.0.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[DataFrame]]&lt;br /&gt;
* [[Encoder (Spark)]]&lt;br /&gt;
* [[RDD]]&lt;br /&gt;
* [[Spark Connect]]&lt;br /&gt;
* [[User-defined function (Spark)]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Navbox open lakehouse}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Concepts]]&lt;br /&gt;
[[Category:Glossary terms]]&lt;br /&gt;
[[Category:Apache Spark]]&lt;/div&gt;</summary>
		<author><name>Open Lakehouse Wiki sync</name></author>
	</entry>
</feed>