<?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=SparkSession</id>
	<title>SparkSession - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=SparkSession"/>
	<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=SparkSession&amp;action=history"/>
	<updated>2026-12-06T00:13:33Z</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=SparkSession&amp;diff=196&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=SparkSession&amp;diff=196&amp;oldid=prev"/>
		<updated>2026-11-25T00:52:56Z</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            = SparkSession&lt;br /&gt;
| also_known_as   = Spark session, &amp;lt;code&amp;gt;spark&amp;lt;/code&amp;gt; (the variable name in shells and notebooks)&lt;br /&gt;
| field           = Distributed data processing&lt;br /&gt;
| introduced      = Apache Spark 2.0.0&lt;br /&gt;
| key_parts       = Builder (&amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;remote&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;appName&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;getOrCreate&amp;lt;/code&amp;gt;), runtime configuration (&amp;lt;code&amp;gt;spark.conf&amp;lt;/code&amp;gt;), catalog, DataFrame readers, SQL&lt;br /&gt;
| implementations = [[Apache Spark]] (Spark Classic and [[Spark Connect]])&lt;br /&gt;
| related         = [[SparkContext]], [[Driver (Apache Spark)]], [[Spark Connect]], [[Lazy evaluation]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the Spark 2.0.0 release notes, the v4.3.0 tag of apache/spark (python/pyspark/sql/session.py, python/pyspark/sql/connect/session.py, python/pyspark/shell.py, sql/api SparkSession.scala, docs/configuration.md, docs/spark-connect-overview.md, docs/spark-connect-gotchas.md) and a PySpark 4.3.0 run}}&lt;br /&gt;
&lt;br /&gt;
In [[Apache Spark]], a &amp;#039;&amp;#039;&amp;#039;SparkSession&amp;#039;&amp;#039;&amp;#039; is the entry point for programming with the DataFrame and Dataset API: it reads data, runs SQL, holds session configuration and temporary views, and gives access to the catalog.&amp;lt;ref name=&amp;quot;pysession&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/sql/session.py |title=session.py (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; SparkSession was added in Spark 2.0.0 to replace &amp;lt;code&amp;gt;SQLContext&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;HiveContext&amp;lt;/code&amp;gt;, which were kept for backward compatibility.&amp;lt;ref name=&amp;quot;r200&amp;quot;&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; In Spark 4 the same SparkSession API exists in two forms: a classic session that runs inside the [[Driver (Apache Spark)|driver]] next to a [[SparkContext]], and a [[Spark Connect]] session that is a thin client sending plans to a remote server.&lt;br /&gt;
&lt;br /&gt;
== How is a SparkSession created? ==&lt;br /&gt;
Code creates or reuses a SparkSession through its builder. In PySpark the main builder methods are:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;master(url)&amp;lt;/code&amp;gt;: the cluster manager URL for a classic session, for example &amp;lt;code&amp;gt;local[*]&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &amp;lt;code&amp;gt;remote(url)&amp;lt;/code&amp;gt;: the Spark Connect server URL, for example &amp;lt;code&amp;gt;sc://localhost:15002&amp;lt;/code&amp;gt;; this makes the session a Connect session.&lt;br /&gt;
* &amp;lt;code&amp;gt;appName(name)&amp;lt;/code&amp;gt;: the application name shown in the web UI.&lt;br /&gt;
* &amp;lt;code&amp;gt;config(key, value)&amp;lt;/code&amp;gt;: any Spark setting; values are passed to both the &amp;lt;code&amp;gt;SparkConf&amp;lt;/code&amp;gt; and the session&amp;#039;s own configuration.&lt;br /&gt;
* &amp;lt;code&amp;gt;enableHiveSupport()&amp;lt;/code&amp;gt;: connect to a [[Hive Metastore]] for persistent tables (not implemented for Connect sessions).&lt;br /&gt;
* &amp;lt;code&amp;gt;getOrCreate()&amp;lt;/code&amp;gt;: return the existing global default session, applying the builder&amp;#039;s options to it, or create a new one.&amp;lt;ref name=&amp;quot;pysession&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;connsession&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/sql/connect/session.py |title=connect/session.py (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;python&amp;quot;&amp;gt;&lt;br /&gt;
from pyspark.sql import SparkSession&lt;br /&gt;
&lt;br /&gt;
spark = (&lt;br /&gt;
    SparkSession.builder&lt;br /&gt;
    .master(&amp;quot;local[*]&amp;quot;)&lt;br /&gt;
    .appName(&amp;quot;orders-report&amp;quot;)&lt;br /&gt;
    .config(&amp;quot;spark.sql.shuffle.partitions&amp;quot;, &amp;quot;64&amp;quot;)&lt;br /&gt;
    .getOrCreate()&lt;br /&gt;
)&lt;br /&gt;
spark.sql(&amp;quot;SELECT 1 AS x&amp;quot;).show()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interactive tools usually create the session in advance. The PySpark shell creates it at startup and prints &amp;quot;SparkSession available as &amp;#039;spark&amp;#039;.&amp;quot;; in such environments the API documentation says to use the builder to get the existing session.&amp;lt;ref name=&amp;quot;pyshell&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/shell.py |title=shell.py (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;scalasession&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/SparkSession.scala |title=SparkSession.scala, sql/api (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Settings fall into two kinds. Runtime SQL settings such as &amp;lt;code&amp;gt;spark.sql.shuffle.partitions&amp;lt;/code&amp;gt; can be changed at any time with &amp;lt;code&amp;gt;spark.conf.set&amp;lt;/code&amp;gt;. Settings that shape the driver or executors, such as &amp;lt;code&amp;gt;spark.driver.memory&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;spark.executor.cores&amp;lt;/code&amp;gt;, take effect only when the application starts; in client mode, driver memory must even be passed on the &amp;lt;code&amp;gt;spark-submit&amp;lt;/code&amp;gt; command line.&amp;lt;ref name=&amp;quot;config&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/configuration.html |title=Spark Configuration (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does SparkSession relate to SparkContext? ==&lt;br /&gt;
A classic SparkSession wraps a [[SparkContext]]. The SparkContext is the connection to the cluster and owns the executors, the schedulers and the RDD API; only one SparkContext may be active per JVM.&amp;lt;ref name=&amp;quot;sc&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/SparkContext.scala |title=SparkContext.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Several SparkSessions can share that one SparkContext: &amp;lt;code&amp;gt;newSession()&amp;lt;/code&amp;gt; returns a session with its own SQL configuration, temporary views and UDFs, but the same SparkContext and table cache.&amp;lt;ref name=&amp;quot;pysession&amp;quot; /&amp;gt; Spark Connect sessions gained &amp;lt;code&amp;gt;newSession()&amp;lt;/code&amp;gt; in PySpark 4.3.0; the new Connect session starts empty against the same server.&amp;lt;ref name=&amp;quot;connsession&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In classic mode, &amp;lt;code&amp;gt;spark.sparkContext&amp;lt;/code&amp;gt; returns the underlying SparkContext. In the Spark 4.3.0 Scala API, the &amp;lt;code&amp;gt;sparkContext&amp;lt;/code&amp;gt; member is marked &amp;lt;code&amp;gt;@ClassicOnly&amp;lt;/code&amp;gt;, and in a PySpark Connect session, reading &amp;lt;code&amp;gt;spark.sparkContext&amp;lt;/code&amp;gt; raises the error &amp;lt;code&amp;gt;JVM_ATTRIBUTE_NOT_SUPPORTED&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;scalasession&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;connsession&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Spark Connect sessions vs classic sessions ==&lt;br /&gt;
A [[Spark Connect]] SparkSession offers the same DataFrame and SQL API, but the client and the Spark driver are separate processes. The client builds unresolved logical plans and sends them over gRPC to a Spark Connect server, which analyzes and runs them.&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;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! !! Classic SparkSession !! Spark Connect SparkSession&lt;br /&gt;
|-&lt;br /&gt;
! Where it runs&lt;br /&gt;
| In the driver JVM (PySpark talks to it through Py4J)&lt;br /&gt;
| In the client process; the driver runs on the Connect server&amp;lt;ref name=&amp;quot;connect&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! How it is created&lt;br /&gt;
| &amp;lt;code&amp;gt;SparkSession.builder.master(...)&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;SparkSession.builder.remote(&amp;quot;sc://host:port&amp;quot;)&amp;lt;/code&amp;gt;, or the &amp;lt;code&amp;gt;SPARK_REMOTE&amp;lt;/code&amp;gt; environment variable&amp;lt;ref name=&amp;quot;pysession&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Access to &amp;lt;code&amp;gt;SparkContext&amp;lt;/code&amp;gt; and RDDs&lt;br /&gt;
| Yes&lt;br /&gt;
| No; SparkContext and the RDD API are not supported&amp;lt;ref name=&amp;quot;connect&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! When a query is analyzed&lt;br /&gt;
| Eagerly, when each transformation is defined&lt;br /&gt;
| Lazily, when the plan is needed: schema access, &amp;lt;code&amp;gt;explain&amp;lt;/code&amp;gt;, persisting or an action&amp;lt;ref name=&amp;quot;gotchas&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/spark-connect-gotchas.html |title=Eager vs Lazy: Spark Connect vs Spark Classic (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Static Spark configuration&lt;br /&gt;
| Set by the application&lt;br /&gt;
| Not accessible to the client&amp;lt;ref name=&amp;quot;connect&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Client package for Python&lt;br /&gt;
| &amp;lt;code&amp;gt;pyspark&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;pyspark&amp;lt;/code&amp;gt;, or the lighter &amp;lt;code&amp;gt;pyspark-client&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;connect&amp;quot; /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Spark 4.0.0 added the &amp;lt;code&amp;gt;spark.api.mode&amp;lt;/code&amp;gt; setting (default &amp;lt;code&amp;gt;classic&amp;lt;/code&amp;gt;). Set to &amp;lt;code&amp;gt;connect&amp;lt;/code&amp;gt;, it makes a Spark Classic application start a local Spark Connect server and use a Connect session automatically.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spark Connect introduced session-scoped methods that cover tasks once done through the SparkContext: &amp;lt;code&amp;gt;addArtifacts&amp;lt;/code&amp;gt; adds local files, Python files or archives to the session, and &amp;lt;code&amp;gt;addTag&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;interruptTag&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;interruptAll&amp;lt;/code&amp;gt; cancels running operations. They were added in PySpark 3.5.0 for Connect and work in Spark Classic since 4.0.0.&amp;lt;ref name=&amp;quot;pysession&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[SparkContext]]&lt;br /&gt;
* [[Spark Connect]]&lt;br /&gt;
* [[Driver (Apache Spark)]]&lt;br /&gt;
* [[Lazy evaluation]]&lt;br /&gt;
* [[Catalyst optimizer]]&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>