<?xml version="1.0"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title>Open Lakehouse Wiki  - Recent changes [en]</title>
		<link>https://openlakehouse.io/wiki/Special:RecentChanges</link>
		<description>Track the most recent changes to the wiki in this feed.</description>
		<language>en</language>
		<generator>MediaWiki 1.43.11</generator>
		<lastBuildDate>Sun, 06 Dec 2026 00:29:08 GMT</lastBuildDate>
		<item>
			<title>Category:People</title>
			<link>https://openlakehouse.io/w/index.php?title=Category:People&amp;diff=218&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Category:People&amp;diff=218&amp;oldid=0</guid>
			<description>&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;Biographical articles about people associated with open lakehouse technologies.&lt;/div&gt;</description>
			<pubDate>Wed, 25 Nov 2026 00:53:04 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Category_talk:People</comments>
		</item>
		<item>
			<title>Template:Infobox person</title>
			<link>https://openlakehouse.io/w/index.php?title=Template:Infobox_person&amp;diff=219&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Template:Infobox_person&amp;diff=219&amp;oldid=0</guid>
			<description>&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;&amp;lt;includeonly&amp;gt;{| class=&amp;quot;infobox&amp;quot;&lt;br /&gt;
|+ class=&amp;quot;infobox-title&amp;quot; | {{{name|{{PAGENAME}}}}}&lt;br /&gt;
{{#if:{{{image|}}}|{{!}}-&lt;br /&gt;
{{!}} colspan=&amp;quot;2&amp;quot; class=&amp;quot;infobox-image&amp;quot; {{!}} [[File:{{{image}}}|200px]]{{#if:{{{caption|}}}|&amp;lt;br/&amp;gt;&amp;lt;small&amp;gt;{{{caption}}}&amp;lt;/small&amp;gt;}}}}&lt;br /&gt;
{{#if:{{{known_for|}}}|{{!}}-&lt;br /&gt;
! Known for&lt;br /&gt;
{{!}} {{{known_for}}}}}&lt;br /&gt;
{{#if:{{{role|}}}|{{!}}-&lt;br /&gt;
! Role&lt;br /&gt;
{{!}} {{{role}}}}}&lt;br /&gt;
{{#if:{{{affiliations|}}}|{{!}}-&lt;br /&gt;
! Affiliations&lt;br /&gt;
{{!}} {{{affiliations}}}}}&lt;br /&gt;
{{#if:{{{projects|}}}|{{!}}-&lt;br /&gt;
! Projects&lt;br /&gt;
{{!}} {{{projects}}}}}&lt;br /&gt;
{{#if:{{{nationality|}}}|{{!}}-&lt;br /&gt;
! Nationality&lt;br /&gt;
{{!}} {{{nationality}}}}}&lt;br /&gt;
{{#if:{{{website|}}}|{{!}}-&lt;br /&gt;
! Website&lt;br /&gt;
{{!}} {{{website}}}}}&lt;br /&gt;
|}&amp;lt;/includeonly&amp;gt;&amp;lt;noinclude&amp;gt;&lt;br /&gt;
Infobox for a person associated with open lakehouse technologies. Every field is optional. Do not add a birth date; include it only if it is already public and relevant, and keep it optional.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{{Infobox person&lt;br /&gt;
| name         = Jane Doe&lt;br /&gt;
| image        =&lt;br /&gt;
| caption      =&lt;br /&gt;
| known_for    = [[Apache Iceberg]]&lt;br /&gt;
| role         = Software engineer&lt;br /&gt;
| affiliations = [[Apache Software Foundation]]&lt;br /&gt;
| projects     = [[Apache Iceberg]], [[Apache Spark]]&lt;br /&gt;
| nationality  =&lt;br /&gt;
| website      = [https://example.org example.org]&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Use only sourced, verifiable facts, and follow the living-persons guidance in the style guide. Add a {{tl|Verified}} line to the article.&lt;br /&gt;
[[Category:Infobox templates]]&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</description>
			<pubDate>Wed, 25 Nov 2026 00:53:04 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Template_talk:Infobox_person</comments>
		</item>
		<item>
			<title>Template:Navbox open lakehouse</title>
			<link>https://openlakehouse.io/w/index.php?title=Template:Navbox_open_lakehouse&amp;diff=220&amp;oldid=113</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Template:Navbox_open_lakehouse&amp;diff=220&amp;oldid=113</guid>
			<description>&lt;p&gt;Sync from open-lakehouse/wiki@7c9abaa&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 00:53, 25 November 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l34&quot;&gt;Line 34:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 34:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;! class=&amp;quot;navbox-group&amp;quot; | Storage and licensing&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;! class=&amp;quot;navbox-group&amp;quot; | Storage and licensing&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| class=&amp;quot;navbox-list&amp;quot; | [[MinIO]] · [[Business Source License]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| class=&amp;quot;navbox-list&amp;quot; | [[MinIO]] · [[Business Source License]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;|-&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;! class=&quot;navbox-group&quot; | People&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;| class=&quot;navbox-list&quot; | [[:Category:People|People]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;! class=&amp;quot;navbox-group&amp;quot; | Reference&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;! class=&amp;quot;navbox-group&amp;quot; | Reference&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wiki:diff:1.41:old-113:rev-220:php=table --&gt;
&lt;/table&gt;</description>
			<pubDate>Wed, 25 Nov 2026 00:53:04 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Template_talk:Navbox_open_lakehouse</comments>
		</item>
		<item>
			<title>Window functions</title>
			<link>https://openlakehouse.io/w/index.php?title=Window_functions&amp;diff=216&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Window_functions&amp;diff=216&amp;oldid=0</guid>
			<description>&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            = Window functions&lt;br /&gt;
| also_known_as   = Analytic functions, OVER clause&lt;br /&gt;
| field           = SQL query processing&lt;br /&gt;
| key_parts       = Partitioning, ordering, window frame (ROWS or RANGE), ranking, offset and aggregate functions&lt;br /&gt;
| implementations = [[Apache Spark]], PostgreSQL, [[Trino]], [[DuckDB]], Snowflake&lt;br /&gt;
| related         = [[Shuffle]], [[Partition]], [[Lateral column alias]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (docs/sql-ref-syntax-qry-select-window.md, docs/sql-ref-syntax-qry-select-qualify.md, docs/sql-ref-syntax-qry-select.md, SqlBaseParser.g4, python/pyspark/sql/window.py, WindowExecBase.scala, sql-tests/inputs/window.sql), the Spark 4.2.0 release notes, PostgreSQL 19 documentation, Trino 484 documentation, DuckDB 2.0 documentation and Snowflake documentation}}&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;&amp;#039;window function&amp;#039;&amp;#039;&amp;#039; is a SQL function that computes a value for each row from a group of related rows, called the window, without collapsing those rows into one as &amp;lt;code&amp;gt;GROUP BY&amp;lt;/code&amp;gt; does; in [[Apache Spark]] it is written as a function followed by an &amp;lt;code&amp;gt;OVER&amp;lt;/code&amp;gt; clause that names the partitioning, the ordering and an optional frame.&amp;lt;ref name=&amp;quot;sparkwin&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-ref-syntax-qry-select-window.html |title=Window Functions (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Window functions are used for rankings, running totals, moving averages and comparisons with the previous or next row. SQL engines that support them differ in frame types, null handling and the filtering clause &amp;lt;code&amp;gt;QUALIFY&amp;lt;/code&amp;gt;, which the comparison table below sets out.&lt;br /&gt;
&lt;br /&gt;
== How does a window function work? ==&lt;br /&gt;
The &amp;lt;code&amp;gt;OVER&amp;lt;/code&amp;gt; clause has three parts. &amp;lt;code&amp;gt;PARTITION BY&amp;lt;/code&amp;gt; splits rows into independent groups; &amp;lt;code&amp;gt;ORDER BY&amp;lt;/code&amp;gt; orders rows inside each group; and the frame clause picks which rows around the current row the function sees. In Spark SQL the frame is written &amp;lt;code&amp;gt;{ RANGE | ROWS } { frame_start | BETWEEN frame_start AND frame_end }&amp;lt;/code&amp;gt;, with bounds &amp;lt;code&amp;gt;UNBOUNDED PRECEDING&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;offset PRECEDING&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;CURRENT ROW&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;offset FOLLOWING&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;UNBOUNDED FOLLOWING&amp;lt;/code&amp;gt;; an omitted &amp;lt;code&amp;gt;frame_end&amp;lt;/code&amp;gt; means &amp;lt;code&amp;gt;CURRENT ROW&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;sparkwin&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;code&amp;gt;ROWS&amp;lt;/code&amp;gt; frame counts physical rows. A &amp;lt;code&amp;gt;RANGE&amp;lt;/code&amp;gt; frame uses value distance on the ordering column, so rows with equal ordering values (peers) are in or out of the frame together. Spark accepts numeric, date and interval offsets in &amp;lt;code&amp;gt;RANGE&amp;lt;/code&amp;gt; frames, for example &amp;lt;code&amp;gt;RANGE BETWEEN CURRENT ROW AND INTERVAL 23 DAYS 4 HOURS FOLLOWING&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;wintests&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/test/resources/sql-tests/inputs/window.sql |title=sql-tests/inputs/window.sql (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What is the default frame? ==&lt;br /&gt;
In Spark, when a window has no ordering, the frame is the whole partition (&amp;lt;code&amp;gt;ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING&amp;lt;/code&amp;gt;). When ordering is defined, the default is a growing frame, &amp;lt;code&amp;gt;RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;pywin&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/sql/window.py |title=window.py (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; This is why &amp;lt;code&amp;gt;last_value(x) OVER (ORDER BY t)&amp;lt;/code&amp;gt; returns the current row&amp;#039;s value (or that of its last peer) unless the frame is extended to &amp;lt;code&amp;gt;UNBOUNDED FOLLOWING&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Which kinds of window functions are there? ==&lt;br /&gt;
Spark groups window functions into three kinds.&amp;lt;ref name=&amp;quot;sparkwin&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Ranking functions:&amp;#039;&amp;#039;&amp;#039; &amp;lt;code&amp;gt;ROW_NUMBER&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;RANK&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DENSE_RANK&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;PERCENT_RANK&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;NTILE&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Analytic (offset and value) functions:&amp;#039;&amp;#039;&amp;#039; &amp;lt;code&amp;gt;LAG&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;LEAD&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;NTH_VALUE&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;FIRST_VALUE&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;LAST_VALUE&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;CUME_DIST&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Aggregate functions&amp;#039;&amp;#039;&amp;#039; used with &amp;lt;code&amp;gt;OVER&amp;lt;/code&amp;gt;, such as &amp;lt;code&amp;gt;SUM&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;AVG&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;MIN&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;MAX&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;COUNT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;LAG&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;LEAD&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;NTH_VALUE&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;FIRST_VALUE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;LAST_VALUE&amp;lt;/code&amp;gt; accept &amp;lt;code&amp;gt;IGNORE NULLS&amp;lt;/code&amp;gt; in Spark; the default is &amp;lt;code&amp;gt;RESPECT NULLS&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;sparkwin&amp;quot; /&amp;gt; &amp;lt;code&amp;gt;RANK&amp;lt;/code&amp;gt; leaves gaps after ties and &amp;lt;code&amp;gt;DENSE_RANK&amp;lt;/code&amp;gt; does not.&amp;lt;ref name=&amp;quot;sparkwin&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How do you filter on a window function? ==&lt;br /&gt;
Spark SQL has a &amp;lt;code&amp;gt;QUALIFY&amp;lt;/code&amp;gt; clause that filters rows after window functions are evaluated, either by referring to a window function&amp;#039;s alias in the &amp;lt;code&amp;gt;SELECT&amp;lt;/code&amp;gt; list or by writing the window function in the condition itself; it was added in Spark 4.2.0 (SPARK-31561).&amp;lt;ref name=&amp;quot;qualify&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-ref-syntax-qry-select-qualify.html |title=QUALIFY Clause (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;r420&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4-2-0.html |title=Spark Release 4.2.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Without &amp;lt;code&amp;gt;QUALIFY&amp;lt;/code&amp;gt;, the same result needs a subquery or common table expression with a &amp;lt;code&amp;gt;WHERE&amp;lt;/code&amp;gt; on the computed column. A named window can be declared once with the &amp;lt;code&amp;gt;WINDOW&amp;lt;/code&amp;gt; clause and reused.&amp;lt;ref name=&amp;quot;select&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-ref-syntax-qry-select.html |title=SELECT (Spark 4.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;
PySpark, with a rank, the previous salary and a three-row moving average per department:&amp;lt;ref name=&amp;quot;pywin&amp;quot; /&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 Window, functions as F&lt;br /&gt;
&lt;br /&gt;
w = Window.partitionBy(&amp;quot;dept&amp;quot;).orderBy(&amp;quot;salary&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
df.select(&lt;br /&gt;
    &amp;quot;name&amp;quot;, &amp;quot;dept&amp;quot;, &amp;quot;salary&amp;quot;,&lt;br /&gt;
    F.rank().over(w).alias(&amp;quot;rank&amp;quot;),&lt;br /&gt;
    F.lag(&amp;quot;salary&amp;quot;).over(w).alias(&amp;quot;prev_salary&amp;quot;),&lt;br /&gt;
    F.avg(&amp;quot;salary&amp;quot;).over(w.rowsBetween(-1, 1)).alias(&amp;quot;moving_avg&amp;quot;),&lt;br /&gt;
).show()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spark SQL, keeping the highest-paid employee of each department with &amp;lt;code&amp;gt;QUALIFY&amp;lt;/code&amp;gt;:&amp;lt;ref name=&amp;quot;qualify&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT name, dept, salary&lt;br /&gt;
FROM employees&lt;br /&gt;
QUALIFY ROW_NUMBER() OVER (PARTITION BY dept ORDER BY salary DESC) = 1;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How do window functions run in Spark? ==&lt;br /&gt;
Spark&amp;#039;s physical window operator requires its input to be clustered by the &amp;lt;code&amp;gt;PARTITION BY&amp;lt;/code&amp;gt; columns and sorted by the partition and &amp;lt;code&amp;gt;ORDER BY&amp;lt;/code&amp;gt; columns, so the planner usually adds a [[shuffle]] and a sort before it. A window with no &amp;lt;code&amp;gt;PARTITION BY&amp;lt;/code&amp;gt; requires all rows in one partition, and Spark logs a warning that this &amp;quot;can cause serious performance degradation&amp;quot;.&amp;lt;ref name=&amp;quot;winexec&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/window/WindowExecBase.scala |title=WindowExecBase.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Engine differences ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Feature !! Apache Spark 4.3 !! PostgreSQL 19 !! Trino 484 !! DuckDB 2.0 !! Snowflake&lt;br /&gt;
|-&lt;br /&gt;
! Frame types&lt;br /&gt;
| &amp;lt;code&amp;gt;ROWS&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;RANGE&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;sparkwin&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;ROWS&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;RANGE&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;GROUPS&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;pgexpr&amp;quot;&amp;gt;{{Cite web |url=https://www.postgresql.org/docs/current/sql-expressions.html |title=Value Expressions: Window Function Calls (PostgreSQL 19) |publisher=PostgreSQL Global Development Group |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;ROWS&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;RANGE&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;GROUPS&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;trinomr&amp;quot;&amp;gt;{{Cite web |url=https://trino.io/docs/current/sql/pattern-recognition-in-window.html |title=Row pattern recognition in window structures (Trino 484) |publisher=Trino Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;ROWS&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;RANGE&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;GROUPS&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;duck&amp;quot;&amp;gt;{{Cite web |url=https://duckdb.org/docs/2.0/sql/functions/window_functions |title=Window Functions (DuckDB 2.0) |publisher=DuckDB Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;ROWS&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;RANGE&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;snowwin&amp;quot;&amp;gt;{{Cite web |url=https://docs.snowflake.com/en/sql-reference/functions-window-syntax |title=Window function syntax and usage |publisher=Snowflake |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Frame exclusion (&amp;lt;code&amp;gt;EXCLUDE&amp;lt;/code&amp;gt;)&lt;br /&gt;
| Not in the frame grammar&amp;lt;ref name=&amp;quot;grammar&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/api/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBaseParser.g4 |title=SqlBaseParser.g4 (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| Yes&amp;lt;ref name=&amp;quot;pgexpr&amp;quot; /&amp;gt;&lt;br /&gt;
| Yes&amp;lt;ref name=&amp;quot;trinoselect&amp;quot;&amp;gt;{{Cite web |url=https://trino.io/docs/current/sql/select.html |title=SELECT (Trino 484) |publisher=Trino Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| Yes&amp;lt;ref name=&amp;quot;duck&amp;quot; /&amp;gt;&lt;br /&gt;
| Not documented&amp;lt;ref name=&amp;quot;snowwin&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Default frame with &amp;lt;code&amp;gt;ORDER BY&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;pywin&amp;quot; /&amp;gt;&lt;br /&gt;
| Same&amp;lt;ref name=&amp;quot;pgexpr&amp;quot; /&amp;gt;&lt;br /&gt;
| Same&amp;lt;ref name=&amp;quot;trinoselect&amp;quot; /&amp;gt;&lt;br /&gt;
| Same&amp;lt;ref name=&amp;quot;duck&amp;quot; /&amp;gt;&lt;br /&gt;
| Same for aggregates; &amp;lt;code&amp;gt;ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING&amp;lt;/code&amp;gt; for &amp;lt;code&amp;gt;FIRST_VALUE&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;LAST_VALUE&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;NTH_VALUE&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;snowwin&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! &amp;lt;code&amp;gt;IGNORE NULLS&amp;lt;/code&amp;gt; on offset and value functions&lt;br /&gt;
| Yes&amp;lt;ref name=&amp;quot;sparkwin&amp;quot; /&amp;gt;&lt;br /&gt;
| Yes&amp;lt;ref name=&amp;quot;pgfunc&amp;quot;&amp;gt;{{Cite web |url=https://www.postgresql.org/docs/current/functions-window.html |title=Window Functions (PostgreSQL 19) |publisher=PostgreSQL Global Development Group |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| Yes&amp;lt;ref name=&amp;quot;trinowin&amp;quot;&amp;gt;{{Cite web |url=https://trino.io/docs/current/functions/window.html |title=Window functions (Trino 484) |publisher=Trino Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| Yes&amp;lt;ref name=&amp;quot;duck&amp;quot; /&amp;gt;&lt;br /&gt;
| Yes (for example &amp;lt;code&amp;gt;LAG&amp;lt;/code&amp;gt;)&amp;lt;ref&amp;gt;{{Cite web |url=https://docs.snowflake.com/en/sql-reference/functions/lag |title=LAG |publisher=Snowflake |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! &amp;lt;code&amp;gt;QUALIFY&amp;lt;/code&amp;gt;&lt;br /&gt;
| Yes, since 4.2.0&amp;lt;ref name=&amp;quot;r420&amp;quot; /&amp;gt;&lt;br /&gt;
| Not documented&amp;lt;ref name=&amp;quot;pgselect&amp;quot;&amp;gt;{{Cite web |url=https://www.postgresql.org/docs/current/sql-select.html |title=SELECT (PostgreSQL 19) |publisher=PostgreSQL Global Development Group |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| Not documented&amp;lt;ref name=&amp;quot;trinoselect&amp;quot; /&amp;gt;&lt;br /&gt;
| Yes&amp;lt;ref name=&amp;quot;duck&amp;quot; /&amp;gt;&lt;br /&gt;
| Yes&amp;lt;ref&amp;gt;{{Cite web |url=https://docs.snowflake.com/en/sql-reference/constructs/qualify |title=QUALIFY |publisher=Snowflake |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Named &amp;lt;code&amp;gt;WINDOW&amp;lt;/code&amp;gt; clause&lt;br /&gt;
| Yes&amp;lt;ref name=&amp;quot;select&amp;quot; /&amp;gt;&lt;br /&gt;
| Yes&amp;lt;ref name=&amp;quot;pgselect&amp;quot; /&amp;gt;&lt;br /&gt;
| Yes&amp;lt;ref name=&amp;quot;trinowin&amp;quot; /&amp;gt;&lt;br /&gt;
| Yes&amp;lt;ref name=&amp;quot;duck&amp;quot; /&amp;gt;&lt;br /&gt;
| Not documented&amp;lt;ref name=&amp;quot;snowwin&amp;quot; /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Not documented&amp;quot; means the cited documentation page for that engine does not describe the feature.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Lateral column alias]]&lt;br /&gt;
* [[Shuffle]]&lt;br /&gt;
* [[Partition]]&lt;br /&gt;
* [[Apache Spark]]&lt;br /&gt;
* [[DuckDB]]&lt;br /&gt;
* [[Trino]]&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;br /&gt;
[[Category:Query engines]]&lt;/div&gt;</description>
			<pubDate>Wed, 25 Nov 2026 00:53:03 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Window_functions</comments>
		</item>
		<item>
			<title>Windowing (stream processing)</title>
			<link>https://openlakehouse.io/w/index.php?title=Windowing_(stream_processing)&amp;diff=217&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Windowing_(stream_processing)&amp;diff=217&amp;oldid=0</guid>
			<description>&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            = Windowing (stream processing)&lt;br /&gt;
| also_known_as   = Time windows, windowed aggregation&lt;br /&gt;
| field           = [[Stream processing]]&lt;br /&gt;
| key_parts       = Window type (tumbling, sliding or hopping, session), window size, slide, gap, time column, [[watermark]]&lt;br /&gt;
| implementations = [[Structured Streaming]] (&amp;lt;code&amp;gt;window&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;session_window&amp;lt;/code&amp;gt;), [[Apache Flink]] (window assigners, windowing TVFs), Kafka Streams (&amp;lt;code&amp;gt;TimeWindows&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;SlidingWindows&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;SessionWindows&amp;lt;/code&amp;gt;)&lt;br /&gt;
| related         = [[Session window]], [[Event time and processing time]], [[Watermark]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the Spark 4.3.0 Structured Streaming programming guide and &amp;lt;code&amp;gt;python/pyspark/sql/functions/builtin.py&amp;lt;/code&amp;gt; at tag v4.3.0 of apache/spark, the Apache Flink 2.3 DataStream &amp;quot;Windows&amp;quot; and SQL &amp;quot;Windowing TVF&amp;quot; pages, and the Kafka Streams 4.4 DSL developer guide}}&lt;br /&gt;
&lt;br /&gt;
In [[stream processing]], &amp;#039;&amp;#039;&amp;#039;windowing&amp;#039;&amp;#039;&amp;#039; is dividing an unbounded stream into finite groups of records, usually by time, so that aggregations such as counts and averages can be computed and emitted for each group. The three common window types are &amp;#039;&amp;#039;&amp;#039;tumbling&amp;#039;&amp;#039;&amp;#039; (fixed size, no overlap), &amp;#039;&amp;#039;&amp;#039;sliding&amp;#039;&amp;#039;&amp;#039; or &amp;#039;&amp;#039;&amp;#039;hopping&amp;#039;&amp;#039;&amp;#039; (fixed size, overlapping) and &amp;#039;&amp;#039;&amp;#039;session&amp;#039;&amp;#039;&amp;#039; windows (variable size, closed by a gap of inactivity). In [[Apache Spark]] [[Structured Streaming]], a window is a grouping key built with the &amp;lt;code&amp;gt;window&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;session_window&amp;lt;/code&amp;gt; function over an [[Event time and processing time|event-time]] column, and a [[watermark]] decides when a window is complete.&amp;lt;ref name=&amp;quot;ss-apis&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#window-operations-on-event-time |title=Structured Streaming: Window Operations on Event Time (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What window types exist? ==&lt;br /&gt;
Structured Streaming supports three types of time windows: tumbling, sliding and session.&amp;lt;ref name=&amp;quot;ss-types&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#types-of-time-windows |title=Structured Streaming: Types of time windows (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A &amp;#039;&amp;#039;&amp;#039;tumbling window&amp;#039;&amp;#039;&amp;#039; is one of a series of fixed-size, non-overlapping, contiguous time intervals. Each record belongs to exactly one window.&amp;lt;ref name=&amp;quot;ss-types&amp;quot; /&amp;gt;&lt;br /&gt;
* A &amp;#039;&amp;#039;&amp;#039;sliding window&amp;#039;&amp;#039;&amp;#039; also has a fixed size, but a new window starts every &amp;#039;&amp;#039;slide&amp;#039;&amp;#039; interval. When the slide is shorter than the size, windows overlap and one record belongs to several windows.&amp;lt;ref name=&amp;quot;ss-types&amp;quot; /&amp;gt;&lt;br /&gt;
* A &amp;#039;&amp;#039;&amp;#039;session window&amp;#039;&amp;#039;&amp;#039; has no fixed size. It starts with a record and grows while further records arrive within a gap duration; it closes when no record arrives within the gap. See [[Session window]].&amp;lt;ref name=&amp;quot;ss-types&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spark&amp;#039;s guide uses the example of counting words in 10-minute windows that slide every 5 minutes: a word received at 12:07 is counted in both the 12:00 to 12:10 window and the 12:05 to 12:15 window.&amp;lt;ref name=&amp;quot;ss-apis&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does windowing work in Structured Streaming? ==&lt;br /&gt;
The &amp;lt;code&amp;gt;window(timeColumn, windowDuration, slideDuration=None, startTime=None)&amp;lt;/code&amp;gt; function, available since Spark 2.0.0, assigns each row to one or more windows. Without &amp;lt;code&amp;gt;slideDuration&amp;lt;/code&amp;gt;, the windows are tumbling; the slide must be less than or equal to the window size.&amp;lt;ref name=&amp;quot;builtin&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/sql/functions/builtin.py |title=python/pyspark/sql/functions/builtin.py (Apache Spark v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Window starts are inclusive and ends are exclusive, so 12:05 falls in &amp;lt;code&amp;gt;[12:05, 12:10)&amp;lt;/code&amp;gt; and not in &amp;lt;code&amp;gt;[12:00, 12:05)&amp;lt;/code&amp;gt;. Windows are aligned to 1970-01-01 00:00:00 UTC; &amp;lt;code&amp;gt;startTime&amp;lt;/code&amp;gt; shifts them, for example to hourly windows that start 15 minutes past the hour. Durations are fixed lengths of time, not calendar units, and windows measured in months are not supported. The result is a struct column named &amp;lt;code&amp;gt;window&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;start&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;end&amp;lt;/code&amp;gt; fields.&amp;lt;ref name=&amp;quot;builtin&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because a window is just a grouping key, a windowed aggregation is written as &amp;lt;code&amp;gt;groupBy(window(...), ...)&amp;lt;/code&amp;gt;, and the same query runs on a batch DataFrame and on a stream.&amp;lt;ref name=&amp;quot;ss-apis&amp;quot; /&amp;gt; The &amp;lt;code&amp;gt;window_time&amp;lt;/code&amp;gt; function, added in Spark 3.4.0, returns a timestamp for a window column, which lets one windowed aggregation feed another, for example 5-minute windows rolled up into 1-hour windows.&amp;lt;ref name=&amp;quot;builtin&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;ss-apis&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On a stream, a windowed aggregation keeps state for every open window. A watermark on the same event-time column lets Spark drop the state of windows that the watermark has passed; in append [[output mode]], each window is emitted once, after that point.&amp;lt;ref name=&amp;quot;ss-late&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#handling-late-data-and-watermarking |title=Structured Streaming: Handling Late Data and Watermarking (Spark 4.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;
&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;
events = spark.readStream.table(&amp;quot;main.web.page_views&amp;quot;)   # columns: ts, page&lt;br /&gt;
&lt;br /&gt;
tumbling = (events.withWatermark(&amp;quot;ts&amp;quot;, &amp;quot;10 minutes&amp;quot;)&lt;br /&gt;
            .groupBy(F.window(&amp;quot;ts&amp;quot;, &amp;quot;5 minutes&amp;quot;), &amp;quot;page&amp;quot;)&lt;br /&gt;
            .count())&lt;br /&gt;
&lt;br /&gt;
sliding = (events.withWatermark(&amp;quot;ts&amp;quot;, &amp;quot;10 minutes&amp;quot;)&lt;br /&gt;
           .groupBy(F.window(&amp;quot;ts&amp;quot;, &amp;quot;10 minutes&amp;quot;, &amp;quot;5 minutes&amp;quot;), &amp;quot;page&amp;quot;)&lt;br /&gt;
           .count())&lt;br /&gt;
&lt;br /&gt;
sessions = (events.withWatermark(&amp;quot;ts&amp;quot;, &amp;quot;10 minutes&amp;quot;)&lt;br /&gt;
            .groupBy(F.session_window(&amp;quot;ts&amp;quot;, &amp;quot;30 minutes&amp;quot;), &amp;quot;page&amp;quot;)&lt;br /&gt;
            .count())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same queries in Spark SQL use &amp;lt;code&amp;gt;window(ts, &amp;#039;5 minutes&amp;#039;)&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;session_window(ts, &amp;#039;30 minutes&amp;#039;)&amp;lt;/code&amp;gt; in the &amp;lt;code&amp;gt;GROUP BY&amp;lt;/code&amp;gt; clause.&lt;br /&gt;
&lt;br /&gt;
== Windowing in other engines ==&lt;br /&gt;
[[Apache Flink]]&amp;#039;s DataStream API defines windows with a &amp;#039;&amp;#039;&amp;#039;window assigner&amp;#039;&amp;#039;&amp;#039;. It ships assigners for tumbling, sliding, session and &amp;#039;&amp;#039;&amp;#039;global&amp;#039;&amp;#039;&amp;#039; windows; a global window puts all records of a key into one window and computes nothing unless a custom trigger is set. Tumbling and sliding assigners take an optional offset, similar to Spark&amp;#039;s &amp;lt;code&amp;gt;startTime&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;flink-win&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-release-2.3/docs/dev/datastream/operators/windows/ |title=Windows (Apache Flink 2.3) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Flink SQL uses windowing table-valued functions (TVFs): &amp;lt;code&amp;gt;TUMBLE&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;HOP&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;CUMULATE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;SESSION&amp;lt;/code&amp;gt;. Each adds &amp;lt;code&amp;gt;window_start&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;window_end&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;window_time&amp;lt;/code&amp;gt; columns, where &amp;lt;code&amp;gt;window_time&amp;lt;/code&amp;gt; equals &amp;lt;code&amp;gt;window_end&amp;lt;/code&amp;gt; minus 1 millisecond. The session TVF is supported only in streaming mode. Windowing TVFs replace the older grouped window functions.&amp;lt;ref name=&amp;quot;flink-tvf&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-release-2.3/docs/sql/reference/queries/window-tvf/ |title=Windowing table-valued functions (Apache Flink 2.3) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Kafka Streams names its window types differently. It has hopping, tumbling, sliding and session windows; hopping and tumbling windows are aligned to the epoch, with an inclusive lower bound and an exclusive upper bound. A Kafka Streams &amp;#039;&amp;#039;&amp;#039;sliding window&amp;#039;&amp;#039;&amp;#039; is not the same as a Spark sliding window: it is aligned to record timestamps, both bounds are inclusive, and it is used for joins (&amp;lt;code&amp;gt;JoinWindows&amp;lt;/code&amp;gt;) and for &amp;lt;code&amp;gt;SlidingWindows&amp;lt;/code&amp;gt; aggregations. The Kafka documentation notes that what other tools call sliding windows, Kafka Streams calls hopping windows.&amp;lt;ref name=&amp;quot;kstreams&amp;quot;&amp;gt;{{Cite web |url=https://kafka.apache.org/44/streams/developer-guide/dsl-api/ |title=Kafka Streams DSL (Apache Kafka 4.4) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Window type !! Spark Structured Streaming !! Apache Flink DataStream !! Apache Flink SQL !! Kafka Streams&lt;br /&gt;
|-&lt;br /&gt;
! Fixed, non-overlapping&lt;br /&gt;
| &amp;lt;code&amp;gt;window(ts, size)&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;builtin&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;TumblingEventTimeWindows&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;TumblingProcessingTimeWindows&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;flink-win&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;TUMBLE&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;flink-tvf&amp;quot; /&amp;gt;&lt;br /&gt;
| Tumbling time window&amp;lt;ref name=&amp;quot;kstreams&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Fixed, overlapping&lt;br /&gt;
| &amp;lt;code&amp;gt;window(ts, size, slide)&amp;lt;/code&amp;gt; (sliding)&amp;lt;ref name=&amp;quot;builtin&amp;quot; /&amp;gt;&lt;br /&gt;
| Sliding window assigners&amp;lt;ref name=&amp;quot;flink-win&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;HOP&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;flink-tvf&amp;quot; /&amp;gt;&lt;br /&gt;
| Hopping time window&amp;lt;ref name=&amp;quot;kstreams&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Gap-based&lt;br /&gt;
| &amp;lt;code&amp;gt;session_window(ts, gap)&amp;lt;/code&amp;gt;, static or per-row gap&amp;lt;ref name=&amp;quot;builtin&amp;quot; /&amp;gt;&lt;br /&gt;
| Session window assigners, static gap or &amp;lt;code&amp;gt;SessionWindowTimeGapExtractor&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;flink-win&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;SESSION&amp;lt;/code&amp;gt;, streaming only, static gap&amp;lt;ref name=&amp;quot;flink-tvf&amp;quot; /&amp;gt;&lt;br /&gt;
| Session window&amp;lt;ref name=&amp;quot;kstreams&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Other types&lt;br /&gt;
| None built in&lt;br /&gt;
| Global windows with a custom trigger&amp;lt;ref name=&amp;quot;flink-win&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;CUMULATE&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;flink-tvf&amp;quot; /&amp;gt;&lt;br /&gt;
| Sliding windows based on record time differences&amp;lt;ref name=&amp;quot;kstreams&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Window bounds&lt;br /&gt;
| Start inclusive, end exclusive, aligned to the Unix epoch with an optional &amp;lt;code&amp;gt;startTime&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;builtin&amp;quot; /&amp;gt;&lt;br /&gt;
| Aligned to the epoch, optional offset&amp;lt;ref name=&amp;quot;flink-win&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;window_start&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;window_end&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;window_time&amp;lt;/code&amp;gt; columns&amp;lt;ref name=&amp;quot;flink-tvf&amp;quot; /&amp;gt;&lt;br /&gt;
| Hopping and tumbling aligned to the epoch; sliding aligned to records&amp;lt;ref name=&amp;quot;kstreams&amp;quot; /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Session window]]&lt;br /&gt;
* [[Watermark]]&lt;br /&gt;
* [[Event time and processing time]]&lt;br /&gt;
* [[Output mode]]&lt;br /&gt;
* [[Stateful stream processing]]&lt;br /&gt;
* [[Stream processing]]&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:Pipelines and orchestration]]&lt;/div&gt;</description>
			<pubDate>Wed, 25 Nov 2026 00:53:03 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Windowing_(stream_processing)</comments>
		</item>
		<item>
			<title>User-defined function (Spark)</title>
			<link>https://openlakehouse.io/w/index.php?title=User-defined_function_(Spark)&amp;diff=213&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=User-defined_function_(Spark)&amp;diff=213&amp;oldid=0</guid>
			<description>&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            = User-defined function (Spark)&lt;br /&gt;
| also_known_as   = UDF, Spark UDF, PySpark UDF&lt;br /&gt;
| field           = Distributed data processing&lt;br /&gt;
| introduced      = Python UDFs since Spark 1.3.0 (&amp;lt;code&amp;gt;pyspark.sql.functions.udf&amp;lt;/code&amp;gt;)&lt;br /&gt;
| key_parts       = Function body, return type, evaluation type (JVM, pickled Python, Arrow-optimized Python, pandas, Arrow)&lt;br /&gt;
| implementations = [[Apache Spark]]&lt;br /&gt;
| related         = [[Pandas UDF]], [[Arrow-optimized Python UDF]], [[Python UDTF]], [[Apache Arrow]], [[Spark Connect]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (python/pyspark/sql/functions/builtin.py, python/pyspark/sql/pandas/functions.py, SQLConf.scala, the PySpark Arrow, Arrow UDF and UDF user guides, the PySpark migration guide, docs/sql-ref-functions-udf-scalar.md, docs/sql-ref-syntax-ddl-create-sql-function.md), the Spark 2.3.0, 3.5.0, 4.1.0, 4.2.0 and 4.3.0 release notes, and two Databricks engineering blog posts}}&lt;br /&gt;
&lt;br /&gt;
In [[Apache Spark]], a &amp;#039;&amp;#039;&amp;#039;user-defined function&amp;#039;&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;UDF&amp;#039;&amp;#039;&amp;#039;) is a function written by the user in Scala, Java, Python or SQL and registered with Spark so that it can be called on columns of a [[DataFrame]] or in a Spark SQL query, like a built-in function.&amp;lt;ref name=&amp;quot;scalar&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-ref-functions-udf-scalar.html |title=Scalar User Defined Functions (UDFs) (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; A scalar UDF acts on one row and returns one value.&amp;lt;ref name=&amp;quot;scalar&amp;quot; /&amp;gt; PySpark offers several kinds of Python UDF that differ in how data moves between the Java virtual machine (JVM) and the Python worker: pickled Python UDFs, [[Arrow-optimized Python UDF|Arrow-optimized Python UDFs]], [[Pandas UDF|pandas UDFs]] and Arrow UDFs. The choice decides how much serialization overhead each call pays.&amp;lt;ref name=&amp;quot;guide&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/api/python/user_guide/udfandudtf.html |title=Chapter 5: Unleashing UDFs &amp;amp; UDTFs (PySpark 4.3.0 user guide) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What kinds of UDF does Spark support? ==&lt;br /&gt;
The PySpark user guide for Spark 4.3.0 names three main categories of Python UDF: scalar Python UDFs, pandas UDFs and Arrow UDFs.&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Scalar Python UDFs&amp;#039;&amp;#039;&amp;#039; take and return Python objects one row at a time. The objects are serialized with pickle (through cloudpickle) or with [[Apache Arrow]].&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Pandas UDFs&amp;#039;&amp;#039;&amp;#039;, also called vectorized UDFs, take and return pandas &amp;lt;code&amp;gt;Series&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;DataFrame&amp;lt;/code&amp;gt; objects and work on a batch of rows at a time; Arrow carries the data.&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Arrow UDFs&amp;#039;&amp;#039;&amp;#039; take and return &amp;lt;code&amp;gt;pyarrow.Array&amp;lt;/code&amp;gt; objects (or iterators of them) directly, without converting to pandas.&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;arrowudf&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/api/python/tutorial/sql/arrow_python_udf.html |title=Arrow Python UDFs (PySpark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
JVM UDFs are written in Scala or Java with &amp;lt;code&amp;gt;udf(...)&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spark.udf.register&amp;lt;/code&amp;gt;, and the class &amp;lt;code&amp;gt;UserDefinedFunction&amp;lt;/code&amp;gt; provides &amp;lt;code&amp;gt;asNonNullable&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;asNondeterministic&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;withName&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;scalar&amp;quot; /&amp;gt; Spark SQL also has SQL UDFs, created with &amp;lt;code&amp;gt;CREATE FUNCTION ... RETURN&amp;lt;/code&amp;gt;, whose body is a SQL expression or query and which can return a scalar or a table.&amp;lt;ref name=&amp;quot;sqlfn&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-ref-syntax-ddl-create-sql-function.html |title=CREATE FUNCTION (SQL) (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Functions that return a table from Python are [[Python UDTF|Python user-defined table functions]].&lt;br /&gt;
&lt;br /&gt;
== Spark UDF types compared ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! !! JVM UDF (Scala/Java) !! Pickled Python UDF !! Arrow-optimized Python UDF !! Pandas UDF !! Arrow UDF&lt;br /&gt;
|-&lt;br /&gt;
! How it is defined&lt;br /&gt;
| &amp;lt;code&amp;gt;udf(...)&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spark.udf.register&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;scalar&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;@udf(..., useArrow=False)&amp;lt;/code&amp;gt; or with &amp;lt;code&amp;gt;spark.sql.execution.pythonUDF.arrow.enabled=false&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;upgrade&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;@udf&amp;lt;/code&amp;gt; (default since Spark 4.2) or &amp;lt;code&amp;gt;useArrow=True&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;upgrade&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;@pandas_udf&amp;lt;/code&amp;gt; with pandas type hints&amp;lt;ref name=&amp;quot;arrowpandas&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;@arrow_udf&amp;lt;/code&amp;gt;, or &amp;lt;code&amp;gt;@udf&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;pyarrow.Array&amp;lt;/code&amp;gt; type hints&amp;lt;ref name=&amp;quot;arrowudf&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Where the code runs&lt;br /&gt;
| Inside the executor JVM&lt;br /&gt;
| Python worker process&lt;br /&gt;
| Python worker process&lt;br /&gt;
| Python worker process&lt;br /&gt;
| Python worker process&lt;br /&gt;
|-&lt;br /&gt;
! Unit of work for the function&lt;br /&gt;
| One row&lt;br /&gt;
| One row&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&lt;br /&gt;
| One row; data moves in Arrow batches&amp;lt;ref name=&amp;quot;arrowpandas&amp;quot; /&amp;gt;&lt;br /&gt;
| A batch, as pandas &amp;lt;code&amp;gt;Series&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;DataFrame&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&lt;br /&gt;
| A batch, as &amp;lt;code&amp;gt;pyarrow.Array&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;arrowudf&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! JVM to Python serialization&lt;br /&gt;
| None&lt;br /&gt;
| Pickle (cloudpickle)&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&lt;br /&gt;
| Arrow&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&lt;br /&gt;
| Arrow&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&lt;br /&gt;
| Arrow, with no pandas conversion&amp;lt;ref name=&amp;quot;arrowudf&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Available since&lt;br /&gt;
| Spark 1.3.0 (&amp;lt;code&amp;gt;functions.udf&amp;lt;/code&amp;gt; in Scala)&amp;lt;ref name=&amp;quot;scalafn&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/functions.scala |title=sql/api/src/main/scala/org/apache/spark/sql/functions.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| Spark 1.3.0&amp;lt;ref name=&amp;quot;udfapi&amp;quot; /&amp;gt;&lt;br /&gt;
| Spark 3.5.0 (SPARK-40307); default in 4.2.0&amp;lt;ref name=&amp;quot;r350&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;r420&amp;quot; /&amp;gt;&lt;br /&gt;
| Spark 2.3.0&amp;lt;ref name=&amp;quot;pandasapi&amp;quot; /&amp;gt;&lt;br /&gt;
| Spark 4.1.0 (SPARK-52214)&amp;lt;ref name=&amp;quot;r410&amp;quot; /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Which UDF type is fastest? ==&lt;br /&gt;
The performance tiers follow from how much work each call spends moving data between the JVM and Python. A JVM UDF runs in the executor JVM and needs no transfer to Python. Every Python UDF runs in a separate Python worker process, so its input and output must cross from the JVM to Python and back; PySpark uses Arrow to make that transfer efficient.&amp;lt;ref name=&amp;quot;arrowpandas&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/api/python/tutorial/sql/arrow_pandas.html |title=Apache Arrow in PySpark (PySpark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Among Python UDFs, pickled UDFs pay the most serialization overhead. The PySpark user guide says they rely on cloudpickle and meet performance bottlenecks with large inputs and outputs.&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt; When Databricks engineers introduced pandas UDFs for Spark 2.3 in 2017, they wrote that row-at-a-time Python UDFs &amp;quot;suffer from high serialization and invocation overhead&amp;quot;, which led many pipelines to write UDFs in Java or Scala and call them from Python; their benchmark found pandas UDFs 3 to over 100 times faster than row-at-a-time UDFs.&amp;lt;ref name=&amp;quot;blog2017&amp;quot;&amp;gt;{{Cite web |url=https://www.databricks.com/blog/2017/10/30/introducing-vectorized-udfs-for-pyspark.html |title=Introducing Pandas UDF for PySpark |publisher=Databricks |date=2017-10-30 |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Arrow-optimized Python UDFs keep the row-at-a-time function but replace pickle with Arrow for the transfer. In a Databricks benchmark for Spark 3.5, an Arrow-optimized Python UDF ran about 1.6 times faster than a pickled UDF on one transformation, and about 1.9 times faster when UDFs were chained, on a 32 GB dataset.&amp;lt;ref name=&amp;quot;blog2023&amp;quot;&amp;gt;{{Cite web |url=https://www.databricks.com/blog/arrow-optimized-python-udfs-apache-sparktm-35 |title=Arrow-optimized Python UDFs in Apache Spark 3.5 |publisher=Databricks |date=2023-11-06 |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; These are measured results for one cluster and dataset, not general guarantees.&lt;br /&gt;
&lt;br /&gt;
Pandas UDFs and Arrow UDFs are vectorized: the function receives a whole batch, so library code (pandas or PyArrow compute functions) can process many rows per call. Arrow UDFs keep the columnar layout end to end and avoid the extra copies of a pandas conversion.&amp;lt;ref name=&amp;quot;arrowudf&amp;quot; /&amp;gt; The batch size for Arrow transfers is &amp;lt;code&amp;gt;spark.sql.execution.arrow.maxRecordsPerBatch&amp;lt;/code&amp;gt;, default 10,000 rows.&amp;lt;ref name=&amp;quot;arrowpandas&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A Python UDF is opaque to the Spark optimizer. Spark 4.3.0 adds an experimental option, &amp;lt;code&amp;gt;spark.sql.experimental.optimizer.transpilePyUDFs&amp;lt;/code&amp;gt; (default &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt;), that tries to rewrite simple Python UDFs as Catalyst expressions; it requires ANSI mode and does not yet work with [[Spark Connect]].&amp;lt;ref name=&amp;quot;sqlconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala |title=SQLConf.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;r430&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4-3-0.html |title=Spark Release 4.3.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How to write a UDF in PySpark ==&lt;br /&gt;
The following PySpark example defines the same string function three ways. It runs on Spark 4.3.0 with PyArrow installed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import pandas as pd&lt;br /&gt;
import pyarrow as pa&lt;br /&gt;
import pyarrow.compute as pc&lt;br /&gt;
from pyspark.sql.functions import udf, pandas_udf, arrow_udf&lt;br /&gt;
&lt;br /&gt;
# Scalar Python UDF: one row per call (Arrow-optimized by default since Spark 4.2)&lt;br /&gt;
@udf(returnType=&amp;quot;int&amp;quot;)&lt;br /&gt;
def slen(s: str) -&amp;gt; int:&lt;br /&gt;
    return len(s)&lt;br /&gt;
&lt;br /&gt;
# Pandas UDF: one pandas Series per batch&lt;br /&gt;
@pandas_udf(&amp;quot;string&amp;quot;)&lt;br /&gt;
def upper_pd(s: pd.Series) -&amp;gt; pd.Series:&lt;br /&gt;
    return s.str.upper()&lt;br /&gt;
&lt;br /&gt;
# Arrow UDF: one pyarrow.Array per batch&lt;br /&gt;
@arrow_udf(&amp;quot;string&amp;quot;)&lt;br /&gt;
def upper_pa(s: pa.Array) -&amp;gt; pa.Array:&lt;br /&gt;
    return pc.ascii_upper(s)&lt;br /&gt;
&lt;br /&gt;
df = spark.createDataFrame([(&amp;quot;John Doe&amp;quot;,)], [&amp;quot;name&amp;quot;])&lt;br /&gt;
df.select(slen(&amp;quot;name&amp;quot;), upper_pd(&amp;quot;name&amp;quot;), upper_pa(&amp;quot;name&amp;quot;)).show()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A Python UDF can be registered for SQL with &amp;lt;code&amp;gt;spark.udf.register(&amp;quot;slen&amp;quot;, slen)&amp;lt;/code&amp;gt; and then called as &amp;lt;code&amp;gt;SELECT slen(name) FROM t&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;udfapi&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/sql/functions/builtin.py |title=python/pyspark/sql/functions/builtin.py (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What changed in Spark 4.x? ==&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Spark 4.0.0&amp;#039;&amp;#039;&amp;#039; added keyword arguments for Python UDFs.&amp;lt;ref name=&amp;quot;udfapi&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Spark 4.1.0&amp;#039;&amp;#039;&amp;#039; added Arrow UDFs (&amp;lt;code&amp;gt;arrow_udf&amp;lt;/code&amp;gt;, SPARK-52214) and Arrow UDTFs (&amp;lt;code&amp;gt;arrow_udtf&amp;lt;/code&amp;gt;, SPARK-52979). From 4.1.0, &amp;lt;code&amp;gt;udf&amp;lt;/code&amp;gt; also creates a vectorized UDF when the type hints match a pandas UDF or Arrow UDF pattern and &amp;lt;code&amp;gt;useArrow&amp;lt;/code&amp;gt; is not set.&amp;lt;ref name=&amp;quot;r410&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4.1.0.html |title=Spark Release 4.1.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;udfapi&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Spark 4.2.0&amp;#039;&amp;#039;&amp;#039; made regular Python UDFs Arrow-optimized by default: &amp;lt;code&amp;gt;spark.sql.execution.pythonUDF.arrow.enabled&amp;lt;/code&amp;gt; now defaults to &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; (SPARK-54555). Setting it to &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt; restores pickled UDFs.&amp;lt;ref name=&amp;quot;upgrade&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/api/python/migration_guide/pyspark_upgrade.html |title=Upgrading PySpark (PySpark 4.3.0 migration guide) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;r420&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4-2-0.html |title=Spark Release 4.2.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The pandas UDF API dates from Spark 2.3.0.&amp;lt;ref name=&amp;quot;pandasapi&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/sql/pandas/functions.py |title=python/pyspark/sql/pandas/functions.py (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Arrow-optimized Python UDFs were introduced in Spark 3.5.0.&amp;lt;ref name=&amp;quot;r350&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-3-5-0.html |title=Spark Release 3.5.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Limitations ==&lt;br /&gt;
SQL boolean expressions do not short-circuit around a UDF: in &amp;lt;code&amp;gt;WHERE cond AND udf(x)&amp;lt;/code&amp;gt; the UDF may be called on every row regardless of &amp;lt;code&amp;gt;cond&amp;lt;/code&amp;gt;, so a UDF that can fail on some inputs must handle them itself.&amp;lt;ref name=&amp;quot;arrowudf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Pandas UDF]]&lt;br /&gt;
* [[Arrow-optimized Python UDF]]&lt;br /&gt;
* [[Python UDTF]]&lt;br /&gt;
* [[Python data source API (Spark)]]&lt;br /&gt;
* [[Apache Arrow]]&lt;br /&gt;
* [[Spark Connect]]&lt;br /&gt;
* [[Encoder (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;</description>
			<pubDate>Wed, 25 Nov 2026 00:53:02 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:User-defined_function_(Spark)</comments>
		</item>
		<item>
			<title>Velox</title>
			<link>https://openlakehouse.io/w/index.php?title=Velox&amp;diff=214&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Velox&amp;diff=214&amp;oldid=0</guid>
			<description>&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 software&lt;br /&gt;
| name                = Velox&lt;br /&gt;
| developer           = Meta, with contributors from other companies&lt;br /&gt;
| initial_release     = 2021 (GitHub repository created)&lt;br /&gt;
| written_in          = C++&lt;br /&gt;
| type                = Execution engine library&lt;br /&gt;
| license             = Apache License 2.0&lt;br /&gt;
| website             = [https://velox-lib.io velox-lib.io]&lt;br /&gt;
| repo                = [https://github.com/facebookincubator/velox github.com/facebookincubator/velox]&lt;br /&gt;
| related             = [[Apache Gluten]], [[Apache Spark]], [[Native execution engine (Spark)]], [[Apache DataFusion Comet]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the facebookincubator/velox README, LICENSE, repository metadata and tags, the VLDB 2022 Velox paper, Meta&amp;#039;s &amp;quot;Introducing Velox&amp;quot; post, the apache/gluten README (main and v1.7.0) and Velox getting-started guide at v1.7.0, and the prestodb/presto presto-native-execution README}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Velox&amp;#039;&amp;#039;&amp;#039; is an open source C++ library that provides the execution layer of a data processing engine: columnar vectors, vectorized expression evaluation, functions and relational operators, which other systems embed instead of writing their own.&amp;lt;ref name=&amp;quot;readme&amp;quot;&amp;gt;{{Cite web |url=https://github.com/facebookincubator/velox/blob/main/README.md |title=Velox README |publisher=GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Meta created Velox, and it is developed with IBM/Ahana, Intel, Voltron Data, Microsoft, ByteDance and other companies under the Apache License 2.0.&amp;lt;ref name=&amp;quot;readme&amp;quot; /&amp;gt; For [[Apache Spark]], Velox is one of the two native backends of [[Apache Gluten]], a plugin that offloads Spark SQL execution from the JVM to native code.&amp;lt;ref name=&amp;quot;gluten&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/gluten/blob/v1.7.0/README.md |title=Apache Gluten README (v1.7.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What does Velox provide? ==&lt;br /&gt;
Velox takes a fully optimized query plan as input and runs it. It does not include a SQL parser, a DataFrame layer or a query optimizer, so it is meant for developers who build or speed up engines, not for end users.&amp;lt;ref name=&amp;quot;readme&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Velox README lists these components:&amp;lt;ref name=&amp;quot;readme&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Type&amp;#039;&amp;#039;&amp;#039;: a type system with scalar, complex and nested types such as structs, maps and arrays.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Vector&amp;#039;&amp;#039;&amp;#039;: an Arrow-compatible columnar memory layout with flat, dictionary, constant and sequence (run-length) encodings, lazy materialization and out-of-order writes.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Expression evaluation&amp;#039;&amp;#039;&amp;#039;: a vectorized engine that evaluates expressions on vector-encoded data.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Functions&amp;#039;&amp;#039;&amp;#039;: vectorized scalar, aggregate and window functions that follow Presto and Spark semantics.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Operators&amp;#039;&amp;#039;&amp;#039;: scans, writes, projections, filters, grouping, ordering, shuffle and exchange, hash, merge and nested loop joins, unnest and others.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;I/O&amp;#039;&amp;#039;&amp;#039;: a connector interface for data sources and sinks, with ORC/DWRF, Parquet and Nimble file formats and storage adapters for S3, HDFS, GCS, ABFS and local files.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Network serializers&amp;#039;&amp;#039;&amp;#039;: wire formats including PrestoPage and Spark&amp;#039;s UnsafeRow.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Resource management&amp;#039;&amp;#039;&amp;#039;: memory arenas, buffer management, tasks, drivers, thread pools, spilling and caching.&lt;br /&gt;
&lt;br /&gt;
The Velox source tree keeps Spark and Presto function sets in separate directories, &amp;lt;code&amp;gt;velox/functions/sparksql&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;velox/functions/prestosql&amp;lt;/code&amp;gt;, so that each engine gets its own SQL dialect behavior.&amp;lt;ref name=&amp;quot;funcs&amp;quot;&amp;gt;{{Cite web |url=https://github.com/facebookincubator/velox/tree/main/velox/functions |title=velox/functions |publisher=GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Developers can add their own types, functions, operators, file formats, storage adapters and serializers.&amp;lt;ref name=&amp;quot;readme&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How is Velox used with Apache Spark? ==&lt;br /&gt;
Velox runs Spark SQL through Apache Gluten. Gluten converts Spark&amp;#039;s physical plan into a Substrait plan, passes it over JNI to a native backend, which builds and runs native operators, and returns results to Spark as columnar batches. Operators that the backend does not support fall back to vanilla Spark, with columnar-to-row and row-to-columnar conversions between them.&amp;lt;ref name=&amp;quot;gluten&amp;quot; /&amp;gt; Gluten v1.7.0 supports two backends, ClickHouse and Velox, and Spark 3.3, 3.4, 3.5, 4.0 and 4.1.&amp;lt;ref name=&amp;quot;gluten&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A Spark application turns on the Gluten Velox backend with the Gluten plugin, off-heap memory and Gluten&amp;#039;s columnar shuffle manager. The configuration below is taken from the Gluten v1.7.0 Velox guide; the off-heap size is an example value.&amp;lt;ref name=&amp;quot;glutenvelox&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/gluten/blob/v1.7.0/docs/get-started/Velox.md |title=Gluten Velox backend getting started (v1.7.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;text&amp;quot;&amp;gt;&lt;br /&gt;
spark.plugins            org.apache.gluten.GlutenPlugin&lt;br /&gt;
spark.memory.offHeap.enabled  true&lt;br /&gt;
spark.memory.offHeap.size     20g&lt;br /&gt;
spark.shuffle.manager    org.apache.spark.shuffle.sort.ColumnarShuffleManager&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Gluten&amp;#039;s main branch also documents an experimental GPU mode in which Velox plan nodes are replaced by operators built on NVIDIA cuDF; see [[GPU acceleration in Spark]].&amp;lt;ref name=&amp;quot;glutengpu&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/gluten/blob/main/docs/backends/velox/get-started/VeloxGPU.md |title=GPU Acceleration in Velox/Gluten (VeloxGPU.md, main branch) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; For other native engines for Spark, such as [[Apache DataFusion Comet]], see [[Native execution engine (Spark)]].&lt;br /&gt;
&lt;br /&gt;
== Which other engines use Velox? ==&lt;br /&gt;
Prestissimo, the native worker of Presto in the &amp;lt;code&amp;gt;presto-native-execution&amp;lt;/code&amp;gt; directory of the prestodb/presto repository, implements the Presto worker REST API in C++ on top of Velox.&amp;lt;ref name=&amp;quot;prestissimo&amp;quot;&amp;gt;{{Cite web |url=https://github.com/prestodb/presto/blob/master/presto-native-execution/README.md |title=Prestissimo: C++ Presto Worker Implementation using Velox |publisher=GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Meta&amp;#039;s March 2023 post describes Prestissimo as replacing Presto Java workers with a Velox-based C++ process, and names Spark (through Gluten) and TorchArrow, a PyTorch data preprocessing library, as the other main integrations at the time.&amp;lt;ref name=&amp;quot;meta&amp;quot;&amp;gt;{{Cite web |url=https://engineering.fb.com/2023/03/09/open-source/velox-open-source-execution-engine/ |title=Introducing Velox: An open source unified execution engine |publisher=Meta |date=2023-03-09 |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What is the history of Velox? ==&lt;br /&gt;
The facebookincubator/velox repository on GitHub was created on 23 July 2021.&amp;lt;ref name=&amp;quot;repo&amp;quot;&amp;gt;{{Cite web |url=https://github.com/facebookincubator/velox |title=facebookincubator/velox |publisher=GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Meta engineers described the design in the paper &amp;quot;Velox: Meta&amp;#039;s Unified Execution Engine&amp;quot;, published in the Proceedings of the VLDB Endowment, volume 15 (2022).&amp;lt;ref name=&amp;quot;paper&amp;quot;&amp;gt;{{Cite web |url=https://www.vldb.org/pvldb/vol15/p3372-pedreira.pdf |title=Velox: Meta&amp;#039;s Unified Execution Engine |publisher=VLDB Endowment |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Meta&amp;#039;s 2023 post states that Velox was already being integrated with more than a dozen data systems at Meta, including Presto and Spark.&amp;lt;ref name=&amp;quot;meta&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Velox does not publish GitHub releases with version numbers; its repository uses date-based tags such as &amp;lt;code&amp;gt;v2026.10.23.00&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;tags&amp;quot;&amp;gt;{{Cite web |url=https://github.com/facebookincubator/velox/tags |title=Tags, facebookincubator/velox |publisher=GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Velox requires at least GCC 11 or Clang 15 to build.&amp;lt;ref name=&amp;quot;readme&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does Velox differ from a query engine? ==&lt;br /&gt;
Velox is a library, not a complete query engine. A system such as Spark or Presto keeps its own SQL parsing, optimization, scheduling and cluster management, and hands Velox the plan fragment to run on one machine.&amp;lt;ref name=&amp;quot;readme&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;meta&amp;quot; /&amp;gt; Without a plugin such as Gluten, Spark runs plans on its own JVM execution layer, described in [[Project Tungsten]].&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Apache Gluten]]&lt;br /&gt;
* [[Native execution engine (Spark)]]&lt;br /&gt;
* [[Apache DataFusion Comet]]&lt;br /&gt;
* [[GPU acceleration in Spark]]&lt;br /&gt;
* [[Project Tungsten]]&lt;br /&gt;
* [[Apache 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:Query engines]]&lt;br /&gt;
[[Category:Apache Spark]]&lt;/div&gt;</description>
			<pubDate>Wed, 25 Nov 2026 00:53:02 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Velox</comments>
		</item>
		<item>
			<title>Whole-stage code generation</title>
			<link>https://openlakehouse.io/w/index.php?title=Whole-stage_code_generation&amp;diff=215&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Whole-stage_code_generation&amp;diff=215&amp;oldid=0</guid>
			<description>&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            = Whole-stage code generation&lt;br /&gt;
| also_known_as   = WholeStageCodegen, whole-stage codegen, WSCG&lt;br /&gt;
| field           = Query execution performance&lt;br /&gt;
| introduced      = Apache Spark 2.0.0 (SPARK-12795)&lt;br /&gt;
| key_parts       = &amp;lt;code&amp;gt;WholeStageCodegenExec&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;CollapseCodegenStages&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;InputAdapter&amp;lt;/code&amp;gt;, codegen stage ID, Java source compiler (Janino by default)&lt;br /&gt;
| implementations = [[Apache Spark]]&lt;br /&gt;
| related         = [[Project Tungsten]], [[Catalyst optimizer]], [[Logical plan and physical plan]], [[Job, stage and task]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the Spark 2.0.0 release notes, SPARK-12795, the 2016 Databricks engineering post on whole-stage code generation, the v4.3.0 tag of apache/spark (WholeStageCodegenExec.scala, SQLConf.scala, docs/sql-ref-syntax-qry-explain.md, docs/web-ui.md) and EXPLAIN and EXPLAIN CODEGEN output from a PySpark 4.3.0 run}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Whole-stage code generation&amp;#039;&amp;#039;&amp;#039; is the technique by which [[Apache Spark]] compiles a chain of physical operators, such as a scan, a filter, a projection and a partial aggregation, into a single generated Java function at run time.&amp;lt;ref name=&amp;quot;wscg&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/WholeStageCodegenExec.scala |title=WholeStageCodegenExec.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;sqlconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala |title=SQLConf.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; It shipped in Spark 2.0.0, whose release notes credit it with 2 to 10 times speedups for common SQL and DataFrame operators, and it is part of the work known as [[Project Tungsten]].&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;&amp;lt;ref name=&amp;quot;jira&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-12795 |title=SPARK-12795: Whole stage codegen |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; It is on by default in Spark 4.3.0 and applies to DataFrame, Dataset and SQL queries.&lt;br /&gt;
&lt;br /&gt;
== Why does Spark generate code? ==&lt;br /&gt;
Before whole-stage code generation, Spark ran each physical operator as an iterator that pulls rows from its child, the &amp;quot;Volcano&amp;quot; model used by many databases. Spark developers Sameer Agarwal, Davies Liu and Reynold Xin explained in a 2016 Databricks post that each such call is a virtual function dispatch and keeps the row in memory. Collapsing a fragment of the query into one function eliminates those calls and lets the JVM JIT compiler keep intermediate data in CPU registers, close to what hand-written code would do.&amp;lt;ref name=&amp;quot;blog2016&amp;quot;&amp;gt;{{Cite web |url=https://www.databricks.com/blog/2016/05/23/apache-spark-as-a-compiler-joining-a-billion-rows-per-second-on-a-laptop.html |title=Apache Spark as a Compiler: Joining a Billion Rows per Second on a Laptop |publisher=Databricks |date=2016-05-23 |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spark turns the generated Java source into bytecode at run time. Spark 4.3.0 added an internal setting, &amp;lt;code&amp;gt;spark.sql.codegen.compiler&amp;lt;/code&amp;gt;, with the values &amp;lt;code&amp;gt;janino&amp;lt;/code&amp;gt; (the Janino library, the default) and &amp;lt;code&amp;gt;jdk&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;javax.tools.JavaCompiler&amp;lt;/code&amp;gt;); its documentation says Janino is several times faster and remains the better choice for most workloads.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What do WholeStageCodegen nodes mean in a plan? ==&lt;br /&gt;
In a physical plan printed by &amp;lt;code&amp;gt;EXPLAIN&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;df.explain()&amp;lt;/code&amp;gt;, an operator that is part of a generated function is prefixed with &amp;lt;code&amp;gt;*(n)&amp;lt;/code&amp;gt;. The number &amp;#039;&amp;#039;n&amp;#039;&amp;#039; is the &amp;#039;&amp;#039;&amp;#039;codegen stage ID&amp;#039;&amp;#039;&amp;#039;: all operators with the same ID are fused into one generated function. IDs start at 1 in each query and are assigned in depth-first post-order, so not all neighbouring operators with a star share an ID.&amp;lt;ref name=&amp;quot;wscg&amp;quot; /&amp;gt; In &amp;lt;code&amp;gt;EXPLAIN FORMATTED&amp;lt;/code&amp;gt; the same information appears as &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; in the outline and &amp;lt;code&amp;gt;[codegen id : n]&amp;lt;/code&amp;gt; in each node&amp;#039;s details.&amp;lt;ref name=&amp;quot;explain&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-ref-syntax-qry-explain.html |title=EXPLAIN (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This sort-merge join plan from PySpark 4.3.0 (with [[Adaptive Query Execution]] and broadcast joins turned off; plan IDs removed) has five codegen stages:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
*(5) Project [k#9L]&lt;br /&gt;
+- *(5) SortMergeJoin [k#9L], [k#11L], Inner&lt;br /&gt;
   :- *(2) Sort [k#9L ASC NULLS FIRST], false, 0&lt;br /&gt;
   :  +- Exchange hashpartitioning(k#9L, 200), ENSURE_REQUIREMENTS&lt;br /&gt;
   :     +- *(1) Project [id#8L AS k#9L]&lt;br /&gt;
   :        +- *(1) Range (0, 1000000, step=1, splits=2)&lt;br /&gt;
   +- *(4) Sort [k#11L ASC NULLS FIRST], false, 0&lt;br /&gt;
      +- Exchange hashpartitioning(k#11L, 200), ENSURE_REQUIREMENTS&lt;br /&gt;
         +- *(3) Project [id#10L AS k#11L]&lt;br /&gt;
            +- *(3) Range (0, 100, step=1, splits=2)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
How to read it:&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Operators without a star are not generated.&amp;#039;&amp;#039;&amp;#039; &amp;lt;code&amp;gt;Exchange&amp;lt;/code&amp;gt; is a [[shuffle]] boundary and is never part of a generated function. The generated code of stage 1 ends where it writes rows to the shuffle.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;An &amp;lt;code&amp;gt;InputAdapter&amp;lt;/code&amp;gt; is hidden.&amp;#039;&amp;#039;&amp;#039; Where a generated stage reads from an operator that does not support code generation, Spark inserts an &amp;lt;code&amp;gt;InputAdapter&amp;lt;/code&amp;gt;, which feeds rows from that operator into the generated code. In Spark 4.3.0 it is not printed in the tree.&amp;lt;ref name=&amp;quot;wscg&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Codegen stages are not Spark stages.&amp;#039;&amp;#039;&amp;#039; A [[Job, stage and task|scheduler stage]] is bounded by shuffles; one scheduler stage can contain several codegen stages. Above, codegen stages 2, 4 and 5 all run in the final scheduler stage, after both shuffles.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Before AQE runs, stars are missing.&amp;#039;&amp;#039;&amp;#039; With [[Adaptive Query Execution]] on (the default), the plan printed before execution starts with &amp;lt;code&amp;gt;AdaptiveSparkPlan isFinalPlan=false&amp;lt;/code&amp;gt; and shows no &amp;lt;code&amp;gt;*(n)&amp;lt;/code&amp;gt; prefixes; they appear in the final plan printed after an action.&lt;br /&gt;
&lt;br /&gt;
The Spark web UI uses the same IDs. Stage DAGs group nodes under &amp;lt;code&amp;gt;WholeStageCodegen&amp;lt;/code&amp;gt; boxes annotated with the codegen ID, which links a stage to the query in the SQL tab.&amp;lt;ref name=&amp;quot;webui&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/web-ui.html |title=Web UI (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 do you see the generated code? ==&lt;br /&gt;
&amp;lt;code&amp;gt;EXPLAIN CODEGEN&amp;lt;/code&amp;gt; (or &amp;lt;code&amp;gt;df.explain(mode=&amp;quot;codegen&amp;quot;)&amp;lt;/code&amp;gt;) prints the physical plan and the generated Java source of each stage.&amp;lt;ref name=&amp;quot;explain&amp;quot; /&amp;gt; Each subtree comes with statistics on the compiled code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
EXPLAIN CODEGEN SELECT sum(id) FROM range(10) WHERE id &amp;gt; 2;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
Found 2 WholeStageCodegen subtrees.&lt;br /&gt;
== Subtree 1 / 2 (maxMethodCodeSize:282; maxConstantPoolSize:217(0.33% used); numInnerClasses:0) ==&lt;br /&gt;
*(1) HashAggregate(keys=[], functions=[partial_sum(id#4360L)], ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;maxMethodCodeSize&amp;lt;/code&amp;gt; is the largest compiled method in bytes of bytecode. It matters because of the fallback rule for huge methods described below.&lt;br /&gt;
&lt;br /&gt;
== When does whole-stage code generation fall back? ==&lt;br /&gt;
Spark falls back to the interpreted, operator-at-a-time path for part of a plan in these cases, all defined in the Spark 4.3.0 source:&amp;lt;ref name=&amp;quot;wscg&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Case !! Effect !! Setting (default)&lt;br /&gt;
|-&lt;br /&gt;
| The operator does not implement code generation, for example the Python UDF operator &amp;lt;code&amp;gt;BatchEvalPython&amp;lt;/code&amp;gt; || The operator runs without a star; an &amp;lt;code&amp;gt;InputAdapter&amp;lt;/code&amp;gt; connects it to generated neighbours || (none)&lt;br /&gt;
|-&lt;br /&gt;
| An expression in the operator only supports interpreted evaluation (&amp;lt;code&amp;gt;CodegenFallback&amp;lt;/code&amp;gt;) || The whole operator is left out of code generation || (none)&lt;br /&gt;
|-&lt;br /&gt;
| The operator&amp;#039;s input or output schema has more fields, counting nested fields, than the limit || The operator is left out of code generation || &amp;lt;code&amp;gt;spark.sql.codegen.maxFields&amp;lt;/code&amp;gt; (100)&lt;br /&gt;
|-&lt;br /&gt;
| The generated Java code fails to compile || A warning &amp;quot;Whole-stage codegen disabled for plan (id=n)&amp;quot; is logged and the subtree runs interpreted || &amp;lt;code&amp;gt;spark.sql.codegen.fallback&amp;lt;/code&amp;gt; (true)&lt;br /&gt;
|-&lt;br /&gt;
| A compiled method is larger than the limit in bytecode || An info message &amp;quot;Found too long generated codes and JIT optimization might not work&amp;quot; is logged and the subtree runs interpreted || &amp;lt;code&amp;gt;spark.sql.codegen.hugeMethodLimit&amp;lt;/code&amp;gt; (65535)&lt;br /&gt;
|-&lt;br /&gt;
| Code generation is turned off || No whole-stage code generation at all || &amp;lt;code&amp;gt;spark.sql.codegen.wholeStage&amp;lt;/code&amp;gt; (true)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 65535 default for &amp;lt;code&amp;gt;spark.sql.codegen.hugeMethodLimit&amp;lt;/code&amp;gt; is the largest bytecode size of a valid Java method. On HotSpot, a method larger than 8 KB of bytecode is not JIT-compiled, so Spark also splits long generated functions into smaller ones (&amp;lt;code&amp;gt;spark.sql.codegen.methodSplitThreshold&amp;lt;/code&amp;gt;).&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt; All settings in this table are internal configurations in Spark 4.3.0.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Two of these cases were seen in PySpark 4.3.0 runs. A Python UDF produced &amp;lt;code&amp;gt;BatchEvalPython&amp;lt;/code&amp;gt; without a star between two generated stages:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
*(2) Project [pythonUDF0#21L AS &amp;lt;lambda&amp;gt;(k)#20L]&lt;br /&gt;
+- BatchEvalPython [&amp;lt;lambda&amp;gt;(id#8L)#19L], [pythonUDF0#21L]&lt;br /&gt;
   +- *(1) Range (0, 1000000, step=1, splits=2)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;code&amp;gt;select&amp;lt;/code&amp;gt; of 101 computed columns left the &amp;lt;code&amp;gt;Project&amp;lt;/code&amp;gt; unstarred, while the &amp;lt;code&amp;gt;Filter&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Range&amp;lt;/code&amp;gt; below it, which have one column, kept &amp;lt;code&amp;gt;*(1)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Project Tungsten]]&lt;br /&gt;
* [[Catalyst optimizer]]&lt;br /&gt;
* [[Logical plan and physical plan]]&lt;br /&gt;
* [[Job, stage and task]]&lt;br /&gt;
* [[Adaptive Query Execution]]&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;</description>
			<pubDate>Wed, 25 Nov 2026 00:53:02 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Whole-stage_code_generation</comments>
		</item>
		<item>
			<title>Stream-static join</title>
			<link>https://openlakehouse.io/w/index.php?title=Stream-static_join&amp;diff=210&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Stream-static_join&amp;diff=210&amp;oldid=0</guid>
			<description>&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            = Stream-static join&lt;br /&gt;
| also_known_as   = Stream-table join, stream enrichment join&lt;br /&gt;
| field           = [[Stream processing]]&lt;br /&gt;
| introduced      = Apache Spark 2.0&lt;br /&gt;
| key_parts       = A streaming DataFrame, a static (batch) DataFrame or table, join keys; no streaming state&lt;br /&gt;
| implementations = [[Structured Streaming]] in [[Apache Spark]]; related forms in [[Apache Flink]] SQL (temporal and lookup joins)&lt;br /&gt;
| related         = [[Stream-stream join]], [[Delta Lake]], [[Broadcast join]], [[Stateful stream processing]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the Spark 4.3.0 Structured Streaming programming guide (join operations, support matrix) and Real-time Mode guide, the Databricks &amp;quot;Work with joins&amp;quot; page, and the Apache Flink 2.3 SQL &amp;quot;Joins&amp;quot; page}}&lt;br /&gt;
&lt;br /&gt;
In [[Apache Spark]] [[Structured Streaming]], a &amp;#039;&amp;#039;&amp;#039;stream-static join&amp;#039;&amp;#039;&amp;#039; joins a streaming DataFrame with a static DataFrame, for example a stream of orders with a table of customers. Each micro-batch of the stream is joined with the static side, and the join keeps no streaming state, so it needs no [[watermark]]. Structured Streaming has supported stream-static joins, inner and some outer types, since Spark 2.0.&amp;lt;ref name=&amp;quot;ss-ss&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#stream-static-joins |title=Structured Streaming: Stream-static Joins (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; It is the usual way to enrich events with reference or dimension data held in a lakehouse table.&lt;br /&gt;
&lt;br /&gt;
== How does a stream-static join work? ==&lt;br /&gt;
The static side is an ordinary batch DataFrame read with &amp;lt;code&amp;gt;spark.read&amp;lt;/code&amp;gt;, and the streaming side comes from &amp;lt;code&amp;gt;spark.readStream&amp;lt;/code&amp;gt;. The join is written like a batch join:&amp;lt;ref name=&amp;quot;ss-ss&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
customers = spark.read.table(&amp;quot;main.crm.customers&amp;quot;)          # static side&lt;br /&gt;
orders = spark.readStream.table(&amp;quot;main.sales.orders&amp;quot;)       # streaming side&lt;br /&gt;
&lt;br /&gt;
enriched = orders.join(customers, &amp;quot;customer_id&amp;quot;, &amp;quot;left_outer&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
(enriched.writeStream&lt;br /&gt;
    .option(&amp;quot;checkpointLocation&amp;quot;, &amp;quot;/checkpoints/orders_enriched&amp;quot;)&lt;br /&gt;
    .toTable(&amp;quot;main.sales.orders_enriched&amp;quot;))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because only the streaming side changes, each batch&amp;#039;s new rows are joined with the static data and the result is final; nothing is buffered for later matches. The Spark guide states that stream-static joins are not stateful and need no state management.&amp;lt;ref name=&amp;quot;ss-ss&amp;quot; /&amp;gt; This is the main difference from a [[stream-stream join]], which buffers both inputs.&lt;br /&gt;
&lt;br /&gt;
== Which join types are supported? ==&lt;br /&gt;
The support matrix in Spark 4.3.0 allows only the join types in which the streaming side&amp;#039;s rows can be completed from the static side alone:&amp;lt;ref name=&amp;quot;ss-matrix&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#support-matrix-for-joins-in-streaming-queries |title=Structured Streaming: Support matrix for joins in streaming queries (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;
! Left input !! Right input !! Inner !! Left outer !! Right outer !! Full outer !! Left semi&lt;br /&gt;
|-&lt;br /&gt;
| Stream || Static || Yes || Yes || No || No || Yes&lt;br /&gt;
|-&lt;br /&gt;
| Static || Stream || Yes || No || Yes || No || No&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The unsupported types would need to emit a static row once it is clear that no streaming row will ever match it, which cannot be known for an unbounded stream without state.&lt;br /&gt;
&lt;br /&gt;
== How is the static side refreshed? ==&lt;br /&gt;
The Databricks documentation, for a static side stored in [[Delta Lake]], states that each micro-batch joins the latest valid version of the static Delta table with the records of that micro-batch. The static table should therefore change slowly. If it changes between runs, reprocessing the same streaming data can give different results, so the output is not deterministic while the static side is changing.&amp;lt;ref name=&amp;quot;db-join&amp;quot;&amp;gt;{{Cite web |url=https://docs.databricks.com/aws/en/transform/join |title=Work with joins on Databricks |publisher=Databricks |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Rows already written are not revised when the static side changes later. An order joined with a customer&amp;#039;s old address keeps the old address in the output, because the join keeps no state with which to revisit it.&amp;lt;ref name=&amp;quot;ss-ss&amp;quot; /&amp;gt; Pipelines that need updates on both sides use a [[stream-stream join]] or a materialized view instead; Databricks recommends a materialized view for incremental results of an inner join.&amp;lt;ref name=&amp;quot;db-join&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Stream-static joins in Real-time Mode ==&lt;br /&gt;
Real-time Mode, added in Spark 4.1.0, supports stream-static joins only when the static side is broadcast with the &amp;lt;code&amp;gt;broadcast(...)&amp;lt;/code&amp;gt; hint, because the join must not add a shuffle.&amp;lt;ref name=&amp;quot;rtm&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/real-time-mode.html |title=Real-time Mode (Spark 4.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.functions import broadcast&lt;br /&gt;
&lt;br /&gt;
enriched = orders.join(broadcast(customers), &amp;quot;customer_id&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In micro-batch mode the hint is optional and follows the usual [[join strategy hints|join strategy]] rules.&lt;br /&gt;
&lt;br /&gt;
== Stream-static join vs stream-stream join ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! !! Stream-static join !! Stream-stream join&lt;br /&gt;
|-&lt;br /&gt;
! Inputs&lt;br /&gt;
| One streaming, one batch DataFrame&amp;lt;ref name=&amp;quot;ss-ss&amp;quot; /&amp;gt;&lt;br /&gt;
| Two streaming DataFrames&amp;lt;ref name=&amp;quot;ss-sts&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#stream-stream-joins |title=Structured Streaming: Stream-stream Joins (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! State&lt;br /&gt;
| None&amp;lt;ref name=&amp;quot;ss-ss&amp;quot; /&amp;gt;&lt;br /&gt;
| Both inputs buffered in the state store&amp;lt;ref name=&amp;quot;ss-sts&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Watermark&lt;br /&gt;
| Not needed&amp;lt;ref name=&amp;quot;db-join&amp;quot; /&amp;gt;&lt;br /&gt;
| Needed to bound state; required for outer and semi joins&amp;lt;ref name=&amp;quot;ss-sts&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Since&lt;br /&gt;
| Spark 2.0&amp;lt;ref name=&amp;quot;ss-ss&amp;quot; /&amp;gt;&lt;br /&gt;
| Spark 2.3&amp;lt;ref name=&amp;quot;ss-sts&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Real-time Mode (Spark 4.3.0)&lt;br /&gt;
| Supported with a broadcast static side&amp;lt;ref name=&amp;quot;rtm&amp;quot; /&amp;gt;&lt;br /&gt;
| Not supported&amp;lt;ref name=&amp;quot;rtm&amp;quot; /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Comparison with Flink ==&lt;br /&gt;
[[Apache Flink]] SQL has two related joins. A &amp;#039;&amp;#039;&amp;#039;temporal join&amp;#039;&amp;#039;&amp;#039; joins against a versioned table, so that each row can be matched with the version valid at its event time. A &amp;#039;&amp;#039;&amp;#039;lookup join&amp;#039;&amp;#039;&amp;#039; enriches a table with data queried from an external system; one side needs a processing-time attribute and the other must be backed by a lookup source connector.&amp;lt;ref name=&amp;quot;flink-join&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-release-2.3/docs/sql/reference/queries/joins/ |title=Joins (Apache Flink 2.3) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; A Spark stream-static join against a Delta table is closest to a processing-time lookup: each batch sees the table as it is when the batch runs.&amp;lt;ref name=&amp;quot;db-join&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Stream-stream join]]&lt;br /&gt;
* [[Broadcast join]]&lt;br /&gt;
* [[Delta Lake]]&lt;br /&gt;
* [[Structured Streaming]]&lt;br /&gt;
* [[Medallion architecture]]&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:Pipelines and orchestration]]&lt;br /&gt;
[[Category:Apache Spark]]&lt;/div&gt;</description>
			<pubDate>Wed, 25 Nov 2026 00:53:01 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Stream-static_join</comments>
		</item>
		<item>
			<title>Stream-stream join</title>
			<link>https://openlakehouse.io/w/index.php?title=Stream-stream_join&amp;diff=211&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Stream-stream_join&amp;diff=211&amp;oldid=0</guid>
			<description>&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            = Stream-stream join&lt;br /&gt;
| also_known_as   = Streaming join, interval join (Flink)&lt;br /&gt;
| field           = [[Stream processing]]&lt;br /&gt;
| introduced      = Apache Spark 2.3&lt;br /&gt;
| key_parts       = Two streaming inputs, join keys, [[watermark]] on each input, event-time range or window condition, buffered state&lt;br /&gt;
| implementations = [[Structured Streaming]] in [[Apache Spark]], [[Apache Flink]] (interval join, regular join), Kafka Streams (&amp;lt;code&amp;gt;JoinWindows&amp;lt;/code&amp;gt;)&lt;br /&gt;
| related         = [[Stream-static join]], [[Watermark]], [[State store]], [[Stateful stream processing]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the Spark 4.3.0 Structured Streaming programming guide (join operations, support matrix, recovery semantics) and Real-time Mode guide, the Apache Flink 2.3 DataStream &amp;quot;Joining&amp;quot; and SQL &amp;quot;Joins&amp;quot; pages, and the Kafka Streams 4.4 DSL developer guide}}&lt;br /&gt;
&lt;br /&gt;
In [[Apache Spark]] [[Structured Streaming]], a &amp;#039;&amp;#039;&amp;#039;stream-stream join&amp;#039;&amp;#039;&amp;#039; joins two streaming DataFrames, so that each new row from one stream is matched with rows that have arrived, or will arrive, on the other. Because a match can come later, Spark buffers past rows of both inputs as state; [[watermark]]s on both inputs and a time condition in the join let Spark drop buffered rows that can no longer match, so that state does not grow without limit. Spark added stream-stream joins in Spark 2.3.&amp;lt;ref name=&amp;quot;ss-join&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#stream-stream-joins |title=Structured Streaming: Stream-stream Joins (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The result of the join is the same as a batch join over the same data.&amp;lt;ref name=&amp;quot;ss-joinops&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#join-operations |title=Structured Streaming: Join Operations (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Why does a stream-stream join need state? ==&lt;br /&gt;
At any moment, both sides of a stream-stream join are incomplete. A row received now on one input can match a row that the other input has not received yet. Spark therefore keeps past input from both streams in the [[state store]], matches every new row against it, and handles late and out-of-order data the same way as for aggregations.&amp;lt;ref name=&amp;quot;ss-join&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Without limits, all past input must be kept, because any new row could match any old one.&amp;lt;ref name=&amp;quot;ss-inner&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#inner-joins-with-optional-watermarking |title=Structured Streaming: Inner Joins with optional Watermarking (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; In a long-running query, that state grows until the query fails or slows down.&lt;br /&gt;
&lt;br /&gt;
== How do watermarks and time constraints bound state? ==&lt;br /&gt;
To let Spark clear old rows, a join needs two things:&amp;lt;ref name=&amp;quot;ss-inner&amp;quot; /&amp;gt;&lt;br /&gt;
# a watermark on both inputs, saying how late each input&amp;#039;s data can be; and&lt;br /&gt;
# an event-time constraint between the inputs, so that Spark can tell when an old row of one input can no longer match the other. The constraint is either a time range, such as &amp;lt;code&amp;gt;leftTime BETWEEN rightTime AND rightTime + INTERVAL 1 HOUR&amp;lt;/code&amp;gt;, or a join on event-time windows, such as &amp;lt;code&amp;gt;leftTimeWindow = rightTimeWindow&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
With both, the rows kept for each side are roughly those within the other side&amp;#039;s watermark delay plus the width of the time range. The guarantee follows the watermark rule: with a 2-hour watermark, no row less than 2 hours late is dropped, but a row later than that may or may not be processed.&amp;lt;ref name=&amp;quot;ss-join&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
The Spark guide&amp;#039;s example joins ad impressions with ad clicks. Impressions can be up to 2 hours late, clicks up to 3 hours late, and a click counts if it happens within 1 hour after its impression.&amp;lt;ref name=&amp;quot;ss-inner&amp;quot; /&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.functions import expr&lt;br /&gt;
&lt;br /&gt;
impressions = spark.readStream.table(&amp;quot;main.ads.impressions&amp;quot;)   # impressionAdId, impressionTime&lt;br /&gt;
clicks = spark.readStream.table(&amp;quot;main.ads.clicks&amp;quot;)             # clickAdId, clickTime&lt;br /&gt;
&lt;br /&gt;
joined = (impressions.withWatermark(&amp;quot;impressionTime&amp;quot;, &amp;quot;2 hours&amp;quot;)&lt;br /&gt;
    .join(&lt;br /&gt;
        clicks.withWatermark(&amp;quot;clickTime&amp;quot;, &amp;quot;3 hours&amp;quot;),&lt;br /&gt;
        expr(&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
            clickAdId = impressionAdId AND&lt;br /&gt;
            clickTime &amp;gt;= impressionTime AND&lt;br /&gt;
            clickTime &amp;lt;= impressionTime + interval 1 hour&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;),&lt;br /&gt;
        &amp;quot;leftOuter&amp;quot;,&lt;br /&gt;
    ))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Which join types are supported? ==&lt;br /&gt;
Inner joins are supported on any columns and conditions; watermarks and time constraints are optional, but without them state is unbounded. Outer and semi joins require them, because Spark must know when a row will never match in order to emit the outer row with nulls, or to evict an unmatched left row.&amp;lt;ref name=&amp;quot;ss-join&amp;quot; /&amp;gt; The support matrix in Spark 4.3.0:&amp;lt;ref name=&amp;quot;ss-matrix&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#support-matrix-for-joins-in-streaming-queries |title=Structured Streaming: Support matrix for joins in streaming queries (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;
! Join type !! Requirement&lt;br /&gt;
|-&lt;br /&gt;
| Inner || Supported; watermarks on both sides and a time constraint are optional and enable state cleanup&lt;br /&gt;
|-&lt;br /&gt;
| Left outer || Watermark on the right side and a time constraint required; left watermark optional, for full cleanup&lt;br /&gt;
|-&lt;br /&gt;
| Right outer || Watermark on the left side and a time constraint required; right watermark optional&lt;br /&gt;
|-&lt;br /&gt;
| Full outer || Watermark on one side and a time constraint required; the other watermark optional&lt;br /&gt;
|-&lt;br /&gt;
| Left semi || Watermark on the right side and a time constraint required; left watermark optional&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Other rules apply. Joins can be chained (&amp;lt;code&amp;gt;df1.join(df2, ...).join(df3, ...)&amp;lt;/code&amp;gt;), and a query with a stream-stream join must use append [[output mode]]. &amp;lt;code&amp;gt;mapGroupsWithState&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;flatMapGroupsWithState&amp;lt;/code&amp;gt; cannot be used before or after a join, but in append mode aggregations, deduplication and other joins can.&amp;lt;ref name=&amp;quot;ss-matrix&amp;quot; /&amp;gt; Changing the join type, the equi-join columns or the input schema is not allowed between restarts from the same [[streaming checkpoint]].&amp;lt;ref name=&amp;quot;ss-changes&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#recovery-semantics-after-changes-in-a-streaming-query |title=Structured Streaming: Recovery Semantics after Changes in a Streaming Query (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Stream-stream joins are not supported in Real-time Mode as of Spark 4.3.0.&amp;lt;ref name=&amp;quot;rtm&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/real-time-mode.html |title=Real-time Mode (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Why are outer join results delayed? ==&lt;br /&gt;
An outer row with nulls is emitted only after Spark is sure no match will arrive, so its delay depends on the watermark delay and the time range. In the micro-batch engine, the watermark advances at the end of a batch and the next batch uses it to clean state and emit outer rows. Since a batch runs only when there is new data, outer output can be held back if either input stops receiving data for a while.&amp;lt;ref name=&amp;quot;ss-outer&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#outer-joins-with-watermarking |title=Structured Streaming: Outer Joins with Watermarking (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Stream-stream joins in other engines ==&lt;br /&gt;
[[Apache Flink]]&amp;#039;s DataStream API has an &amp;#039;&amp;#039;&amp;#039;interval join&amp;#039;&amp;#039;&amp;#039;: elements of stream B with the same key match an element of stream A when &amp;lt;code&amp;gt;a.timestamp + lowerBound &amp;lt;= b.timestamp &amp;lt;= a.timestamp + upperBound&amp;lt;/code&amp;gt;. It supports only inner joins.&amp;lt;ref name=&amp;quot;flink-dsjoin&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-release-2.3/docs/dev/datastream/operators/joining/ |title=Joining (Apache Flink 2.3) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Flink SQL distinguishes &amp;#039;&amp;#039;&amp;#039;regular joins&amp;#039;&amp;#039;&amp;#039;, which keep both inputs in state forever unless a state TTL is configured (which can affect correctness), from &amp;#039;&amp;#039;&amp;#039;interval joins&amp;#039;&amp;#039;&amp;#039;, which need at least one equi-join predicate and a condition that bounds time on both sides.&amp;lt;ref name=&amp;quot;flink-sqljoin&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-release-2.3/docs/sql/reference/queries/joins/ |title=Joins (Apache Flink 2.3) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; A Spark join with a time-range condition and watermarks corresponds to an interval join; a Spark inner join without them corresponds to a regular join without TTL.&lt;br /&gt;
&lt;br /&gt;
Kafka Streams uses &amp;lt;code&amp;gt;JoinWindows&amp;lt;/code&amp;gt;, a sliding window over record timestamps, for windowed stream-stream joins.&amp;lt;ref name=&amp;quot;kstreams&amp;quot;&amp;gt;{{Cite web |url=https://kafka.apache.org/44/streams/developer-guide/dsl-api/ |title=Kafka Streams DSL (Apache Kafka 4.4) |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;
! !! Spark stream-stream join !! Flink DataStream interval join !! Flink SQL interval join !! Flink SQL regular join&lt;br /&gt;
|-&lt;br /&gt;
! Time bound&lt;br /&gt;
| Optional for inner, required for outer and semi&amp;lt;ref name=&amp;quot;ss-join&amp;quot; /&amp;gt;&lt;br /&gt;
| Required (lower and upper bound)&amp;lt;ref name=&amp;quot;flink-dsjoin&amp;quot; /&amp;gt;&lt;br /&gt;
| Required on both sides&amp;lt;ref name=&amp;quot;flink-sqljoin&amp;quot; /&amp;gt;&lt;br /&gt;
| None&amp;lt;ref name=&amp;quot;flink-sqljoin&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Can state grow without limit?&lt;br /&gt;
| Yes, for an inner join without watermarks and a time constraint&amp;lt;ref name=&amp;quot;ss-inner&amp;quot; /&amp;gt;&lt;br /&gt;
| No; the time bounds are part of the join&amp;lt;ref name=&amp;quot;flink-dsjoin&amp;quot; /&amp;gt;&lt;br /&gt;
| No; the time condition is required&amp;lt;ref name=&amp;quot;flink-sqljoin&amp;quot; /&amp;gt;&lt;br /&gt;
| Yes, unless a state TTL is configured&amp;lt;ref name=&amp;quot;flink-sqljoin&amp;quot; /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Stream-static join]]&lt;br /&gt;
* [[Watermark]]&lt;br /&gt;
* [[State store]]&lt;br /&gt;
* [[Stateful stream processing]]&lt;br /&gt;
* [[Output mode]]&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:Pipelines and orchestration]]&lt;br /&gt;
[[Category:Apache Spark]]&lt;/div&gt;</description>
			<pubDate>Wed, 25 Nov 2026 00:53:01 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Stream-stream_join</comments>
		</item>
		<item>
			<title>Time travel (SQL)</title>
			<link>https://openlakehouse.io/w/index.php?title=Time_travel_(SQL)&amp;diff=212&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Time_travel_(SQL)&amp;diff=212&amp;oldid=0</guid>
			<description>&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            = Time travel (SQL)&lt;br /&gt;
| also_known_as   = AS OF query, temporal query, snapshot query&lt;br /&gt;
| field           = Table formats and SQL&lt;br /&gt;
| key_parts       = VERSION AS OF, TIMESTAMP AS OF, table versions or snapshots, retention&lt;br /&gt;
| implementations = [[Apache Spark]] with [[Delta Lake]], [[Apache Iceberg]] and [[Apache Hudi]]; [[Trino]], Snowflake, BigQuery&lt;br /&gt;
| related         = [[Open table format]], [[Data Source V2]], [[Catalog plugin API (Spark)]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (SqlBaseParser.g4, SQLConf.scala, TableCatalog.java, TimeTravelSpec.scala, DataFrameReader.scala, docs/sql-migration-guide.md), the Spark 3.3.0, 3.4.0, 4.0.0 and 4.3.0 release notes, Delta Lake batch reads and writes docs, Apache Iceberg 1.12.0 Spark queries and configuration docs, Apache Hudi 1.2.1 SQL queries and quick start docs, Trino 484 Iceberg and Delta Lake connector docs, the Snowflake AT/BEFORE reference and the BigQuery query syntax and time travel docs}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Time travel&amp;#039;&amp;#039;&amp;#039; in SQL is a query that reads a table as it was at an earlier version or point in time, written in [[Apache Spark]] SQL as &amp;lt;code&amp;gt;SELECT ... FROM t VERSION AS OF v&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;SELECT ... FROM t TIMESTAMP AS OF ts&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;grammar&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/api/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBaseParser.g4 |title=SqlBaseParser.g4 (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Spark parses the clause, and the table format resolves it: [[Delta Lake]] maps the version to a commit in its transaction log, and [[Apache Iceberg]] maps it to a snapshot ID, branch or tag. Time travel is used to reproduce reports and models, audit changes and recover from bad writes, and it works only while the old data and metadata are still retained.&amp;lt;ref name=&amp;quot;delta&amp;quot;&amp;gt;{{Cite web |url=https://docs.delta.io/latest/delta-batch.html |title=Table batch reads and writes |publisher=Delta Lake (Linux Foundation) |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What is the syntax in Apache Spark? ==&lt;br /&gt;
The Spark SQL grammar accepts four spellings after a table name: &amp;lt;code&amp;gt;VERSION AS OF&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;FOR SYSTEM_VERSION AS OF&amp;lt;/code&amp;gt; take an integer or string literal; &amp;lt;code&amp;gt;TIMESTAMP AS OF&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;FOR SYSTEM_TIME AS OF&amp;lt;/code&amp;gt; take an expression.&amp;lt;ref name=&amp;quot;grammar&amp;quot; /&amp;gt; The timestamp expression must be deterministic and evaluable once at analysis time, and a query cannot carry both a version and a timestamp.&amp;lt;ref name=&amp;quot;ttspec&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TimeTravelSpec.scala |title=TimeTravelSpec.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spark 3.3.0 added the &amp;lt;code&amp;gt;AS OF&amp;lt;/code&amp;gt; syntax (SPARK-37219), and Spark 3.4.0 allowed a scalar subquery in the timestamp (SPARK-39306).&amp;lt;ref name=&amp;quot;r330&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-3-3-0.html |title=Spark Release 3.3.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;r340&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-3-4-0.html |title=Spark Release 3.4.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Spark 4.0.0 added time travel options to the &amp;lt;code&amp;gt;spark.read&amp;lt;/code&amp;gt; API (SPARK-45575); the option names are &amp;lt;code&amp;gt;versionAsOf&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;timestampAsOf&amp;lt;/code&amp;gt; by default, configurable with &amp;lt;code&amp;gt;spark.sql.timeTravelVersionKey&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spark.sql.timeTravelTimestampKey&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;r400&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4-0-0.html |title=Spark Release 4.0.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;sqlconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala |title=SQLConf.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spark 4.3.0 added an &amp;lt;code&amp;gt;@&amp;lt;/code&amp;gt; suffix on table names (SPARK-57421, SPARK-58012): &amp;lt;code&amp;gt;name@v123&amp;lt;/code&amp;gt; reads version 123, and &amp;lt;code&amp;gt;name@20240101000000000&amp;lt;/code&amp;gt; (format &amp;lt;code&amp;gt;yyyyMMddHHmmssSSS&amp;lt;/code&amp;gt;, in the session time zone) reads the table at that timestamp to millisecond precision. The suffix is controlled by &amp;lt;code&amp;gt;spark.sql.timeTravel.atSyntax.enabled&amp;lt;/code&amp;gt;, default &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;r430&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4-3-0.html |title=Spark Release 4.3.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt; Also since 4.3, Spark rejects these time travel options on catalog-backed Data Source V2 writes with &amp;lt;code&amp;gt;UNSUPPORTED_FEATURE.TIME_TRAVEL&amp;lt;/code&amp;gt;, because a write must target the current table state.&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;&lt;br /&gt;
&lt;br /&gt;
== How does a connector implement time travel? ==&lt;br /&gt;
For catalog tables, Spark passes the parsed clause to the [[Catalog plugin API (Spark)|catalog plugin]]. &amp;lt;code&amp;gt;TableCatalog&amp;lt;/code&amp;gt; has &amp;lt;code&amp;gt;loadTable(ident, String version)&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;loadTable(ident, long timestamp)&amp;lt;/code&amp;gt;, where the timestamp is in microseconds since the Unix epoch. Their default implementations throw a &amp;quot;no such table&amp;quot; error, so a catalog that does not override them does not support time travel.&amp;lt;ref name=&amp;quot;tablecatalog&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/TableCatalog.java |title=TableCatalog.java (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;
Spark SQL against a Delta Lake or Iceberg table named &amp;lt;code&amp;gt;sales.orders&amp;lt;/code&amp;gt;:&amp;lt;ref name=&amp;quot;delta&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;iceq&amp;quot;&amp;gt;{{Cite web |url=https://iceberg.apache.org/docs/latest/spark-queries/ |title=Spark Queries (Apache Iceberg 1.12.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
-- Delta Lake: commit version from DESCRIBE HISTORY&lt;br /&gt;
SELECT * FROM sales.orders VERSION AS OF 12;&lt;br /&gt;
SELECT * FROM sales.orders TIMESTAMP AS OF &amp;#039;2026-11-01 00:00:00&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
-- Iceberg: snapshot ID, branch or tag name&lt;br /&gt;
SELECT * FROM lake.sales.orders VERSION AS OF 10963874102873;&lt;br /&gt;
SELECT * FROM lake.sales.orders VERSION AS OF &amp;#039;audit-branch&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
-- Spark 4.3 @ suffix (for catalogs that implement time travel)&lt;br /&gt;
SELECT * FROM sales.orders@v12;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same reads with the DataFrame API, where &amp;lt;code&amp;gt;spark.read.table&amp;lt;/code&amp;gt; passes its options to the relation that Spark resolves:&amp;lt;ref name=&amp;quot;reader&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/classic/DataFrameReader.scala |title=DataFrameReader.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;r400&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
df_v12 = spark.read.option(&amp;quot;versionAsOf&amp;quot;, 12).table(&amp;quot;sales.orders&amp;quot;)&lt;br /&gt;
df_nov = spark.read.option(&amp;quot;timestampAsOf&amp;quot;, &amp;quot;2026-11-01 00:00:00&amp;quot;).table(&amp;quot;sales.orders&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How do table formats compare? ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! !! Delta Lake !! Apache Iceberg !! Apache Hudi&lt;br /&gt;
|-&lt;br /&gt;
! What a version is&lt;br /&gt;
| A commit version in the transaction log, listed by &amp;lt;code&amp;gt;DESCRIBE HISTORY&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;delta&amp;quot; /&amp;gt;&lt;br /&gt;
| A snapshot ID, or a branch or tag name&amp;lt;ref name=&amp;quot;iceq&amp;quot; /&amp;gt;&lt;br /&gt;
| A commit time (instant)&amp;lt;ref name=&amp;quot;hudiqs&amp;quot;&amp;gt;{{Cite web |url=https://hudi.apache.org/docs/quick-start-guide/ |title=Spark Quick Start (Apache Hudi 1.2.1) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Spark SQL syntax&lt;br /&gt;
| &amp;lt;code&amp;gt;VERSION AS OF&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;TIMESTAMP AS OF&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;delta&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;VERSION AS OF&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;TIMESTAMP AS OF&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;FOR SYSTEM_VERSION AS OF&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;FOR SYSTEM_TIME AS OF&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;iceq&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;TIMESTAMP AS OF&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;hudisql&amp;quot;&amp;gt;{{Cite web |url=https://hudi.apache.org/docs/sql_queries/ |title=SQL Queries (Apache Hudi 1.2.1) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Timestamp forms&lt;br /&gt;
| Any expression castable to a timestamp, such as &amp;lt;code&amp;gt;&amp;#039;2018-10-18&amp;#039;&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;current_timestamp() - interval 12 hours&amp;lt;/code&amp;gt;; no subqueries&amp;lt;ref name=&amp;quot;delta&amp;quot; /&amp;gt;&lt;br /&gt;
| Timestamp string, or Unix time in seconds in SQL&amp;lt;ref name=&amp;quot;iceq&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;yyyy-MM-dd HH:mm:ss.SSS&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yyyy-MM-dd&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;yyyyMMddHHmmssSSS&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;hudisql&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! DataFrame options&lt;br /&gt;
| &amp;lt;code&amp;gt;versionAsOf&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;timestampAsOf&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;delta&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;snapshot-id&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;as-of-timestamp&amp;lt;/code&amp;gt; (milliseconds), &amp;lt;code&amp;gt;branch&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;tag&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;iceq&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;as.of.instant&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;hudiqs&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! What limits how far back&lt;br /&gt;
| &amp;lt;code&amp;gt;delta.logRetentionDuration&amp;lt;/code&amp;gt; (default 30 days) and &amp;lt;code&amp;gt;VACUUM&amp;lt;/code&amp;gt;, governed by &amp;lt;code&amp;gt;delta.deletedFileRetentionDuration&amp;lt;/code&amp;gt; (default 7 days)&amp;lt;ref name=&amp;quot;delta&amp;quot; /&amp;gt;&lt;br /&gt;
| Snapshot expiration; &amp;lt;code&amp;gt;history.expire.max-snapshot-age-ms&amp;lt;/code&amp;gt; defaults to 5 days and &amp;lt;code&amp;gt;history.expire.min-snapshots-to-keep&amp;lt;/code&amp;gt; to 1&amp;lt;ref name=&amp;quot;icecfg&amp;quot;&amp;gt;{{Cite web |url=https://iceberg.apache.org/docs/latest/configuration/ |title=Configuration (Apache Iceberg 1.12.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| Not described on the cited Hudi pages&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Delta Lake documents that, by default, a table can be read up to 30 days back unless &amp;lt;code&amp;gt;VACUUM&amp;lt;/code&amp;gt; has run or the retention properties were changed. Because version timestamps come from log file timestamps, time travel by timestamp can break if the table directory is copied to a new location, while time travel by version is unaffected.&amp;lt;ref name=&amp;quot;delta&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Iceberg branches and tags give names to snapshots. A query by snapshot ID or timestamp uses the schema of that snapshot, a query on a branch uses the table&amp;#039;s current schema, and a query on a tag uses the schema of the tagged snapshot.&amp;lt;ref name=&amp;quot;iceq&amp;quot; /&amp;gt; Iceberg snapshots remain until they are expired, so expiration settings, not a fixed window, decide what can be read.&amp;lt;ref name=&amp;quot;icemaint&amp;quot;&amp;gt;{{Cite web |url=https://iceberg.apache.org/docs/latest/maintenance/ |title=Maintenance (Apache Iceberg 1.12.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Time travel in other engines ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Engine !! Syntax&lt;br /&gt;
|-&lt;br /&gt;
| [[Trino]] 484 (Iceberg and Delta Lake connectors)&lt;br /&gt;
| &amp;lt;code&amp;gt;FOR VERSION AS OF&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;FOR TIMESTAMP AS OF&amp;lt;/code&amp;gt;; on Iceberg, the version can be a branch or tag name&amp;lt;ref&amp;gt;{{Cite web |url=https://trino.io/docs/current/connector/iceberg.html |title=Iceberg connector (Trino 484) |publisher=Trino Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://trino.io/docs/current/connector/delta-lake.html |title=Delta Lake connector (Trino 484) |publisher=Trino Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Snowflake&lt;br /&gt;
| &amp;lt;code&amp;gt;AT&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;BEFORE&amp;lt;/code&amp;gt; in the &amp;lt;code&amp;gt;FROM&amp;lt;/code&amp;gt; clause, for example &amp;lt;code&amp;gt;AT (TIMESTAMP =&amp;gt; ...)&amp;lt;/code&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://docs.snowflake.com/en/sql-reference/constructs/at-before |title=AT, BEFORE |publisher=Snowflake |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| BigQuery&lt;br /&gt;
| &amp;lt;code&amp;gt;FOR SYSTEM_TIME AS OF&amp;lt;/code&amp;gt;; the time travel window is seven days by default and can be set between two and seven days&amp;lt;ref&amp;gt;{{Cite web |url=https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax |title=Query syntax (GoogleSQL for BigQuery) |publisher=Google Cloud |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://cloud.google.com/bigquery/docs/time-travel |title=Data retention with time travel and fail-safe |publisher=Google Cloud |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Delta Lake]]&lt;br /&gt;
* [[Apache Iceberg]]&lt;br /&gt;
* [[Apache Hudi]]&lt;br /&gt;
* [[Open table format]]&lt;br /&gt;
* [[Catalog plugin API (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;br /&gt;
[[Category:Table formats]]&lt;/div&gt;</description>
			<pubDate>Wed, 25 Nov 2026 00:53:01 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Time_travel_(SQL)</comments>
		</item>
		<item>
			<title>State store</title>
			<link>https://openlakehouse.io/w/index.php?title=State_store&amp;diff=207&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=State_store&amp;diff=207&amp;oldid=0</guid>
			<description>&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            = State store&lt;br /&gt;
| also_known_as   = State store provider&lt;br /&gt;
| field           = [[Stream processing]]&lt;br /&gt;
| key_parts       = Versioned key-value store per operator and partition, state store provider class, checkpointed files, maintenance task&lt;br /&gt;
| implementations = [[Structured Streaming]]: &amp;lt;code&amp;gt;HDFSBackedStateStoreProvider&amp;lt;/code&amp;gt; (default) and &amp;lt;code&amp;gt;RocksDBStateStoreProvider&amp;lt;/code&amp;gt;&lt;br /&gt;
| related         = [[RocksDB state store]], [[Streaming checkpoint]], [[Stateful stream processing]], [[Watermark]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the Spark 4.3.0 Structured Streaming programming guide (State Store section) and miscellaneous notes, &amp;lt;code&amp;gt;SQLConf.scala&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;HDFSBackedStateStoreProvider.scala&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;RocksDBFileManager.scala&amp;lt;/code&amp;gt; at tag v4.3.0 of apache/spark, the state data source guide, SPARK-45511, the Databricks RocksDB state store page, and the Apache Flink 2.3 &amp;quot;State Backends&amp;quot; page}}&lt;br /&gt;
&lt;br /&gt;
In [[Apache Spark]] [[Structured Streaming]], a &amp;#039;&amp;#039;&amp;#039;state store&amp;#039;&amp;#039;&amp;#039; is the versioned key-value store in which stateful operators keep the data they carry from one micro-batch to the next, such as running aggregates, deduplication keys, buffered join rows and user state. Each stateful operator has one state store per shuffle partition, running on an executor, and every batch produces a new version that is saved to the [[streaming checkpoint]] so the state survives failures.&amp;lt;ref name=&amp;quot;ss-store&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#state-store |title=Structured Streaming: State Store (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Spark ships two implementations, the HDFS-backed state store and the [[RocksDB state store]], and the choice between them mostly decides how much state a query can hold without memory problems.&lt;br /&gt;
&lt;br /&gt;
== Which operators use the state store? ==&lt;br /&gt;
Streaming aggregations, streaming deduplication with &amp;lt;code&amp;gt;dropDuplicates&amp;lt;/code&amp;gt;, stream-stream joins and the arbitrary stateful operators (&amp;lt;code&amp;gt;mapGroupsWithState&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;flatMapGroupsWithState&amp;lt;/code&amp;gt; and [[transformWithState]]) all keep state in the state store.&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt; Stateless operations, including [[stream-static join]]s, do not.&amp;lt;ref name=&amp;quot;ss-join&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#stream-static-joins |title=Structured Streaming: Stream-static Joins (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; See [[Stateful stream processing]].&lt;br /&gt;
&lt;br /&gt;
== How does the state store work? ==&lt;br /&gt;
A state store is a versioned key-value store with reads and writes. Updates are applied in sets, transactionally, and each set increments the store&amp;#039;s version; a retried task can therefore re-run its updates against the correct earlier version.&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt; The version of a store matches the batch id of the query.&lt;br /&gt;
&lt;br /&gt;
The state store provider is set with &amp;lt;code&amp;gt;spark.sql.streaming.stateStore.providerClass&amp;lt;/code&amp;gt;. Its default is &amp;lt;code&amp;gt;org.apache.spark.sql.execution.streaming.state.HDFSBackedStateStoreProvider&amp;lt;/code&amp;gt;, and it cannot be changed between restarts from the same checkpoint location.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala |title=SQLConf.scala (Apache Spark v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;misc&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/additional-information.html |title=Structured Streaming: Miscellaneous Notes (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Users can also write their own provider by extending the &amp;lt;code&amp;gt;StateStoreProvider&amp;lt;/code&amp;gt; interface.&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
State is partitioned by hashing the grouping key, which is why &amp;lt;code&amp;gt;spark.sql.shuffle.partitions&amp;lt;/code&amp;gt; cannot change for a query that already has a checkpoint.&amp;lt;ref name=&amp;quot;misc&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spark tries to run each state store on the same executor in every batch, using the preferred-location feature of RDDs, because loading a store on a new executor means reading its checkpointed files. The preference is not a guarantee; raising &amp;lt;code&amp;gt;spark.locality.wait&amp;lt;/code&amp;gt; makes it more likely to hold. A background maintenance task, run every &amp;lt;code&amp;gt;spark.sql.streaming.stateStore.maintenanceInterval&amp;lt;/code&amp;gt; (default 60 seconds), runs background maintenance in every loaded provider and unloads providers that are no longer active on an executor.&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== HDFS-backed vs RocksDB state store ==&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;HDFS-backed state store&amp;#039;&amp;#039;&amp;#039; keeps all of its data in an in-memory map in the executor JVM and saves it to files in an HDFS-compatible file system.&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt; Each batch writes a &amp;lt;code&amp;gt;&amp;#039;&amp;#039;version&amp;#039;&amp;#039;.delta&amp;lt;/code&amp;gt; file with that batch&amp;#039;s changes, and Spark consolidates deltas into a &amp;lt;code&amp;gt;&amp;#039;&amp;#039;version&amp;#039;&amp;#039;.snapshot&amp;lt;/code&amp;gt; file after &amp;lt;code&amp;gt;spark.sql.streaming.stateStore.minDeltasForSnapshot&amp;lt;/code&amp;gt; (default 10) delta files.&amp;lt;ref name=&amp;quot;hdfs&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/HDFSBackedStateStoreProvider.scala |title=HDFSBackedStateStoreProvider.scala (Apache Spark v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;RocksDB state store&amp;#039;&amp;#039;&amp;#039;, added in Spark 3.2, keeps state in RocksDB in native memory and on local disk instead of the JVM heap, and uploads its files to the checkpoint location. The Spark guide recommends it for queries with millions of keys in state, where the HDFS-backed store causes long JVM garbage collection pauses and uneven micro-batch times.&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt; It is the only provider that supports [[transformWithState]]. See [[RocksDB state store]].&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! !! HDFS-backed state store !! RocksDB state store&lt;br /&gt;
|-&lt;br /&gt;
! Provider class&lt;br /&gt;
| &amp;lt;code&amp;gt;HDFSBackedStateStoreProvider&amp;lt;/code&amp;gt; (default in Apache Spark)&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;RocksDBStateStoreProvider&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Where live state is held&lt;br /&gt;
| In-memory map on the executor JVM heap&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt;&lt;br /&gt;
| RocksDB, in native memory and on local disk&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Checkpoint files&lt;br /&gt;
| &amp;lt;code&amp;gt;.delta&amp;lt;/code&amp;gt; per batch, &amp;lt;code&amp;gt;.snapshot&amp;lt;/code&amp;gt; after consolidation&amp;lt;ref name=&amp;quot;hdfs&amp;quot; /&amp;gt;&lt;br /&gt;
| A &amp;lt;code&amp;gt;&amp;#039;&amp;#039;version&amp;#039;&amp;#039;.zip&amp;lt;/code&amp;gt; per version plus shared SST files; optionally changelog files&amp;lt;ref name=&amp;quot;rocksfm&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDBFileManager.scala |title=RocksDBFileManager.scala (Apache Spark v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! State size limit in practice&lt;br /&gt;
| Executor heap; large state causes GC pauses&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt;&lt;br /&gt;
| Local disk and the configured memory bound&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! transformWithState&lt;br /&gt;
| Not supported&lt;br /&gt;
| Supported&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
On Databricks, RocksDB is the default state store provider in Databricks Runtime 17.3 LTS and above.&amp;lt;ref name=&amp;quot;db-rocks&amp;quot;&amp;gt;{{Cite web |url=https://docs.databricks.com/aws/en/structured-streaming/rocksdb-state-store |title=Configure RocksDB state store on Databricks |publisher=Databricks |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How big does state get? ==&lt;br /&gt;
State size is driven by the number of distinct keys each operator keeps and how long it keeps them. A [[watermark]] bounds it for windowed aggregations, deduplication and stream-stream joins; without one, aggregation and deduplication state grows for as long as new keys arrive.&amp;lt;ref name=&amp;quot;ss-dedup&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#streaming-deduplication |title=Structured Streaming: Streaming Deduplication (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Each operator reports state metrics in the query progress, including the number of rows in state (&amp;lt;code&amp;gt;numTotalStateRows&amp;lt;/code&amp;gt;), updated and removed rows.&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;state data source&amp;#039;&amp;#039;&amp;#039; reads the state of a checkpoint as a batch DataFrame, which helps to inspect state size and contents. It is experimental and, as of Spark 4.0, read-only.&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;jira45511&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-45511 |title=SPARK-45511: SPIP: State Data Source - Reader |publisher=Apache Software Foundation JIRA |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;
spark.conf.set(&lt;br /&gt;
    &amp;quot;spark.sql.streaming.stateStore.providerClass&amp;quot;,&lt;br /&gt;
    &amp;quot;org.apache.spark.sql.execution.streaming.state.RocksDBStateStoreProvider&amp;quot;,&lt;br /&gt;
)  # set before the query first starts; fixed for its checkpoint&lt;br /&gt;
&lt;br /&gt;
state = spark.read.format(&amp;quot;statestore&amp;quot;).load(&amp;quot;/checkpoints/page_counts&amp;quot;)&lt;br /&gt;
state.groupBy(&amp;quot;partition_id&amp;quot;).count().show()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison with Flink state backends ==&lt;br /&gt;
[[Apache Flink]] calls the same component a &amp;#039;&amp;#039;&amp;#039;state backend&amp;#039;&amp;#039;&amp;#039;. Without other configuration it uses the &amp;lt;code&amp;gt;HashMapStateBackend&amp;lt;/code&amp;gt;, which holds state as objects on the Java heap, much like Spark&amp;#039;s HDFS-backed store. The &amp;lt;code&amp;gt;EmbeddedRocksDBStateBackend&amp;lt;/code&amp;gt; keeps state as serialized bytes in RocksDB and is the only Flink backend that offers incremental checkpoints; the &amp;lt;code&amp;gt;ForStStateBackend&amp;lt;/code&amp;gt; is experimental.&amp;lt;ref name=&amp;quot;flink-sb&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-release-2.3/docs/ops/state/state_backends/ |title=State Backends (Apache Flink 2.3) |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;
* [[RocksDB state store]]&lt;br /&gt;
* [[Stateful stream processing]]&lt;br /&gt;
* [[Streaming checkpoint]]&lt;br /&gt;
* [[transformWithState]]&lt;br /&gt;
* [[Watermark]]&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;br /&gt;
[[Category:Pipelines and orchestration]]&lt;/div&gt;</description>
			<pubDate>Wed, 25 Nov 2026 00:53:00 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:State_store</comments>
		</item>
		<item>
			<title>Streaming checkpoint</title>
			<link>https://openlakehouse.io/w/index.php?title=Streaming_checkpoint&amp;diff=208&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Streaming_checkpoint&amp;diff=208&amp;oldid=0</guid>
			<description>&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            = Streaming checkpoint&lt;br /&gt;
| also_known_as   = Checkpoint location, &amp;lt;code&amp;gt;checkpointLocation&amp;lt;/code&amp;gt;&lt;br /&gt;
| field           = [[Stream processing]]&lt;br /&gt;
| key_parts       = Offset log (&amp;lt;code&amp;gt;offsets/&amp;lt;/code&amp;gt;), commit log (&amp;lt;code&amp;gt;commits/&amp;lt;/code&amp;gt;), state (&amp;lt;code&amp;gt;state/&amp;lt;/code&amp;gt;), query metadata (&amp;lt;code&amp;gt;metadata&amp;lt;/code&amp;gt;)&lt;br /&gt;
| implementations = [[Structured Streaming]] in [[Apache Spark]]&lt;br /&gt;
| related         = [[Checkpointing (Spark)]], [[State store]], [[Exactly-once semantics]], [[Flink checkpoint and savepoint]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the Spark 4.3.0 Structured Streaming programming guide (recovering from failures, recovery semantics after changes) and miscellaneous notes, and &amp;lt;code&amp;gt;StreamingCheckpointConstants.scala&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;StreamingQueryCheckpointMetadata.scala&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;StreamMetadata.scala&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;CommitLog.scala&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;OffsetSeq.scala&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;SQLConf.scala&amp;lt;/code&amp;gt; at tag v4.3.0 of apache/spark, the Delta Lake table streaming documentation and the Apache Flink 2.3 &amp;quot;Checkpoints vs. Savepoints&amp;quot; page}}&lt;br /&gt;
&lt;br /&gt;
In [[Apache Spark]] [[Structured Streaming]], a &amp;#039;&amp;#039;&amp;#039;streaming checkpoint&amp;#039;&amp;#039;&amp;#039; is the directory, set with the &amp;lt;code&amp;gt;checkpointLocation&amp;lt;/code&amp;gt; option, where a streaming query records which input offsets each micro-batch covered, which batches finished, and the state of its stateful operators, so that after a failure or a restart the query continues exactly where it stopped.&amp;lt;ref name=&amp;quot;ss-ckpt&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#recovering-from-failures-with-checkpointing |title=Structured Streaming: Recovering from Failures with Checkpointing (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; A checkpoint belongs to one query. Some changes to the query can be made between restarts from the same checkpoint and others cannot. Lineage checkpoints of RDDs and DataFrames are a different feature; see [[Checkpointing (Spark)]].&lt;br /&gt;
&lt;br /&gt;
== What is inside a streaming checkpoint? ==&lt;br /&gt;
At tag v4.3.0, Spark names four entries under the checkpoint root: &amp;lt;code&amp;gt;offsets&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;commits&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;state&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;metadata&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;consts&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/runtime/StreamingCheckpointConstants.scala |title=StreamingCheckpointConstants.scala (Apache Spark v4.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;
! Entry !! Contents !! Written&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;offsets/&amp;lt;/code&amp;gt;&lt;br /&gt;
| The offset log: one file per batch with the offsets of every source for that batch, plus a set of session configurations that must stay fixed for the query&amp;lt;ref name=&amp;quot;offsetseq&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/checkpointing/OffsetSeq.scala |title=OffsetSeq.scala (Apache Spark v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| Before the batch is processed&amp;lt;ref name=&amp;quot;commitlog&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/checkpointing/CommitLog.scala |title=CommitLog.scala (Apache Spark 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;code&amp;gt;commits/&amp;lt;/code&amp;gt;&lt;br /&gt;
| The commit log: one file per batch that marks the batch as complete&amp;lt;ref name=&amp;quot;commitlog&amp;quot; /&amp;gt;&lt;br /&gt;
| After the batch succeeds, before the next batch starts&amp;lt;ref name=&amp;quot;commitlog&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;state/&amp;lt;/code&amp;gt;&lt;br /&gt;
| Versioned files of the [[state store]], per stateful operator and partition&lt;br /&gt;
| At the end of each batch of a stateful query&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;metadata&amp;lt;/code&amp;gt;&lt;br /&gt;
| The query&amp;#039;s unique id, which stays the same across restarts&amp;lt;ref name=&amp;quot;streammeta&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/runtime/StreamMetadata.scala |title=StreamMetadata.scala (Apache Spark v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| When the query first starts&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The order of writes is what makes recovery work. For each batch, Spark writes the batch&amp;#039;s offsets to the offset log, processes the batch, and then writes the batch to the commit log.&amp;lt;ref name=&amp;quot;commitlog&amp;quot; /&amp;gt; On restart, a batch that has an offset entry but no commit entry is run again with exactly the same offsets. Combined with a replayable source and an idempotent or transactional sink, this gives the end-to-end guarantee described in [[Exactly-once semantics]].&lt;br /&gt;
&lt;br /&gt;
Spark keeps a bounded history. &amp;lt;code&amp;gt;spark.sql.streaming.minBatchesToRetain&amp;lt;/code&amp;gt; (default 100, since 2.1.1) is the minimum number of batches that stay recoverable; state, offset and commit log files older than that are eligible for cleanup.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala |title=SQLConf.scala (Apache Spark v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The checkpoint location must be a path in an HDFS-compatible, fault-tolerant file system, such as HDFS or an object store.&amp;lt;ref name=&amp;quot;ss-ckpt&amp;quot; /&amp;gt; &amp;lt;code&amp;gt;spark.sql.streaming.checkpointLocation&amp;lt;/code&amp;gt; sets a default parent directory for queries that do not set the option.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What is safe to change between restarts? ==&lt;br /&gt;
The Spark guide lists which query changes are allowed when restarting from the same checkpoint. &amp;quot;Allowed&amp;quot; means the query starts, but whether the result is well defined depends on the change; &amp;quot;not allowed&amp;quot; means the restart is likely to fail with unpredictable errors.&amp;lt;ref name=&amp;quot;ss-changes&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#recovery-semantics-after-changes-in-a-streaming-query |title=Structured Streaming: Recovery Semantics after Changes in a Streaming Query (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;
! Change !! Verdict !! Example&lt;br /&gt;
|-&lt;br /&gt;
| Number or type of input sources || Not allowed || Adding a second Kafka source&lt;br /&gt;
|-&lt;br /&gt;
| Source rate limits || Allowed || Adding &amp;lt;code&amp;gt;maxOffsetsPerTrigger&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Subscribed topics or input files || Generally not allowed || &amp;lt;code&amp;gt;subscribe&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;topic&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;newTopic&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Sink type || Some combinations || File sink to Kafka sink is allowed; Kafka sink to file sink is not&lt;br /&gt;
|-&lt;br /&gt;
| File sink output directory || Not allowed || Changing &amp;lt;code&amp;gt;path&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Kafka sink topic || Allowed || Changing &amp;lt;code&amp;gt;topic&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Filters and projections || Allowed; a different output schema only if the sink accepts it || Adding a &amp;lt;code&amp;gt;where&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Stateful operators (aggregation keys or aggregates, deduplication columns, stream-stream join type or keys, user state schema) || Not allowed || Adding a grouping column&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Some configurations are also fixed for the life of a checkpoint. The Spark notes name &amp;lt;code&amp;gt;spark.sql.shuffle.partitions&amp;lt;/code&amp;gt; (state is hash-partitioned by key, so the number of state partitions cannot change), &amp;lt;code&amp;gt;spark.sql.streaming.stateStore.providerClass&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spark.sql.streaming.multipleWatermarkPolicy&amp;lt;/code&amp;gt;; to change them, start a new query with a new checkpoint.&amp;lt;ref name=&amp;quot;misc&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/additional-information.html |title=Structured Streaming: Miscellaneous Notes (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Spark stores the values of these and other state-related configurations in the offset log and reuses them on restart, whatever the session sets.&amp;lt;ref name=&amp;quot;offsetseq&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[transformWithState]] is an exception for user state: state variables can be added and removed between runs, and with &amp;lt;code&amp;gt;spark.sql.streaming.stateStore.encodingFormat&amp;lt;/code&amp;gt; set to &amp;lt;code&amp;gt;avro&amp;lt;/code&amp;gt;, fields of a state variable&amp;#039;s value can be added, removed, widened or reordered.&amp;lt;ref name=&amp;quot;tws&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/structured-streaming-transform-with-state.html#state-schema-evolution |title=Structured Streaming: transformWithState, State Schema Evolution (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What happens if the checkpoint is deleted? ==&lt;br /&gt;
Without its checkpoint, a query starts as a new query: sources start from their configured starting position, state is empty, and batch ids start again from 0. Sinks that deduplicate by batch id must be told. The [[Delta Lake]] documentation warns that a query restarted with a new checkpoint must use a different &amp;lt;code&amp;gt;txnAppId&amp;lt;/code&amp;gt; in [[foreachBatch]] writes; otherwise its writes are ignored as duplicates.&amp;lt;ref name=&amp;quot;delta&amp;quot;&amp;gt;{{Cite web |url=https://docs.delta.io/latest/delta-streaming.html |title=Table streaming reads and writes |publisher=Delta Lake (Linux Foundation) |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Delta Lake&amp;#039;s &amp;lt;code&amp;gt;VACUUM&amp;lt;/code&amp;gt; skips directories whose names begin with an underscore, so a checkpoint can be kept next to the table it writes, for example in &amp;lt;code&amp;gt;&amp;amp;lt;table&amp;amp;gt;/_checkpoints&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;delta&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
(spark.readStream.format(&amp;quot;kafka&amp;quot;)&lt;br /&gt;
    .option(&amp;quot;kafka.bootstrap.servers&amp;quot;, &amp;quot;broker:9092&amp;quot;)&lt;br /&gt;
    .option(&amp;quot;subscribe&amp;quot;, &amp;quot;orders&amp;quot;)&lt;br /&gt;
    .option(&amp;quot;maxOffsetsPerTrigger&amp;quot;, 100000)   # safe to change between restarts&lt;br /&gt;
    .load()&lt;br /&gt;
    .writeStream&lt;br /&gt;
    .option(&amp;quot;checkpointLocation&amp;quot;, &amp;quot;s3a://lake/checkpoints/orders_bronze&amp;quot;)&lt;br /&gt;
    .toTable(&amp;quot;main.sales.orders_bronze&amp;quot;))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison with Flink checkpoints ==&lt;br /&gt;
[[Apache Flink]] also uses the word checkpoint. A Flink checkpoint is a recovery mechanism for unexpected job failures; Flink creates, owns and releases it without user action, and deletes it when the user terminates the job unless retention is configured. A Flink &amp;#039;&amp;#039;&amp;#039;savepoint&amp;#039;&amp;#039;&amp;#039; is created with the same mechanism but is owned by the user and designed for portability, for example for upgrades and redeployment; the Flink documentation compares the two to backups and recovery logs in a database.&amp;lt;ref name=&amp;quot;flink-cvs&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-release-2.3/docs/ops/state/checkpoints_vs_savepoints/ |title=Checkpoints vs. Savepoints (Apache Flink 2.3) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; See [[Flink checkpoint and savepoint]].&lt;br /&gt;
&lt;br /&gt;
A Spark streaming checkpoint is closer to a retained Flink checkpoint: it is a directory the user names, it stays after the query stops, and a restarted or changed query reads it, within the limits listed above.&amp;lt;ref name=&amp;quot;ss-ckpt&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;ss-changes&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Checkpointing (Spark)]]&lt;br /&gt;
* [[State store]]&lt;br /&gt;
* [[Exactly-once semantics]]&lt;br /&gt;
* [[Structured Streaming]]&lt;br /&gt;
* [[Trigger (Structured Streaming)]]&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;br /&gt;
[[Category:Pipelines and orchestration]]&lt;/div&gt;</description>
			<pubDate>Wed, 25 Nov 2026 00:53:00 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Streaming_checkpoint</comments>
		</item>
		<item>
			<title>Streaming deduplication</title>
			<link>https://openlakehouse.io/w/index.php?title=Streaming_deduplication&amp;diff=209&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Streaming_deduplication&amp;diff=209&amp;oldid=0</guid>
			<description>&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            = Streaming deduplication&lt;br /&gt;
| also_known_as   = Stream deduplication&lt;br /&gt;
| field           = [[Stream processing]]&lt;br /&gt;
| key_parts       = Unique identifier column(s), [[watermark]], deduplication state in the [[state store]]&lt;br /&gt;
| implementations = [[Structured Streaming]]: &amp;lt;code&amp;gt;dropDuplicates&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;dropDuplicatesWithinWatermark&amp;lt;/code&amp;gt; (Spark 3.5.0 and later); [[Delta Lake]] insert-only &amp;lt;code&amp;gt;MERGE&amp;lt;/code&amp;gt; in [[foreachBatch]]&lt;br /&gt;
| related         = [[Watermark]], [[Exactly-once semantics]], [[State store]], [[Stateful stream processing]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the Spark 4.3.0 Structured Streaming programming guide (streaming deduplication, recovery semantics) and Real-time Mode guide, &amp;lt;code&amp;gt;python/pyspark/sql/dataframe.py&amp;lt;/code&amp;gt; at tag v4.3.0 of apache/spark, SPARK-42931, and the Delta Lake merge documentation}}&lt;br /&gt;
&lt;br /&gt;
In [[Apache Spark]] [[Structured Streaming]], &amp;#039;&amp;#039;&amp;#039;streaming deduplication&amp;#039;&amp;#039;&amp;#039; is removing repeated records from a stream by a unique identifier, so that each event is passed on once even if the source delivers it several times. Spark keeps the identifiers it has already seen as state; &amp;lt;code&amp;gt;dropDuplicates&amp;lt;/code&amp;gt; does this with or without a [[watermark]], and &amp;lt;code&amp;gt;dropDuplicatesWithinWatermark&amp;lt;/code&amp;gt;, added in Spark 3.5.0, deduplicates within the watermark delay when duplicates carry different event times.&amp;lt;ref name=&amp;quot;ss-dedup&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#streaming-deduplication |title=Structured Streaming: Streaming Deduplication (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;jira&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-42931 |title=SPARK-42931: dropDuplicates within watermark |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Duplicates are common in streaming because producers and connectors retry, and at-least-once delivery means a record may arrive more than once.&lt;br /&gt;
&lt;br /&gt;
== How does dropDuplicates work on a stream? ==&lt;br /&gt;
On a batch DataFrame, &amp;lt;code&amp;gt;dropDuplicates&amp;lt;/code&amp;gt; (available since Spark 1.4.0) simply drops duplicate rows. On a streaming DataFrame, it keeps the data it needs from all earlier triggers as state in order to drop duplicates in later ones.&amp;lt;ref name=&amp;quot;df&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/sql/dataframe.py |title=python/pyspark/sql/dataframe.py (Apache Spark v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The Spark guide describes two ways to use it:&amp;lt;ref name=&amp;quot;ss-dedup&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Without a watermark&amp;#039;&amp;#039;&amp;#039;, there is no bound on when a duplicate may arrive, so the query keeps state for every record it has ever seen. State grows for the life of the query.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;With a watermark&amp;#039;&amp;#039;&amp;#039;, if duplicates arrive no later than a known bound, the query sets a watermark on an event-time column and deduplicates on both the identifier and the event-time column. Spark then drops state for records older than the watermark, which bounds state.&lt;br /&gt;
&lt;br /&gt;
Records older than the watermark are dropped, to avoid any chance of emitting a duplicate.&amp;lt;ref name=&amp;quot;df&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
events = spark.readStream.table(&amp;quot;main.iot.raw_events&amp;quot;)   # columns: event_id, event_time, ...&lt;br /&gt;
&lt;br /&gt;
# Unbounded state: every event_id is remembered&lt;br /&gt;
dedup_all = events.dropDuplicates([&amp;quot;event_id&amp;quot;])&lt;br /&gt;
&lt;br /&gt;
# Bounded state: event_id plus event_time, cleaned by the watermark&lt;br /&gt;
dedup_bounded = (events&lt;br /&gt;
    .withWatermark(&amp;quot;event_time&amp;quot;, &amp;quot;10 seconds&amp;quot;)&lt;br /&gt;
    .dropDuplicates([&amp;quot;event_id&amp;quot;, &amp;quot;event_time&amp;quot;]))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What is dropDuplicatesWithinWatermark? ==&lt;br /&gt;
The bounded form of &amp;lt;code&amp;gt;dropDuplicates&amp;lt;/code&amp;gt; works only if the event time is part of the identity of a record, so that true duplicates share it. Sometimes they do not, for example when a non-idempotent writer sets the event time at write time and a retried write gets a new one. &amp;lt;code&amp;gt;dropDuplicatesWithinWatermark&amp;lt;/code&amp;gt; handles this case: it deduplicates on the identifier alone, within the time range of the watermark.&amp;lt;ref name=&amp;quot;ss-dedup&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
dedup = (events&lt;br /&gt;
    .withWatermark(&amp;quot;event_time&amp;quot;, &amp;quot;10 hours&amp;quot;)&lt;br /&gt;
    .dropDuplicatesWithinWatermark([&amp;quot;event_id&amp;quot;]))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The guarantee is that events are deduplicated as long as the distance between the earliest and the latest copy is smaller than the watermark delay, so the delay should be longer than the largest time difference expected between duplicates. A watermark is required, and the operator works only on streaming DataFrames. Data older than the watermark is dropped.&amp;lt;ref name=&amp;quot;df&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;ss-dedup&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== dropDuplicates vs dropDuplicatesWithinWatermark ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! !! &amp;lt;code&amp;gt;dropDuplicates&amp;lt;/code&amp;gt; without watermark !! &amp;lt;code&amp;gt;dropDuplicates&amp;lt;/code&amp;gt; with watermark !! &amp;lt;code&amp;gt;dropDuplicatesWithinWatermark&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Available since&lt;br /&gt;
| Spark 1.4.0&amp;lt;ref name=&amp;quot;df&amp;quot; /&amp;gt;&lt;br /&gt;
| Spark 1.4.0&amp;lt;ref name=&amp;quot;df&amp;quot; /&amp;gt;&lt;br /&gt;
| Spark 3.5.0&amp;lt;ref name=&amp;quot;jira&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Key&lt;br /&gt;
| Identifier columns&amp;lt;ref name=&amp;quot;ss-dedup&amp;quot; /&amp;gt;&lt;br /&gt;
| Identifier and event-time columns&amp;lt;ref name=&amp;quot;ss-dedup&amp;quot; /&amp;gt;&lt;br /&gt;
| Identifier columns only&amp;lt;ref name=&amp;quot;ss-dedup&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! State&lt;br /&gt;
| Unbounded&amp;lt;ref name=&amp;quot;ss-dedup&amp;quot; /&amp;gt;&lt;br /&gt;
| Bounded by the watermark&amp;lt;ref name=&amp;quot;ss-dedup&amp;quot; /&amp;gt;&lt;br /&gt;
| Bounded by the watermark&amp;lt;ref name=&amp;quot;ss-dedup&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Duplicates with different event times&lt;br /&gt;
| Removed&amp;lt;ref name=&amp;quot;ss-dedup&amp;quot; /&amp;gt;&lt;br /&gt;
| Not removed, because event time is part of the key&lt;br /&gt;
| Removed if within the watermark delay&amp;lt;ref name=&amp;quot;df&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Batch DataFrames&lt;br /&gt;
| Supported&amp;lt;ref name=&amp;quot;df&amp;quot; /&amp;gt;&lt;br /&gt;
| Supported&amp;lt;ref name=&amp;quot;df&amp;quot; /&amp;gt;&lt;br /&gt;
| Streaming only&amp;lt;ref name=&amp;quot;df&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Real-time Mode (Spark 4.3.0)&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; | Supported&amp;lt;ref name=&amp;quot;rtm&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/real-time-mode.html |title=Real-time Mode (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| Not supported&amp;lt;ref name=&amp;quot;rtm&amp;quot; /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The deduplication columns are part of the query&amp;#039;s state schema: changing their number or type is not allowed between restarts from the same [[streaming checkpoint]].&amp;lt;ref name=&amp;quot;ss-changes&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#recovery-semantics-after-changes-in-a-streaming-query |title=Structured Streaming: Recovery Semantics after Changes in a Streaming Query (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The plain &amp;lt;code&amp;gt;distinct&amp;lt;/code&amp;gt; operation is not supported on streaming DataFrames.&amp;lt;ref name=&amp;quot;ss-unsup&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#unsupported-operations |title=Structured Streaming: Unsupported Operations (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Deduplicating against a table ==&lt;br /&gt;
&amp;lt;code&amp;gt;dropDuplicates&amp;lt;/code&amp;gt; only removes duplicates that the query itself sees within its state. To avoid inserting a record that is already in the target table, for example one written by an earlier query or a backfill, the [[Delta Lake]] documentation uses an insert-only &amp;lt;code&amp;gt;MERGE&amp;lt;/code&amp;gt; inside [[foreachBatch]], which inserts only rows whose key is not yet in the table.&amp;lt;ref name=&amp;quot;delta-merge&amp;quot;&amp;gt;{{Cite web |url=https://docs.delta.io/latest/delta-update.html#upsert-from-streaming-queries-using-foreachbatch |title=Table deletes, updates, and merges: Upsert from streaming queries using foreachBatch |publisher=Delta Lake (Linux 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 delta.tables import DeltaTable&lt;br /&gt;
&lt;br /&gt;
target = DeltaTable.forName(spark, &amp;quot;main.iot.events&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
def insert_new(batch_df, batch_id):&lt;br /&gt;
    (target.alias(&amp;quot;t&amp;quot;)&lt;br /&gt;
        .merge(batch_df.dropDuplicates([&amp;quot;event_id&amp;quot;]).alias(&amp;quot;s&amp;quot;),&lt;br /&gt;
               &amp;quot;t.event_id = s.event_id&amp;quot;)&lt;br /&gt;
        .whenNotMatchedInsertAll()&lt;br /&gt;
        .execute())&lt;br /&gt;
&lt;br /&gt;
(dedup_bounded.writeStream&lt;br /&gt;
    .foreachBatch(insert_new)&lt;br /&gt;
    .option(&amp;quot;checkpointLocation&amp;quot;, &amp;quot;/checkpoints/iot_events&amp;quot;)&lt;br /&gt;
    .start())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Deduplication in the stream and an insert-only merge into the table can be combined: the first bounds the work per batch, the second protects the table across queries and restarts.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Watermark]]&lt;br /&gt;
* [[Exactly-once semantics]]&lt;br /&gt;
* [[foreachBatch]]&lt;br /&gt;
* [[State store]]&lt;br /&gt;
* [[Stateful stream processing]]&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;br /&gt;
[[Category:Pipelines and orchestration]]&lt;/div&gt;</description>
			<pubDate>Wed, 25 Nov 2026 00:53:00 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Streaming_deduplication</comments>
		</item>
		<item>
			<title>Speculative execution</title>
			<link>https://openlakehouse.io/w/index.php?title=Speculative_execution&amp;diff=203&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Speculative_execution&amp;diff=203&amp;oldid=0</guid>
			<description>&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            = Speculative execution&lt;br /&gt;
| also_known_as   = Speculation, speculative tasks, &amp;lt;code&amp;gt;spark.speculation&amp;lt;/code&amp;gt;&lt;br /&gt;
| field           = Distributed data processing&lt;br /&gt;
| key_parts       = Straggler detection, duplicate task attempts, first attempt wins, output commit coordination&lt;br /&gt;
| implementations = [[Apache Spark]]&lt;br /&gt;
| related         = [[Data skew]], [[Accumulator]], [[Exactly-once semantics]], [[Executor]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (docs/configuration.md, docs/rdd-programming-guide.md, docs/streaming/apis-on-dataframes-and-datasets.md, docs/sql-performance-tuning.md, core scheduler/TaskSetManager.scala, core scheduler/OutputCommitCoordinator.scala, sql adaptive/OptimizeSkewedJoin.scala) and the Delta Lake protocol at tag v4.4.1}}&lt;br /&gt;
&lt;br /&gt;
In [[Apache Spark]], &amp;#039;&amp;#039;&amp;#039;speculative execution&amp;#039;&amp;#039;&amp;#039; is a scheduler feature that launches a second copy of a task that is running much slower than the other tasks in its stage, on another [[executor]], and uses whichever copy finishes first. It targets stragglers caused by a slow machine or disk, and is off by default (&amp;lt;code&amp;gt;spark.speculation=false&amp;lt;/code&amp;gt;).&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; Because the same task can run twice, any side effect that is not idempotent can happen twice.&lt;br /&gt;
&lt;br /&gt;
== How does speculation decide which tasks to copy? ==&lt;br /&gt;
Spark checks for slow tasks every &amp;lt;code&amp;gt;spark.speculation.interval&amp;lt;/code&amp;gt;. Speculation for a stage starts only after a fraction &amp;lt;code&amp;gt;spark.speculation.quantile&amp;lt;/code&amp;gt; of its tasks has finished; then a running task is a candidate if it is &amp;lt;code&amp;gt;spark.speculation.multiplier&amp;lt;/code&amp;gt; times slower than the median of the finished tasks and has run at least &amp;lt;code&amp;gt;spark.speculation.minTaskRuntime&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Setting !! Default !! Since !! Meaning&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.speculation&amp;lt;/code&amp;gt; || false || 0.6.0 || Turn speculation on&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.speculation.interval&amp;lt;/code&amp;gt; || 100ms || 0.6.0 || How often to look for slow tasks&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.speculation.multiplier&amp;lt;/code&amp;gt; || 3 || 0.6.0 || How many times slower than the median a task must be&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.speculation.quantile&amp;lt;/code&amp;gt; || 0.9 || 0.6.0 || Fraction of tasks that must be done before speculating in a stage&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.speculation.minTaskRuntime&amp;lt;/code&amp;gt; || 100ms || 3.2.0 || Minimum run time before a task can be speculated&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.speculation.task.duration.threshold&amp;lt;/code&amp;gt; || none || 3.0.0 || Speculate stages with few tasks once a task runs longer than this&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.speculation.efficiency.enabled&amp;lt;/code&amp;gt; || true || 3.4.0 || Speculate only tasks that are inefficient by data processing rate or duration&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;small&amp;gt;Source: Spark 4.3.0 configuration reference.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The duration threshold helps stages that have no more tasks than one executor has slots, where the median rule has too few finished tasks to work with.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt; With &amp;lt;code&amp;gt;spark.speculation.efficiency.enabled&amp;lt;/code&amp;gt;, a task is speculated only if its data processing rate is below the stage average times a multiplier, or if its duration exceeds the threshold times &amp;lt;code&amp;gt;spark.speculation.efficiency.longRunTaskFactor&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What happens when a speculative copy finishes? ==&lt;br /&gt;
When one attempt of a task succeeds, the scheduler kills the other running attempts of the same task, with the reason &amp;quot;another attempt succeeded&amp;quot;.&amp;lt;ref name=&amp;quot;tsm&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/scheduler/TaskSetManager.scala |title=TaskSetManager.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The killed attempt may have already done part of its work.&lt;br /&gt;
&lt;br /&gt;
For file output written through Spark&amp;#039;s commit protocol, the &amp;#039;&amp;#039;&amp;#039;output commit coordinator&amp;#039;&amp;#039;&amp;#039; on the driver decides which attempt may commit each partition, with a &amp;quot;first committer wins&amp;quot; policy. This keeps two attempts from both committing their output files.&amp;lt;ref name=&amp;quot;occ&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/scheduler/OutputCommitCoordinator.scala |title=OutputCommitCoordinator.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Table formats add their own commit on top. In [[Delta Lake]], a table snapshot consists of the &amp;lt;code&amp;gt;add&amp;lt;/code&amp;gt; actions in committed log entries, so a data file written by an attempt whose transaction never committed is not part of the table.&amp;lt;ref name=&amp;quot;delta&amp;quot;&amp;gt;{{Cite web |url=https://github.com/delta-io/delta/blob/v4.4.1/PROTOCOL.md#action-reconciliation |title=Delta Transaction Log Protocol: Action Reconciliation (v4.4.1) |publisher=Delta Lake (Linux Foundation) |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Side effects with non-idempotent writes ==&lt;br /&gt;
Code that writes to an external system directly from tasks is outside the commit coordinator. With speculation on, two attempts of the same task can run that code at the same time, and the killed attempt may have written some or all of its data before it was stopped.&amp;lt;ref name=&amp;quot;tsm&amp;quot; /&amp;gt; Examples are:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;foreach&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;foreachPartition&amp;lt;/code&amp;gt; code that inserts rows into a database, posts to an HTTP API or sends messages to a queue;&lt;br /&gt;
* UDFs with side effects, such as writing a log record per row;&lt;br /&gt;
* [[Accumulator]] updates inside transformations, which the Spark docs say may be applied more than once when tasks are re-executed.&amp;lt;ref name=&amp;quot;rddguide&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/rdd-programming-guide.html#accumulators |title=RDD Programming Guide: Accumulators (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same duplication can happen without speculation, from task retries, so code that writes externally should be idempotent anyway: use upserts or &amp;lt;code&amp;gt;MERGE&amp;lt;/code&amp;gt; keyed on a stable ID, or write to a staging location and commit once from the driver. In [[Structured Streaming]], &amp;lt;code&amp;gt;foreachBatch&amp;lt;/code&amp;gt; gives only at-least-once write guarantees by default, and the docs suggest using the batch ID passed to the function to deduplicate output.&amp;lt;ref name=&amp;quot;ss&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html |title=Structured Streaming Programming Guide: APIs on DataFrames and Datasets (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; See [[Exactly-once semantics]].&lt;br /&gt;
&lt;br /&gt;
== When to use speculation ==&lt;br /&gt;
Speculation helps when tasks are slow because of the machine they run on, for example a node with a failing disk or a noisy neighbour. It does not help with [[data skew]], because a copy of a skewed task has the same amount of data and is just as slow. For skewed joins, Spark&amp;#039;s [[Adaptive Query Execution]] can split large partitions instead.&amp;lt;ref name=&amp;quot;perf&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-performance-tuning.html |title=Performance Tuning (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; In Spark 4.3.0 this applies to sort-merge and shuffled hash joins, and only to a side the join type allows to split: the left side of inner, cross, left semi, left anti and left outer joins, and the right side of inner, cross and right outer joins. It also applies to the streamed side of a broadcast hash join when &amp;lt;code&amp;gt;spark.sql.adaptive.localShuffleReader.enabled&amp;lt;/code&amp;gt; is false. It does not split skewed aggregations, windows or full outer joins; for those, see [[salting]].&amp;lt;ref name=&amp;quot;skewrule&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/OptimizeSkewedJoin.scala |title=OptimizeSkewedJoin.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Each speculative copy also uses a task slot that another task could have used.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
spark.speculation                          true&lt;br /&gt;
spark.speculation.multiplier               3&lt;br /&gt;
spark.speculation.quantile                 0.9&lt;br /&gt;
spark.speculation.minTaskRuntime           30s&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Data skew]]&lt;br /&gt;
* [[Accumulator]]&lt;br /&gt;
* [[Exactly-once semantics]]&lt;br /&gt;
* [[Executor]]&lt;br /&gt;
* [[Dynamic allocation]]&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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:59 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Speculative_execution</comments>
		</item>
		<item>
			<title>Spill (memory)</title>
			<link>https://openlakehouse.io/w/index.php?title=Spill_(memory)&amp;diff=204&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Spill_(memory)&amp;diff=204&amp;oldid=0</guid>
			<description>&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            = Spill&lt;br /&gt;
| also_known_as   = Spill to disk, memory spill&lt;br /&gt;
| field           = Distributed data processing&lt;br /&gt;
| key_parts       = Execution memory, spill files on local disk, spill metrics&lt;br /&gt;
| implementations = [[Apache Spark]], [[Trino]], [[Apache Flink]]&lt;br /&gt;
| related         = [[Spark memory management]], [[Shuffle]], [[Data skew]], [[Executor]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (docs/web-ui.md, docs/monitoring.md, docs/tuning.md, docs/configuration.md, docs/rdd-programming-guide.md), the Trino 484 docs (Spill to disk, Spilling properties) and the Apache Flink 2.3 docs (TaskManager memory, memory tuning, configuration)}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Spill&amp;#039;&amp;#039;&amp;#039; is the act of a query engine writing intermediate data from memory to local disk while an operation runs, because the data for a sort, aggregation, join or shuffle does not fit in the memory the operation is allowed to use. In [[Apache Spark]], a task spills when its share of execution memory is full; the task keeps running, reads the spilled data back later, and finishes slower instead of failing.&amp;lt;ref name=&amp;quot;rddguide&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/rdd-programming-guide.html#shuffle-operations |title=RDD Programming Guide: Shuffle operations (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;tuning&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/tuning.html |title=Tuning Spark (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; [[Trino]] and [[Apache Flink]] spill too, under different rules.&lt;br /&gt;
&lt;br /&gt;
== What is spill in Apache Spark? ==&lt;br /&gt;
Spark divides each executor&amp;#039;s unified memory region into execution memory, used for shuffles, joins, sorts and aggregations, and storage memory, used for cached data.&amp;lt;ref name=&amp;quot;tuning&amp;quot; /&amp;gt; Shuffle operations build in-memory structures to organize records; when these do not fit, Spark spills them to disk, which adds disk I/O and garbage collection.&amp;lt;ref name=&amp;quot;rddguide&amp;quot; /&amp;gt; Spill files go to the scratch directories in &amp;lt;code&amp;gt;spark.local.dir&amp;lt;/code&amp;gt; (default &amp;lt;code&amp;gt;/tmp&amp;lt;/code&amp;gt;), and data spilled during shuffles is compressed by default (&amp;lt;code&amp;gt;spark.shuffle.spill.compress&amp;lt;/code&amp;gt;).&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;
Spill is not the same as shuffle files. Shuffle files are the normal output of the map side of a [[shuffle]], written by every shuffle; spill files are temporary overflow inside one task. A shuffle with no spill still writes shuffle files.&amp;lt;ref name=&amp;quot;rddguide&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Spill metrics in the Spark UI ==&lt;br /&gt;
The Spark UI reports spill in two places.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Stage page.&amp;#039;&amp;#039;&amp;#039; The task summary and the per-executor table show &amp;#039;&amp;#039;&amp;#039;Shuffle spill (memory)&amp;#039;&amp;#039;&amp;#039;, the size of the spilled data in its deserialized form in memory, and &amp;#039;&amp;#039;&amp;#039;Shuffle spill (disk)&amp;#039;&amp;#039;&amp;#039;, the size of its serialized form on disk.&amp;lt;ref name=&amp;quot;webui&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/web-ui.html |title=Web UI (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The memory figure is usually the larger of the two, because the serialized and compressed form on disk is smaller.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;SQL tab.&amp;#039;&amp;#039;&amp;#039; Operators such as &amp;lt;code&amp;gt;Sort&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;HashAggregate&amp;lt;/code&amp;gt; show a &amp;lt;code&amp;gt;spill size&amp;lt;/code&amp;gt; metric (bytes spilled to disk by that operator) next to &amp;lt;code&amp;gt;peak memory&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;webui&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same numbers are in the task metrics of the REST API and event log as &amp;lt;code&amp;gt;memoryBytesSpilled&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;diskBytesSpilled&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;monitoring&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/monitoring.html |title=Monitoring and Instrumentation (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What causes spill? ==&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Too few shuffle partitions.&amp;#039;&amp;#039;&amp;#039; Each task gets a larger slice of data. &amp;lt;code&amp;gt;spark.sql.shuffle.partitions&amp;lt;/code&amp;gt; defaults to 200; with [[Adaptive Query Execution]] on, Spark starts from that number and coalesces small partitions.&amp;lt;ref name=&amp;quot;perf&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-performance-tuning.html |title=Performance Tuning (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;[[Data skew]].&amp;#039;&amp;#039;&amp;#039; One task gets most of the data, so only that task spills.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Little execution memory per task.&amp;#039;&amp;#039;&amp;#039; All running tasks on an executor share its execution memory, so more cores per executor means less memory per task. The region size is set by &amp;lt;code&amp;gt;spark.executor.memory&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spark.memory.fraction&amp;lt;/code&amp;gt; (default 0.6).&amp;lt;ref name=&amp;quot;tuning&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Large cached datasets.&amp;#039;&amp;#039;&amp;#039; Cached blocks occupy storage memory. Execution can evict them, but only down to &amp;lt;code&amp;gt;spark.memory.storageFraction&amp;lt;/code&amp;gt; (default 0.5) of the region.&amp;lt;ref name=&amp;quot;tuning&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Common fixes follow from the causes: more shuffle partitions, fixing skew, more memory per executor or fewer cores per executor, and caching less. A small amount of spill is normal; it matters when spill dominates a stage&amp;#039;s run time.&lt;br /&gt;
&lt;br /&gt;
== Spill compared across engines ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! !! Apache Spark !! Trino !! Apache Flink&lt;br /&gt;
|-&lt;br /&gt;
! Default behaviour&lt;br /&gt;
| Always on; tasks spill execution data when memory runs out&amp;lt;ref name=&amp;quot;rddguide&amp;quot; /&amp;gt;&lt;br /&gt;
| Off (&amp;lt;code&amp;gt;spill-enabled&amp;lt;/code&amp;gt; defaults to false); without it, queries over the memory limits are killed&amp;lt;ref name=&amp;quot;trinospillprops&amp;quot;&amp;gt;{{Cite web |url=https://trino.io/docs/current/admin/properties-spilling.html |title=Spilling properties (Trino 484) |publisher=Trino Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;trinospill&amp;quot;&amp;gt;{{Cite web |url=https://trino.io/docs/current/admin/spill.html |title=Spill to disk (Trino 484) |publisher=Trino Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| For batch jobs, Flink spills to disk when managed memory is not enough&amp;lt;ref name=&amp;quot;flinktuning&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-stable/docs/deployment/memory/mem_tuning/ |title=Memory tuning guide (Apache Flink 2.3) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Memory that spills&lt;br /&gt;
| Execution memory in the executor&amp;#039;s unified region (heap, or off-heap if enabled)&amp;lt;ref name=&amp;quot;tuning&amp;quot; /&amp;gt;&lt;br /&gt;
| Revocable memory, which does not count toward query limits and which the memory manager can take back&amp;lt;ref name=&amp;quot;trinospill&amp;quot; /&amp;gt;&lt;br /&gt;
| Managed memory, native (off-heap) memory used for sorting, hash tables and cached intermediate results; by default 0.4 of total Flink memory (&amp;lt;code&amp;gt;taskmanager.memory.managed.fraction&amp;lt;/code&amp;gt;)&amp;lt;ref name=&amp;quot;flinkmem&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-stable/docs/deployment/memory/mem_setup_tm/ |title=Set up TaskManager Memory (Apache Flink 2.3) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;flinkconfig&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-stable/docs/deployment/config/ |title=Configuration (Apache Flink 2.3) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Where spill goes&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.local.dir&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;spiller-spill-path&amp;lt;/code&amp;gt;, which must be set when spilling is on; a comma-separated list spreads spill over several disks&amp;lt;ref name=&amp;quot;trinospillprops&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;io.tmp.dirs&amp;lt;/code&amp;gt; (default: the JVM temporary directory), which also holds RocksDB files and cached jars&amp;lt;ref name=&amp;quot;flinkconfig&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Operations that spill&lt;br /&gt;
| Shuffle, sort, aggregation and join structures&amp;lt;ref name=&amp;quot;rddguide&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;webui&amp;quot; /&amp;gt;&lt;br /&gt;
| Joins, aggregations, &amp;lt;code&amp;gt;ORDER BY&amp;lt;/code&amp;gt; and window functions&amp;lt;ref name=&amp;quot;trinospill&amp;quot; /&amp;gt;&lt;br /&gt;
| Batch algorithms such as external sorts and hash joins&amp;lt;ref name=&amp;quot;flinkconfig&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Status&lt;br /&gt;
| Core part of execution&lt;br /&gt;
| The Trino docs call spill to disk legacy functionality and point to fault-tolerant execution with the task retry policy instead&amp;lt;ref name=&amp;quot;trinospill&amp;quot; /&amp;gt;&lt;br /&gt;
| Core part of batch execution&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In Trino, spill is enabled per cluster and is limited by &amp;lt;code&amp;gt;max-spill-per-node&amp;lt;/code&amp;gt; (all queries on a node) and &amp;lt;code&amp;gt;query-max-spill-per-node&amp;lt;/code&amp;gt; (one query on a node), both 100GB by default.&amp;lt;ref name=&amp;quot;trinospillprops&amp;quot; /&amp;gt; The Trino docs warn that a query forced to spill may run orders of magnitude longer than one that runs in memory, and that spill does not guarantee that every memory-intensive query will succeed.&amp;lt;ref name=&amp;quot;trinospill&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Spark memory management]]&lt;br /&gt;
* [[Shuffle]]&lt;br /&gt;
* [[Data skew]]&lt;br /&gt;
* [[Executor]]&lt;br /&gt;
* [[Garbage collection in 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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:59 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Spill_(memory)</comments>
		</item>
		<item>
			<title>SQL pipe syntax</title>
			<link>https://openlakehouse.io/w/index.php?title=SQL_pipe_syntax&amp;diff=205&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=SQL_pipe_syntax&amp;diff=205&amp;oldid=0</guid>
			<description>&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            = SQL pipe syntax&lt;br /&gt;
| also_known_as   = Pipe syntax, operator pipe syntax, &amp;lt;code&amp;gt;&amp;amp;#124;&amp;gt;&amp;lt;/code&amp;gt; syntax&lt;br /&gt;
| field           = SQL query languages&lt;br /&gt;
| key_parts       = &amp;lt;code&amp;gt;FROM&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;TABLE&amp;lt;/code&amp;gt; source, pipe operator &amp;lt;code&amp;gt;&amp;amp;#124;&amp;gt;&amp;lt;/code&amp;gt;, operators &amp;lt;code&amp;gt;SELECT&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;EXTEND&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;SET&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DROP&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;AS&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;WHERE&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;AGGREGATE&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;JOIN&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ORDER BY&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;LIMIT&amp;lt;/code&amp;gt;&lt;br /&gt;
| implementations = [[Apache Spark]], GoogleSQL (BigQuery), ZetaSQL&lt;br /&gt;
| related         = [[Spark SQL scripting]], [[Spark SQL ANSI mode]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (docs/sql-pipe-syntax.md, SqlBaseParser.g4, SQLConf.scala), SPARK-49555, the Spark 4.0.0 and 4.2.0 release notes, the PVLDB 17(12) paper by Shute et al. and the BigQuery pipe syntax reference}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;SQL pipe syntax&amp;#039;&amp;#039;&amp;#039; is an extension of SQL in which a query is written as a sequence of operators joined by the pipe symbol &amp;lt;code&amp;gt;|&amp;gt;&amp;lt;/code&amp;gt;, each operator taking the table produced by the previous one, so that the query reads top to bottom in the order of its logical transformations. [[Apache Spark]] SQL supports pipe syntax since Spark 4.0.0 (SPARK-49555).&amp;lt;ref name=&amp;quot;r400&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4-0-0.html |title=Spark Release 4.0.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;doc&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-pipe-syntax.html |title=SQL Pipe Syntax (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Pipe syntax keeps standard SQL working unchanged: a query can use standard clauses, pipe operators, or both.&amp;lt;ref name=&amp;quot;doc&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Where does SQL pipe syntax come from? ==&lt;br /&gt;
Pipe syntax was described by Jeff Shute and other Google engineers in the paper &amp;quot;SQL Has Problems. We Can Fix Them: Pipe Syntax In SQL&amp;quot;, published in the Proceedings of the VLDB Endowment, volume 17, issue 12 (2024). The paper presents it as an addition to GoogleSQL, Google&amp;#039;s SQL dialect, that fixes the rigid clause order of standard SQL without replacing the language.&amp;lt;ref name=&amp;quot;paper&amp;quot;&amp;gt;{{Cite web |url=https://www.vldb.org/pvldb/vol17/p4051-shute.pdf |title=SQL Has Problems. We Can Fix Them: Pipe Syntax In SQL |publisher=Proceedings of the VLDB Endowment, 17(12): 4051-4063 |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; BigQuery documents pipe syntax as an extension to GoogleSQL, and Google announced that it would be available to all BigQuery users by default from 4 February 2025.&amp;lt;ref name=&amp;quot;bq&amp;quot;&amp;gt;{{Cite web |url=https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/pipe-syntax |title=Pipe syntax (BigQuery documentation) |publisher=Google Cloud |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;bqblog&amp;quot;&amp;gt;{{Cite web |url=https://cloud.google.com/blog/products/data-analytics/simplify-your-sql-with-pipe-syntax-in-bigquery-and-cloud-logging |title=Simplify your SQL with pipe syntax in BigQuery and Cloud Logging |publisher=Google Cloud Blog |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The Spark ticket SPARK-49555 links to the paper and to the open source ZetaSQL implementation.&amp;lt;ref name=&amp;quot;jira&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-49555 |title=SPARK-49555: SQL Pipe Syntax |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does pipe syntax work in Spark SQL? ==&lt;br /&gt;
A pipe query in Spark SQL usually starts with &amp;lt;code&amp;gt;FROM table_name&amp;lt;/code&amp;gt;, which Spark accepts as a standalone query equivalent to &amp;lt;code&amp;gt;TABLE table_name&amp;lt;/code&amp;gt;. Any number of pipe operators can follow, in any order, each starting with &amp;lt;code&amp;gt;|&amp;gt;&amp;lt;/code&amp;gt; and one or more SQL keywords.&amp;lt;ref name=&amp;quot;doc&amp;quot; /&amp;gt; Pipe operators can also be appended to the end of any ordinary Spark SQL query.&amp;lt;ref name=&amp;quot;doc&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spark&amp;#039;s documentation states several invariants. Each operator works the same way on its input regardless of how that input was computed. For a valid chain of N operators, the first M operators (M ≤ N) also form a valid query, which lets a user run a prefix of a query while debugging. Subqueries, views and DDL or DML statements can contain queries in either syntax.&amp;lt;ref name=&amp;quot;doc&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Pipe syntax is controlled by &amp;lt;code&amp;gt;spark.sql.operatorPipeSyntaxEnabled&amp;lt;/code&amp;gt;, added in Spark 4.0.0 and &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; by default in Spark 4.3.0.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala |title=SQLConf.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Since Spark 4.2.0 a single &amp;lt;code&amp;gt;|&amp;lt;/code&amp;gt; can also be used as the pipe token (SPARK-51518). This is governed by &amp;lt;code&amp;gt;spark.sql.parser.singleCharacterPipeOperator.enabled&amp;lt;/code&amp;gt;, true by default; the parser tells a pipe apart from bitwise OR by checking whether a pipe operator keyword follows.&amp;lt;ref name=&amp;quot;r420&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4-2-0.html |title=Spark Release 4.2.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;grammar&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/api/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBaseParser.g4 |title=SqlBaseParser.g4 (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Which pipe operators does Spark SQL support? ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Operator !! What it does !! Closest standard Spark SQL&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;SELECT&amp;lt;/code&amp;gt; || Evaluates expressions over each input row || Outermost &amp;lt;code&amp;gt;SELECT&amp;lt;/code&amp;gt; of a subquery&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;EXTEND&amp;lt;/code&amp;gt; || Appends computed columns || &amp;lt;code&amp;gt;SELECT *, expr AS col&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;SET&amp;lt;/code&amp;gt; || Replaces the values of existing columns || &amp;lt;code&amp;gt;SELECT * REPLACE (expr AS col)&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;DROP&amp;lt;/code&amp;gt; || Removes columns || &amp;lt;code&amp;gt;SELECT * EXCEPT (col)&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AS&amp;lt;/code&amp;gt; || Gives the input a new table alias || Table alias&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;WHERE&amp;lt;/code&amp;gt; || Filters rows; can appear anywhere, so no separate &amp;lt;code&amp;gt;HAVING&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;QUALIFY&amp;lt;/code&amp;gt; is needed || &amp;lt;code&amp;gt;WHERE&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;HAVING&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;QUALIFY&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AGGREGATE&amp;lt;/code&amp;gt; || Aggregates, with or without &amp;lt;code&amp;gt;GROUP BY&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;SELECT ... GROUP BY&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;JOIN&amp;lt;/code&amp;gt; || Joins the input (left side) with a table argument (right side) || &amp;lt;code&amp;gt;JOIN&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ORDER BY&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;LIMIT&amp;lt;/code&amp;gt; || Sorts and limits rows || &amp;lt;code&amp;gt;ORDER BY&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;LIMIT&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;UNION&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;INTERSECT&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;EXCEPT&amp;lt;/code&amp;gt; || Set operations with another table || Same set operations&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;TABLESAMPLE&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;PIVOT&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;UNPIVOT&amp;lt;/code&amp;gt; || Sampling and reshaping || Same clauses&lt;br /&gt;
|}&lt;br /&gt;
Source: Spark 4.3.0 pipe syntax documentation.&amp;lt;ref name=&amp;quot;doc&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;AGGREGATE&amp;lt;/code&amp;gt; differs most from standard SQL. Its output holds the grouping columns first and then the aggregate columns, so the grouping expressions are not repeated in a &amp;lt;code&amp;gt;SELECT&amp;lt;/code&amp;gt; list. &amp;lt;code&amp;gt;GROUP BY&amp;lt;/code&amp;gt; ordinals refer to the columns of the input table, not to a select list.&amp;lt;ref name=&amp;quot;doc&amp;quot; /&amp;gt; In Spark 4.3.0 a pipe &amp;lt;code&amp;gt;SELECT&amp;lt;/code&amp;gt; also accepts aggregate functions and an optional &amp;lt;code&amp;gt;GROUP BY&amp;lt;/code&amp;gt;, as in &amp;lt;code&amp;gt;TABLE t |&amp;gt; SELECT a, SUM(b) AS s GROUP BY a&amp;lt;/code&amp;gt;: the grammar allows a &amp;lt;code&amp;gt;GROUP BY&amp;lt;/code&amp;gt; clause after the select list, the analyzer permits aggregate functions in &amp;lt;code&amp;gt;SELECT&amp;lt;/code&amp;gt; but rejects them in &amp;lt;code&amp;gt;EXTEND&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;SET&amp;lt;/code&amp;gt; and other pipe operators, and the Spark test suite runs such queries.&amp;lt;ref name=&amp;quot;grammar&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;pipeops&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/pipeOperators.scala |title=pipeOperators.scala (tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;pipetests&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/test/resources/sql-tests/results/pipe-operators.sql.out |title=pipe-operators.sql.out (tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The Spark 4.2.0 release notes list this change as SPARK-54292.&amp;lt;ref name=&amp;quot;r420&amp;quot; /&amp;gt; The 4.3.0 pipe syntax documentation still says that aggregate functions are not supported in a pipe &amp;lt;code&amp;gt;SELECT&amp;lt;/code&amp;gt; and should go in &amp;lt;code&amp;gt;AGGREGATE&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;doc&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
The Spark documentation rewrites query 13 of the TPC-H benchmark, which in standard SQL needs a subquery for its two levels of aggregation, as a straight sequence of operators:&amp;lt;ref name=&amp;quot;doc&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
-- Standard SQL&lt;br /&gt;
SELECT c_count, COUNT(*) AS custdist&lt;br /&gt;
FROM (&lt;br /&gt;
  SELECT c_custkey, COUNT(o_orderkey) c_count&lt;br /&gt;
  FROM customer&lt;br /&gt;
  LEFT OUTER JOIN orders ON c_custkey = o_custkey&lt;br /&gt;
    AND o_comment NOT LIKE &amp;#039;%unusual%packages%&amp;#039;&lt;br /&gt;
  GROUP BY c_custkey&lt;br /&gt;
) AS c_orders&lt;br /&gt;
GROUP BY c_count&lt;br /&gt;
ORDER BY custdist DESC, c_count DESC;&lt;br /&gt;
&lt;br /&gt;
-- The same query with pipe syntax&lt;br /&gt;
FROM customer&lt;br /&gt;
|&amp;gt; LEFT OUTER JOIN orders ON c_custkey = o_custkey&lt;br /&gt;
   AND o_comment NOT LIKE &amp;#039;%unusual%packages%&amp;#039;&lt;br /&gt;
|&amp;gt; AGGREGATE COUNT(o_orderkey) c_count&lt;br /&gt;
   GROUP BY c_custkey&lt;br /&gt;
|&amp;gt; AGGREGATE COUNT(*) AS custdist&lt;br /&gt;
   GROUP BY c_count&lt;br /&gt;
|&amp;gt; ORDER BY custdist DESC, c_count DESC;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A smaller example builds columns step by step and filters on an aggregate without &amp;lt;code&amp;gt;HAVING&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
VALUES (&amp;#039;a&amp;#039;, 10), (&amp;#039;a&amp;#039;, 5), (&amp;#039;b&amp;#039;, 3) AS t(k, v)&lt;br /&gt;
|&amp;gt; EXTEND v * 2 AS v2&lt;br /&gt;
|&amp;gt; AGGREGATE SUM(v2) AS total GROUP BY k&lt;br /&gt;
|&amp;gt; WHERE total &amp;gt; 10&lt;br /&gt;
|&amp;gt; ORDER BY total DESC;&lt;br /&gt;
-- one row: k = &amp;#039;a&amp;#039;, total = 30&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Is pipe syntax more readable? ==&lt;br /&gt;
The paper&amp;#039;s authors argue that standard SQL&amp;#039;s fixed clause order forces subqueries and &amp;quot;inside-out&amp;quot; data flow, and that operators applied in sequence are easier to read, write and extend.&amp;lt;ref name=&amp;quot;paper&amp;quot; /&amp;gt; In Spark SQL, pipe syntax also lets a computed column be used by the next operator without a lateral column alias or a subquery.&amp;lt;ref name=&amp;quot;doc&amp;quot; /&amp;gt; Pipe syntax is optional: any query can be written in standard Spark SQL, in pipe syntax or in a mix of the two, so it can be adopted one query at a time.&amp;lt;ref name=&amp;quot;doc&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Apache Spark]]&lt;br /&gt;
* [[Spark SQL scripting]]&lt;br /&gt;
* [[Spark SQL ANSI mode]]&lt;br /&gt;
* [[Spark Declarative Pipelines]]&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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:59 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:SQL_pipe_syntax</comments>
		</item>
		<item>
			<title>Stateful stream processing</title>
			<link>https://openlakehouse.io/w/index.php?title=Stateful_stream_processing&amp;diff=206&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Stateful_stream_processing&amp;diff=206&amp;oldid=0</guid>
			<description>&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            = Stateful stream processing&lt;br /&gt;
| also_known_as   = Stateful streaming&lt;br /&gt;
| field           = [[Stream processing]]&lt;br /&gt;
| key_parts       = Keyed state, timers, time-to-live (TTL), [[watermark]], fault-tolerant state storage&lt;br /&gt;
| implementations = [[Structured Streaming]] (built-in stateful operators, [[transformWithState]]), [[Apache Flink]] (keyed state, &amp;lt;code&amp;gt;KeyedProcessFunction&amp;lt;/code&amp;gt;), Kafka Streams&lt;br /&gt;
| related         = [[State store]], [[RocksDB state store]], [[Streaming checkpoint]], [[mapGroupsWithState and flatMapGroupsWithState]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the Spark 4.3.0 Structured Streaming programming guide (arbitrary stateful operations, unsupported operations) and transformWithState guide, &amp;lt;code&amp;gt;SQLConf.scala&amp;lt;/code&amp;gt; at tag v4.3.0 of apache/spark, SPARK-40925, the Databricks &amp;quot;What is stateful streaming?&amp;quot; page, and the Apache Flink 2.3 &amp;quot;Working with State&amp;quot;, &amp;quot;Process Function&amp;quot;, &amp;quot;State Backends&amp;quot; and &amp;quot;State Schema Evolution&amp;quot; pages}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Stateful stream processing&amp;#039;&amp;#039;&amp;#039; is stream processing in which the result for a record depends on information kept from earlier records, such as a running count, the last value seen for a key, or rows waiting for a join partner. The engine stores this &amp;#039;&amp;#039;&amp;#039;state&amp;#039;&amp;#039;&amp;#039;, usually partitioned by key, saves it to durable storage so it survives failures, and removes it when it is no longer needed. In [[Apache Spark]] [[Structured Streaming]], state is held in a [[state store]] and used by built-in operators (aggregations, deduplication, stream-stream joins) and by the [[transformWithState]] operator for custom logic.&amp;lt;ref name=&amp;quot;ss-store&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#state-store |title=Structured Streaming: State Store (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;tws&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/structured-streaming-transform-with-state.html |title=Structured Streaming: transformWithState (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What is the difference between stateless and stateful streaming? ==&lt;br /&gt;
A stateless query handles each record on its own: filters, projections, parsing, and joins with a static table. The only thing a stateless Structured Streaming query tracks is which input has been processed. A stateful query updates intermediate state in every batch.&amp;lt;ref name=&amp;quot;db-stateful&amp;quot;&amp;gt;{{Cite web |url=https://docs.databricks.com/aws/en/structured-streaming/stateful-streaming |title=What is stateful streaming? |publisher=Databricks |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; State makes results possible that depend on history, but it costs memory and storage, adds checkpointing time, and fixes parts of the query for the life of its checkpoint.&lt;br /&gt;
&lt;br /&gt;
== What are state, timers and TTL? ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;State&amp;#039;&amp;#039;&amp;#039; is data kept per key between records. In Spark&amp;#039;s built-in operators, the engine decides what to keep: partial aggregates per group and window, the keys already seen for deduplication, or buffered rows for a join.&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;&amp;#039;timer&amp;#039;&amp;#039;&amp;#039; is a callback that the application registers for a future time, so that it can act when nothing arrives, for example to close a session or raise an alert after silence. An event-time timer fires when the [[watermark]] passes its time; a processing-time timer fires when the wall clock does.&amp;lt;ref name=&amp;quot;flink-pf&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-release-2.3/docs/dev/datastream/operators/process_function/ |title=Process Function (Apache Flink 2.3) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Time-to-live (TTL)&amp;#039;&amp;#039;&amp;#039; makes state expire a set time after it was written, so that state for keys that go quiet does not stay forever. Both Spark and Flink measure state TTL in processing time.&amp;lt;ref name=&amp;quot;tws&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;flink-state&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-release-2.3/docs/dev/datastream/fault-tolerance/state/ |title=Working with State (Apache Flink 2.3) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does Structured Streaming handle state? ==&lt;br /&gt;
Most stateful Spark queries use built-in operators, and Spark manages their state. Streaming aggregations, &amp;lt;code&amp;gt;dropDuplicates&amp;lt;/code&amp;gt; and stream-stream joins keep state per key in the state store and use the watermark to drop state that can no longer change; see [[Watermark]], [[Streaming deduplication]] and [[Stream-stream join]].&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For logic that does not fit them, Spark has arbitrary stateful operators. &amp;lt;code&amp;gt;mapGroupsWithState&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;flatMapGroupsWithState&amp;lt;/code&amp;gt; date from Spark 2.2 and are now called legacy; since Spark 4.0, the guide encourages &amp;lt;code&amp;gt;transformWithState&amp;lt;/code&amp;gt; instead.&amp;lt;ref name=&amp;quot;ss-arb&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#arbitrary-stateful-operations |title=Structured Streaming: Arbitrary Stateful Operations (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; In transformWithState, a stateful processor class declares named state variables of three types, &amp;#039;&amp;#039;&amp;#039;ValueState&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;ListState&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;MapState&amp;#039;&amp;#039;&amp;#039;, registers timers, sets optional TTL per variable and can be seeded with an initial state DataFrame. It is available in Scala, Java and Python.&amp;lt;ref name=&amp;quot;tws&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
transformWithState timers can be listed, added and removed; a key can have several; and timers are checkpointed, so they can fire after a restart. TTL works only with &amp;lt;code&amp;gt;TimeMode.ProcessingTime&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;tws&amp;quot; /&amp;gt; The operator requires the [[RocksDB state store]].&lt;br /&gt;
&lt;br /&gt;
Since Spark 3.4.0, a query can chain several stateful operators, for example an aggregation followed by a stream-stream join, in append mode. Late records are then filtered against the watermark of the previous micro-batch; &amp;lt;code&amp;gt;spark.sql.streaming.statefulOperator.allowMultiple=false&amp;lt;/code&amp;gt; restores the earlier behavior with a single stateful operator.&amp;lt;ref name=&amp;quot;jira40925&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-40925 |title=SPARK-40925: Fix late record filtering to support chaining of stateful operators |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;sqlconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala |title=SQLConf.scala (Apache Spark v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Chaining stateful operators is not supported in update or complete [[output mode]].&amp;lt;ref name=&amp;quot;ss-unsup&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#unsupported-operations |title=Structured Streaming: Unsupported Operations (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 Flink handle state? ==&lt;br /&gt;
[[Apache Flink]]&amp;#039;s &amp;#039;&amp;#039;&amp;#039;keyed state&amp;#039;&amp;#039;&amp;#039; is scoped to the key of the current record and is available only on a &amp;lt;code&amp;gt;KeyedStream&amp;lt;/code&amp;gt;, created with &amp;lt;code&amp;gt;keyBy&amp;lt;/code&amp;gt;. The state primitives are &amp;lt;code&amp;gt;ValueState&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ListState&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ReducingState&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;AggregatingState&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;MapState&amp;lt;/code&amp;gt;, each created from a state descriptor.&amp;lt;ref name=&amp;quot;flink-state&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Flink timers are registered through the &amp;lt;code&amp;gt;TimerService&amp;lt;/code&amp;gt; of a &amp;lt;code&amp;gt;KeyedProcessFunction&amp;lt;/code&amp;gt;. When a timer fires, &amp;lt;code&amp;gt;onTimer&amp;lt;/code&amp;gt; runs with state scoped to the key that set the timer.&amp;lt;ref name=&amp;quot;flink-pf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Flink TTL is configured with a &amp;lt;code&amp;gt;StateTtlConfig&amp;lt;/code&amp;gt; on any keyed state type, with per-entry TTL for list elements and map entries. The update type (by default &amp;lt;code&amp;gt;OnCreateAndWrite&amp;lt;/code&amp;gt;) decides when the TTL is refreshed, and the visibility setting decides whether expired values that have not been cleaned up yet can still be read. Only processing-time TTL is supported.&amp;lt;ref name=&amp;quot;flink-state&amp;quot; /&amp;gt; Flink keeps state in a state backend: the heap-based &amp;lt;code&amp;gt;HashMapStateBackend&amp;lt;/code&amp;gt; by default, or the &amp;lt;code&amp;gt;EmbeddedRocksDBStateBackend&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;flink-sb&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-release-2.3/docs/ops/state/state_backends/ |title=State Backends (Apache Flink 2.3) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== transformWithState vs Flink keyed state ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! !! Spark &amp;lt;code&amp;gt;transformWithState&amp;lt;/code&amp;gt; !! Flink keyed state with &amp;lt;code&amp;gt;KeyedProcessFunction&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Programming model&lt;br /&gt;
| A &amp;lt;code&amp;gt;StatefulProcessor&amp;lt;/code&amp;gt; class with &amp;lt;code&amp;gt;init&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;handleInputRows&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;handleExpiredTimer&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;handleInitialState&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;close&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;tws&amp;quot; /&amp;gt;&lt;br /&gt;
| A &amp;lt;code&amp;gt;KeyedProcessFunction&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;processElement&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;onTimer&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;flink-pf&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Input per call&lt;br /&gt;
| All rows of a key in the micro-batch (one row in Real-time Mode)&amp;lt;ref name=&amp;quot;tws&amp;quot; /&amp;gt;&lt;br /&gt;
| One record&amp;lt;ref name=&amp;quot;flink-pf&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! State types&lt;br /&gt;
| ValueState, ListState, MapState&amp;lt;ref name=&amp;quot;tws&amp;quot; /&amp;gt;&lt;br /&gt;
| ValueState, ListState, ReducingState, AggregatingState, MapState&amp;lt;ref name=&amp;quot;flink-state&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Timers&lt;br /&gt;
| Processing-time and event-time, several per key, checkpointed&amp;lt;ref name=&amp;quot;tws&amp;quot; /&amp;gt;&lt;br /&gt;
| Processing-time and event-time through the &amp;lt;code&amp;gt;TimerService&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;flink-pf&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! TTL&lt;br /&gt;
| Per state variable, processing time only&amp;lt;ref name=&amp;quot;tws&amp;quot; /&amp;gt;&lt;br /&gt;
| Per state descriptor with &amp;lt;code&amp;gt;StateTtlConfig&amp;lt;/code&amp;gt;, processing time only, per entry for collections&amp;lt;ref name=&amp;quot;flink-state&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Storage&lt;br /&gt;
| RocksDB state store, required&amp;lt;ref name=&amp;quot;tws&amp;quot; /&amp;gt;&lt;br /&gt;
| Heap (&amp;lt;code&amp;gt;HashMapStateBackend&amp;lt;/code&amp;gt;, default) or RocksDB&amp;lt;ref name=&amp;quot;flink-sb&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! State schema changes&lt;br /&gt;
| State variables can be added or removed; value fields can evolve with Avro encoding&amp;lt;ref name=&amp;quot;tws&amp;quot; /&amp;gt;&lt;br /&gt;
| Migrated automatically when a job is restored from a savepoint with changed state types, for serializers that support it&amp;lt;ref name=&amp;quot;flink-se&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-release-2.3/docs/dev/datastream/fault-tolerance/serialization/schema_evolution/ |title=State Schema Evolution (Apache Flink 2.3) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== What does state cost? ==&lt;br /&gt;
State has to be stored, checkpointed and restored. Databricks advises setting the number of shuffle partitions to one to two times the number of cluster cores for stateful queries, and notes that the partition count is fixed when the checkpoint is created.&amp;lt;ref name=&amp;quot;db-stateful&amp;quot; /&amp;gt; In open source Spark, &amp;lt;code&amp;gt;spark.sql.shuffle.partitions&amp;lt;/code&amp;gt; and the state store provider cannot change between restarts from the same checkpoint.&amp;lt;ref name=&amp;quot;misc&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/additional-information.html |title=Structured Streaming: Miscellaneous Notes (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; See [[Streaming checkpoint]] for what else is fixed.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[transformWithState]]&lt;br /&gt;
* [[State store]]&lt;br /&gt;
* [[RocksDB state store]]&lt;br /&gt;
* [[Watermark]]&lt;br /&gt;
* [[Stream-stream join]]&lt;br /&gt;
* [[Streaming deduplication]]&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:Pipelines and orchestration]]&lt;br /&gt;
[[Category:Apache Spark]]&lt;/div&gt;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:59 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Stateful_stream_processing</comments>
		</item>
		<item>
			<title>Spark-submit</title>
			<link>https://openlakehouse.io/w/index.php?title=Spark-submit&amp;diff=200&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Spark-submit&amp;diff=200&amp;oldid=0</guid>
			<description>&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;{{DISPLAYTITLE:spark-submit}}&lt;br /&gt;
{{Infobox software&lt;br /&gt;
| name                = spark-submit&lt;br /&gt;
| developer           = [[Apache Software Foundation]] ([[Apache Spark]] project)&lt;br /&gt;
| initial_release     = Spark 1.0.0&lt;br /&gt;
| latest_release      = Spark 4.3.0&lt;br /&gt;
| latest_release_date = 2026-10-30&lt;br /&gt;
| written_in          = Shell script, Scala&lt;br /&gt;
| type                = Application launcher for Apache Spark&lt;br /&gt;
| license             = Apache License 2.0&lt;br /&gt;
| website             = [https://spark.apache.org/docs/4.3.0/submitting-applications.html Submitting Applications]&lt;br /&gt;
| repo                = [https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/deploy/SparkSubmit.scala github.com/apache/spark (core/.../deploy/SparkSubmit.scala)]&lt;br /&gt;
| related             = [[Spark configuration precedence]], [[Spark on YARN]], [[Spark on Kubernetes]], [[Spark standalone cluster manager]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (docs/submitting-applications.md, docs/configuration.md, docs/spark-standalone.md, docs/running-on-yarn.md, SparkSubmitArguments.scala and JavaUtils.java), SPARK-48392 and the Spark 1.0.0 release notes}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;spark-submit&amp;#039;&amp;#039;&amp;#039; is the command-line script in the &amp;lt;code&amp;gt;bin&amp;lt;/code&amp;gt; directory of [[Apache Spark]] that launches a packaged Spark application (a JAR, a Python file or an R file) on a local machine or on any supported cluster manager through one interface.&amp;lt;ref name=&amp;quot;submit&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/submitting-applications.html |title=Submitting Applications (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; It sets up the classpath with Spark and its dependencies, chooses where the driver runs, ships the application&amp;#039;s files to the cluster and passes configuration to the application.&amp;lt;ref name=&amp;quot;submit&amp;quot; /&amp;gt; The &amp;lt;code&amp;gt;spark-shell&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;pyspark&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spark-sql&amp;lt;/code&amp;gt; shells and the [[Spark Thrift Server]] start script accept the same options.&amp;lt;ref name=&amp;quot;submit&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;thrift&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-distributed-sql-engine.html |title=Distributed SQL Engine (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;spark-submit&amp;lt;/code&amp;gt; was introduced in Spark 1.0.0, whose release notes describe it as a new tool for submitting an application to any Spark cluster, including local, [[Apache Mesos support in Spark|Mesos]] and YARN clusters, through a common process.&amp;lt;ref name=&amp;quot;r100&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-1-0-0.html |title=Spark Release 1.0.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How is spark-submit used? ==&lt;br /&gt;
The general form is &amp;lt;code&amp;gt;spark-submit [options] &amp;lt;app jar | python file | R file&amp;gt; [app arguments]&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;ssargs&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/deploy/SparkSubmitArguments.scala |title=SparkSubmitArguments.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; For a Python application, the &amp;lt;code&amp;gt;.py&amp;lt;/code&amp;gt; file takes the place of the JAR, and extra &amp;lt;code&amp;gt;.py&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;.zip&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;.egg&amp;lt;/code&amp;gt; files go on the Python path with &amp;lt;code&amp;gt;--py-files&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;submit&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# A PySpark job on YARN, driver inside the cluster&lt;br /&gt;
./bin/spark-submit \&lt;br /&gt;
  --master yarn \&lt;br /&gt;
  --deploy-mode cluster \&lt;br /&gt;
  --name nightly-etl \&lt;br /&gt;
  --executor-memory 4g \&lt;br /&gt;
  --num-executors 10 \&lt;br /&gt;
  --py-files libs.zip \&lt;br /&gt;
  --conf spark.sql.shuffle.partitions=400 \&lt;br /&gt;
  etl_job.py --date 2026-11-23&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Everything after the application file is passed to the application as its own arguments, so Spark options must come before it.&amp;lt;ref name=&amp;quot;submit&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What are the main arguments? ==&lt;br /&gt;
The following options are listed by &amp;lt;code&amp;gt;spark-submit --help&amp;lt;/code&amp;gt; in Spark 4.3.0.&amp;lt;ref name=&amp;quot;ssargs&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Option !! Meaning !! Default or scope&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;--master&amp;lt;/code&amp;gt; || Master URL: &amp;lt;code&amp;gt;local[*]&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spark://host:port&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yarn&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;k8s://https://host:port&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;local[*]&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;--deploy-mode&amp;lt;/code&amp;gt; || Run the driver in the submitting process (&amp;lt;code&amp;gt;client&amp;lt;/code&amp;gt;) or on a cluster node (&amp;lt;code&amp;gt;cluster&amp;lt;/code&amp;gt;) || &amp;lt;code&amp;gt;client&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;--class&amp;lt;/code&amp;gt; || Main class of a Java or Scala application || Java/Scala only&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;--name&amp;lt;/code&amp;gt; || Application name ||&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;--conf&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;-c&amp;lt;/code&amp;gt; || Any Spark property as &amp;lt;code&amp;gt;key=value&amp;lt;/code&amp;gt;; repeat the flag for each property ||&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;--properties-file&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;--load-spark-defaults&amp;lt;/code&amp;gt; || Load properties from a file; also load &amp;lt;code&amp;gt;spark-defaults.conf&amp;lt;/code&amp;gt; || see [[Spark configuration precedence]]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;--jars&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;--packages&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;--repositories&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;--exclude-packages&amp;lt;/code&amp;gt; || JARs, or Maven coordinates resolved with transitive dependencies, for the driver and executor classpaths ||&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;--py-files&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;--files&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;--archives&amp;lt;/code&amp;gt; || Python dependencies; files and archives placed in each executor&amp;#039;s working directory ||&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;--driver-memory&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;--executor-memory&amp;lt;/code&amp;gt; || Driver and executor memory || 1024 MiB and 1 GiB&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;--executor-cores&amp;lt;/code&amp;gt; || Cores per executor || 1 on YARN and Kubernetes; all cores of the worker in standalone mode&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;--num-executors&amp;lt;/code&amp;gt; || Executors for static allocation || 2; YARN and Kubernetes only&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;--total-executor-cores&amp;lt;/code&amp;gt; || Total cores for the application || Standalone only&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;--queue&amp;lt;/code&amp;gt; || YARN queue || &amp;lt;code&amp;gt;default&amp;lt;/code&amp;gt;; YARN only&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;--supervise&amp;lt;/code&amp;gt; || Restart the driver if it exits with a non-zero code || Standalone cluster mode only&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;--kill&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;--status&amp;lt;/code&amp;gt; || Kill or query a submitted driver by submission ID || Standalone or Kubernetes cluster mode&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;--remote&amp;lt;/code&amp;gt; || [[Spark Connect]] server URL such as &amp;lt;code&amp;gt;sc://host:port&amp;lt;/code&amp;gt;; cannot be combined with &amp;lt;code&amp;gt;--master&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;--deploy-mode&amp;lt;/code&amp;gt; || Spark Connect only&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;--verbose&amp;lt;/code&amp;gt; || Print debug output, including where each configuration value came from ||&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The default driver memory comes from the constant &amp;lt;code&amp;gt;DEFAULT_DRIVER_MEM_MB&amp;lt;/code&amp;gt;, 1024 in Spark 4.3.0.&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/common/utils-java/src/main/java/org/apache/spark/network/util/JavaUtils.java |title=JavaUtils.java (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What is the difference between client and cluster deploy mode? ==&lt;br /&gt;
In &amp;#039;&amp;#039;&amp;#039;client&amp;#039;&amp;#039;&amp;#039; mode, the driver runs inside the &amp;lt;code&amp;gt;spark-submit&amp;lt;/code&amp;gt; process, and the application&amp;#039;s input and output are attached to the console. The Spark documentation recommends it when submitting from a gateway machine close to the workers, and for interactive shells.&amp;lt;ref name=&amp;quot;submit&amp;quot; /&amp;gt; In &amp;#039;&amp;#039;&amp;#039;cluster&amp;#039;&amp;#039;&amp;#039; mode, the driver is launched on a node inside the cluster; the documentation recommends it when submitting from a machine far from the workers, such as a laptop, to reduce network latency between driver and executors.&amp;lt;ref name=&amp;quot;submit&amp;quot; /&amp;gt; On YARN, cluster mode runs the driver inside the YARN application master, and the client can exit after submission.&amp;lt;ref name=&amp;quot;yarn&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/running-on-yarn.html |title=Running Spark on YARN (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Spark 4.3.0 documentation states that the standalone cluster manager does not support cluster mode for Python applications.&amp;lt;ref name=&amp;quot;submit&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How are dependencies shipped? ==&lt;br /&gt;
The application JAR and any JARs given with &amp;lt;code&amp;gt;--jars&amp;lt;/code&amp;gt; are transferred to the cluster and put on the driver and executor classpaths. &amp;lt;code&amp;gt;--jars&amp;lt;/code&amp;gt; takes a comma-separated list and does not expand directories.&amp;lt;ref name=&amp;quot;submit&amp;quot; /&amp;gt; Spark uses the URL scheme to decide how to distribute a file: &amp;lt;code&amp;gt;file:&amp;lt;/code&amp;gt; paths are served by the driver&amp;#039;s file server, &amp;lt;code&amp;gt;hdfs:&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;http:&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;https:&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ftp:&amp;lt;/code&amp;gt; are downloaded from the URI, and &amp;lt;code&amp;gt;local:&amp;lt;/code&amp;gt; means the file already exists at that path on every node.&amp;lt;ref name=&amp;quot;submit&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;--packages&amp;lt;/code&amp;gt; takes Maven coordinates in the form &amp;lt;code&amp;gt;groupId:artifactId:version&amp;lt;/code&amp;gt; and resolves their transitive dependencies from the local Maven repository, Maven Central and any repositories given with &amp;lt;code&amp;gt;--repositories&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;ssargs&amp;quot; /&amp;gt; For example, a [[Delta Lake]] or [[Apache Iceberg]] runtime can be added this way at launch time instead of being bundled into the application JAR.&lt;br /&gt;
&lt;br /&gt;
== What are common mistakes? ==&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Options after the application file.&amp;#039;&amp;#039;&amp;#039; Arguments after the JAR or &amp;lt;code&amp;gt;.py&amp;lt;/code&amp;gt; file go to the application, not to Spark.&amp;lt;ref name=&amp;quot;submit&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Setting driver memory in code in client mode.&amp;#039;&amp;#039;&amp;#039; In client mode, &amp;lt;code&amp;gt;spark.driver.memory&amp;lt;/code&amp;gt; set on a &amp;lt;code&amp;gt;SparkConf&amp;lt;/code&amp;gt; inside the application has no effect, because the driver JVM is already running; use &amp;lt;code&amp;gt;--driver-memory&amp;lt;/code&amp;gt; or the defaults file.&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;
* &amp;#039;&amp;#039;&amp;#039;Several properties in one &amp;lt;code&amp;gt;--conf&amp;lt;/code&amp;gt;.&amp;#039;&amp;#039;&amp;#039; Each property needs its own &amp;lt;code&amp;gt;--conf&amp;lt;/code&amp;gt; flag, and a value containing spaces must be quoted as &amp;lt;code&amp;gt;&amp;quot;key=value&amp;quot;&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;submit&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Local paths in cluster mode.&amp;#039;&amp;#039;&amp;#039; The application JAR URL must be visible from inside the cluster, for example an &amp;lt;code&amp;gt;hdfs://&amp;lt;/code&amp;gt; path or a &amp;lt;code&amp;gt;file://&amp;lt;/code&amp;gt; path present on every node.&amp;lt;ref name=&amp;quot;submit&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Bundling Spark into the application JAR.&amp;#039;&amp;#039;&amp;#039; When building an assembly JAR, Spark and Hadoop should be &amp;lt;code&amp;gt;provided&amp;lt;/code&amp;gt; dependencies, because the cluster supplies them at runtime.&amp;lt;ref name=&amp;quot;submit&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;&amp;lt;code&amp;gt;--properties-file&amp;lt;/code&amp;gt; dropping the defaults.&amp;#039;&amp;#039;&amp;#039; Since Spark 4.0.0 the &amp;lt;code&amp;gt;--load-spark-defaults&amp;lt;/code&amp;gt; flag is needed to keep &amp;lt;code&amp;gt;spark-defaults.conf&amp;lt;/code&amp;gt; when a properties file is given.&amp;lt;ref name=&amp;quot;submit&amp;quot; /&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-48392 |title=SPARK-48392: Load spark-defaults.conf when passing configurations to spark-submit through --properties-file |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Unused JAR copies on standalone workers.&amp;#039;&amp;#039;&amp;#039; Files and JARs are copied to each executor&amp;#039;s working directory; YARN cleans them up automatically, while standalone workers need &amp;lt;code&amp;gt;spark.worker.cleanup.appDataTtl&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;submit&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Is spark-submit still needed with Spark Connect? ==&lt;br /&gt;
A [[Spark Connect]] client does not need &amp;lt;code&amp;gt;spark-submit&amp;lt;/code&amp;gt;: it connects to a running Spark Connect server with a connection string such as &amp;lt;code&amp;gt;sc://localhost:15002&amp;lt;/code&amp;gt;.&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; &amp;lt;code&amp;gt;spark-submit&amp;lt;/code&amp;gt; still launches classic applications and the servers themselves; &amp;lt;code&amp;gt;sbin/start-connect-server.sh&amp;lt;/code&amp;gt; starts a Spark Connect server.&amp;lt;ref name=&amp;quot;standalone&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/spark-standalone.html |title=Spark Standalone Mode (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; &amp;lt;code&amp;gt;spark-submit&amp;lt;/code&amp;gt; also has a &amp;lt;code&amp;gt;--remote&amp;lt;/code&amp;gt; option for running an application as a Spark Connect client.&amp;lt;ref name=&amp;quot;ssargs&amp;quot; /&amp;gt; On Kubernetes, the [[Kubernetes Operator for Apache Spark]] submits applications from a &amp;lt;code&amp;gt;SparkApplication&amp;lt;/code&amp;gt; resource instead of a manual &amp;lt;code&amp;gt;spark-submit&amp;lt;/code&amp;gt; call.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Spark configuration precedence]]&lt;br /&gt;
* [[Spark on YARN]]&lt;br /&gt;
* [[Spark on Kubernetes]]&lt;br /&gt;
* [[Spark standalone cluster manager]]&lt;br /&gt;
* [[Kubernetes Operator for Apache Spark]]&lt;br /&gt;
* [[Driver (Apache Spark)]]&lt;br /&gt;
* [[Executor]]&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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:58 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Spark-submit</comments>
		</item>
		<item>
			<title>Spark Thrift Server</title>
			<link>https://openlakehouse.io/w/index.php?title=Spark_Thrift_Server&amp;diff=201&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Spark_Thrift_Server&amp;diff=201&amp;oldid=0</guid>
			<description>&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 software&lt;br /&gt;
| name                = Spark Thrift Server&lt;br /&gt;
| developer           = [[Apache Software Foundation]] ([[Apache Spark]] project)&lt;br /&gt;
| initial_release     = Spark 1.1.0 (as the Spark SQL JDBC/ODBC server)&lt;br /&gt;
| latest_release      = Spark 4.3.0&lt;br /&gt;
| latest_release_date = 2026-10-30&lt;br /&gt;
| written_in          = Scala, Java&lt;br /&gt;
| type                = JDBC/ODBC server for Spark SQL (HiveServer2 protocol)&lt;br /&gt;
| license             = Apache License 2.0&lt;br /&gt;
| website             = [https://spark.apache.org/docs/4.3.0/sql-distributed-sql-engine.html Distributed SQL Engine]&lt;br /&gt;
| repo                = [https://github.com/apache/spark/tree/v4.3.0/sql/hive-thriftserver github.com/apache/spark (sql/hive-thriftserver)]&lt;br /&gt;
| related             = [[Spark Connect]], [[Apache Hive]], [[Hive Metastore]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (docs/sql-distributed-sql-engine.md, docs/sql-migration-guide.md, sbin/start-thriftserver.sh, SQLConf.scala, sql/connect/client/jdbc), the Spark 1.1.0, 4.1.0 and 4.3.0 release notes, SPARK-53484 and the Databricks Connect and Databricks JDBC Driver documentation}}&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;Spark Thrift Server&amp;#039;&amp;#039;&amp;#039; is the JDBC/ODBC server of [[Apache Spark]] SQL: a long-running Spark application that implements the HiveServer2 Thrift protocol, so that BI tools, SQL clients and the &amp;lt;code&amp;gt;beeline&amp;lt;/code&amp;gt; shell can run SQL on Spark over standard JDBC or ODBC connections without writing Spark code.&amp;lt;ref name=&amp;quot;dse&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-distributed-sql-engine.html |title=Distributed SQL Engine (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Each client connection gets its own session on a shared Spark application.&amp;lt;ref name=&amp;quot;sqlmig&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; Since Spark 4.1, [[Spark Connect]] also offers a JDBC driver, which gives JDBC clients a second way to reach Spark.&amp;lt;ref name=&amp;quot;r410&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4.1.0.html |title=Spark Release 4.1.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Is the Spark Thrift Server deprecated? ==&lt;br /&gt;
No. The Spark Thrift Server is not deprecated in Spark 4.3.0. It is documented in the Spark 4.3.0 SQL guide, and the Spark 4.3.0 release notes include changes to it, such as making its JDBC metadata operations aware of DataSource V2 catalogs (SPARK-57518, opt-in with &amp;lt;code&amp;gt;spark.sql.thriftServer.catalogMetadata.enabled&amp;lt;/code&amp;gt;) and disallowing JVM system properties in its sessions (SPARK-57441).&amp;lt;ref name=&amp;quot;dse&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;r430&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4-3-0.html |title=Spark Release 4.3.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
Spark 1.1.0 introduced a JDBC/ODBC server for Spark SQL that let many applications connect to Spark SQL and share cached tables.&amp;lt;ref&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-1-1-0.html |title=Spark Release 1.1.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Spark 1.6 made the server multi-session by default.&amp;lt;ref name=&amp;quot;sqlmig&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does the Spark Thrift Server work? ==&lt;br /&gt;
The Spark Thrift Server corresponds to HiveServer2 in [[Apache Hive]], and clients connect to it with Hive JDBC URLs of the form &amp;lt;code&amp;gt;jdbc:hive2://host:port&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;dse&amp;quot; /&amp;gt; The server is a Spark application: &amp;lt;code&amp;gt;sbin/start-thriftserver.sh&amp;lt;/code&amp;gt; submits the class &amp;lt;code&amp;gt;org.apache.spark.sql.hive.thriftserver.HiveThriftServer2&amp;lt;/code&amp;gt; with the application name &amp;quot;Thrift JDBC/ODBC Server&amp;quot;, and it accepts every [[Spark-submit|spark-submit]] option plus &amp;lt;code&amp;gt;--hiveconf&amp;lt;/code&amp;gt; for Hive properties.&amp;lt;ref name=&amp;quot;dse&amp;quot; /&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sbin/start-thriftserver.sh |title=sbin/start-thriftserver.sh (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Queries therefore run on the server&amp;#039;s own executors, on whatever cluster manager it was started on.&lt;br /&gt;
&lt;br /&gt;
By default the server listens on &amp;lt;code&amp;gt;localhost:10000&amp;lt;/code&amp;gt;. The port and host can be changed with the environment variables &amp;lt;code&amp;gt;HIVE_SERVER2_THRIFT_PORT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;HIVE_SERVER2_THRIFT_BIND_HOST&amp;lt;/code&amp;gt; or the properties &amp;lt;code&amp;gt;hive.server2.thrift.port&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hive.server2.thrift.bind.host&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;dse&amp;quot; /&amp;gt; Hive configuration comes from &amp;lt;code&amp;gt;hive-site.xml&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;core-site.xml&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hdfs-site.xml&amp;lt;/code&amp;gt; in Spark&amp;#039;s &amp;lt;code&amp;gt;conf/&amp;lt;/code&amp;gt; directory.&amp;lt;ref name=&amp;quot;dse&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Start the server on YARN, then connect with beeline&lt;br /&gt;
./sbin/start-thriftserver.sh \&lt;br /&gt;
  --master yarn \&lt;br /&gt;
  --conf spark.sql.shuffle.partitions=64 \&lt;br /&gt;
  --hiveconf hive.server2.thrift.port=10000&lt;br /&gt;
&lt;br /&gt;
./bin/beeline -u jdbc:hive2://localhost:10000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
-- Inside beeline: plain Spark SQL&lt;br /&gt;
SHOW TABLES;&lt;br /&gt;
SET spark.sql.shuffle.partitions=200;   -- affects this session only&lt;br /&gt;
SELECT count(*) FROM sales WHERE region = &amp;#039;EMEA&amp;#039;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The server can also carry Thrift RPC over HTTP. Setting &amp;lt;code&amp;gt;hive.server2.transport.mode=http&amp;lt;/code&amp;gt; enables it, by default on port 10001 (&amp;lt;code&amp;gt;hive.server2.thrift.http.port&amp;lt;/code&amp;gt;) at endpoint &amp;lt;code&amp;gt;cliservice&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;hive.server2.http.endpoint&amp;lt;/code&amp;gt;); clients add &amp;lt;code&amp;gt;transportMode=http;httpPath=cliservice&amp;lt;/code&amp;gt; to the JDBC URL.&amp;lt;ref name=&amp;quot;dse&amp;quot; /&amp;gt; &amp;lt;code&amp;gt;sbin/stop-thriftserver.sh&amp;lt;/code&amp;gt; stops the server.&amp;lt;ref name=&amp;quot;dse&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How do sessions work? ==&lt;br /&gt;
Since Spark 1.6 the Spark Thrift Server runs in multi-session mode: each JDBC/ODBC connection has its own copy of the SQL configuration and its own temporary function registry, while cached tables are shared by all connections. Setting &amp;lt;code&amp;gt;spark.sql.hive.thriftServer.singleSession=true&amp;lt;/code&amp;gt; restores the older single-session mode.&amp;lt;ref name=&amp;quot;sqlmig&amp;quot; /&amp;gt; Because all sessions share one Spark application, they share its executors and its Spark core configuration; a &amp;lt;code&amp;gt;SET&amp;lt;/code&amp;gt; in one session changes only runtime SQL configurations for that session (see [[Spark configuration precedence]]).&lt;br /&gt;
&lt;br /&gt;
Several behaviors changed in recent releases:&amp;lt;ref name=&amp;quot;sqlmig&amp;quot; /&amp;gt;&lt;br /&gt;
* Since Spark 3.5, cancelling a running statement interrupts its tasks; &amp;lt;code&amp;gt;spark.sql.thriftServer.interruptOnCancel=false&amp;lt;/code&amp;gt; restores the old behavior.&lt;br /&gt;
* Since Spark 4.1, &amp;lt;code&amp;gt;GetColumns&amp;lt;/code&amp;gt; returns a 1-based &amp;lt;code&amp;gt;ORDINAL_POSITION&amp;lt;/code&amp;gt; instead of the previous 0-based value.&lt;br /&gt;
* Since Spark 4.3, sessions cannot set JVM system properties through the &amp;lt;code&amp;gt;set:system:&amp;lt;/code&amp;gt; configuration overlay, for example in a JDBC connection string; &amp;lt;code&amp;gt;spark.sql.legacy.hive.thriftServer.allowSettingSystemProperties=true&amp;lt;/code&amp;gt; restores the old behavior.&lt;br /&gt;
&lt;br /&gt;
== Spark Thrift Server vs Spark Connect ==&lt;br /&gt;
[[Spark Connect]] is a gRPC protocol through which a thin client sends unresolved DataFrame plans to a Spark server.&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; Spark 4.1.0 added a JDBC driver for Spark Connect (SPARK-53484), and Spark 4.3.0 extended it, for example with support for &amp;lt;code&amp;gt;ARRAY&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;MAP&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;STRUCT&amp;lt;/code&amp;gt; results (SPARK-57380).&amp;lt;ref name=&amp;quot;r410&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;r430&amp;quot; /&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-53484 |title=SPARK-53484: SPIP: JDBC Driver for Spark Connect |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The driver accepts URLs that start with &amp;lt;code&amp;gt;jdbc:sc://&amp;lt;/code&amp;gt;.&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/connect/client/jdbc/src/main/scala/org/apache/spark/sql/connect/client/jdbc/NonRegisteringSparkConnectDriver.scala |title=NonRegisteringSparkConnectDriver.scala (v4.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;
! !! Spark Connect !! Spark Thrift Server&lt;br /&gt;
|-&lt;br /&gt;
! Protocol&lt;br /&gt;
| gRPC with Protocol Buffers; results as Apache Arrow batches || HiveServer2 Thrift (binary or HTTP)&lt;br /&gt;
|-&lt;br /&gt;
! Clients&lt;br /&gt;
| PySpark, Scala and other Spark Connect clients (DataFrame API and SQL); JDBC driver since Spark 4.1.0 || Any HiveServer2-compatible JDBC/ODBC client, such as &amp;lt;code&amp;gt;beeline&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! JDBC URL&lt;br /&gt;
| &amp;lt;code&amp;gt;jdbc:sc://host:port&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;jdbc:hive2://host:port&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Default port&lt;br /&gt;
| 15002 || 10000 (binary), 10001 (HTTP)&lt;br /&gt;
|-&lt;br /&gt;
! Start script&lt;br /&gt;
| &amp;lt;code&amp;gt;sbin/start-connect-server.sh&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;sbin/start-thriftserver.sh&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Session isolation&lt;br /&gt;
| One session per client; no access to static configuration or the &amp;lt;code&amp;gt;SparkContext&amp;lt;/code&amp;gt; || One session per connection with its own SQL configuration and temporary functions; shared cache&lt;br /&gt;
|}&lt;br /&gt;
Sources: the Spark 4.3.0 Spark Connect and distributed SQL engine guides, the standalone guide, the SQL migration guide and the Spark Connect JDBC driver source.&amp;lt;ref name=&amp;quot;connect&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;dse&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;sqlmig&amp;quot; /&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/spark-standalone.html |title=Spark Standalone Mode (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The two servers address different clients: the Thrift Server serves tools built for HiveServer2, while Spark Connect also serves DataFrame programs written against the Spark client libraries. On Databricks, Databricks Connect is an extension of Spark Connect for Databricks Runtime 13.3 LTS and above.&amp;lt;ref&amp;gt;{{Cite web |url=https://docs.databricks.com/aws/en/dev-tools/databricks-connect/ |title=What is Databricks Connect? |publisher=Databricks |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; For SQL tools, Databricks publishes the Databricks JDBC Driver under the Apache 2.0 license; it can run queries either through the Statement Execution API or over Thrift.&amp;lt;ref&amp;gt;{{Cite web |url=https://docs.databricks.com/aws/en/integrations/jdbc-oss/ |title=Databricks JDBC Driver |publisher=Databricks |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Outside the Spark project, Apache Kyuubi describes itself as a multi-tenant Thrift JDBC/ODBC server and a distributed, multi-tenant gateway that provides serverless SQL on lakehouses.&amp;lt;ref&amp;gt;{{Cite web |url=https://kyuubi.apache.org/ |title=Apache Kyuubi |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;
* [[Spark Connect]]&lt;br /&gt;
* [[Spark configuration precedence]]&lt;br /&gt;
* [[Spark-submit|spark-submit]]&lt;br /&gt;
* [[Apache Hive]]&lt;br /&gt;
* [[Hive Metastore]]&lt;br /&gt;
* [[Hive on 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;br /&gt;
[[Category:Query engines]]&lt;/div&gt;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:58 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Spark_Thrift_Server</comments>
		</item>
		<item>
			<title>Spark UI</title>
			<link>https://openlakehouse.io/w/index.php?title=Spark_UI&amp;diff=202&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Spark_UI&amp;diff=202&amp;oldid=0</guid>
			<description>&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            = Spark UI&lt;br /&gt;
| also_known_as   = Spark web UI, application UI, port 4040&lt;br /&gt;
| field           = Monitoring and debugging&lt;br /&gt;
| key_parts       = Jobs, Stages, Storage, Environment, Executors and SQL tabs; Structured Streaming tab; REST API at /api/v1&lt;br /&gt;
| implementations = [[Apache Spark]]&lt;br /&gt;
| related         = [[Spark History Server]], [[Spark event log]], [[Spark listener]], [[Job, stage and task]], [[Executor]], [[Shuffle]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (docs/web-ui.md, docs/monitoring.md, docs/configuration.md, config/UI.scala, config/Status.scala)}}&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;Spark UI&amp;#039;&amp;#039;&amp;#039; is the web interface that the driver of an [[Apache Spark]] application serves while the application runs, by default at &amp;lt;code&amp;gt;http://&amp;amp;lt;driver-host&amp;amp;gt;:4040&amp;lt;/code&amp;gt;, to show the application&amp;#039;s jobs, stages, tasks, cached data, configuration, executors and SQL queries. It runs when &amp;lt;code&amp;gt;spark.ui.enabled&amp;lt;/code&amp;gt; is true, which is the default.&amp;lt;ref name=&amp;quot;uiconf&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;webui&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/web-ui.html |title=Web UI (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The UI exists only while the application runs; for finished applications, the [[Spark History Server]] rebuilds the same pages from the [[Spark event log]].&lt;br /&gt;
&lt;br /&gt;
== How do you open the Spark UI? ==&lt;br /&gt;
The UI is on by default (&amp;lt;code&amp;gt;spark.ui.enabled&amp;lt;/code&amp;gt;, default true) and listens on &amp;lt;code&amp;gt;spark.ui.port&amp;lt;/code&amp;gt; (default 4040).&amp;lt;ref name=&amp;quot;uiconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/internal/config/UI.scala |title=config/UI.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; When the port is taken, for example by another application on the same host, Spark tries 4041, 4042 and so on, and logs the chosen port at startup.&amp;lt;ref name=&amp;quot;webui&amp;quot; /&amp;gt; The same data is available as JSON from the REST API at &amp;lt;code&amp;gt;http://localhost:4040/api/v1&amp;lt;/code&amp;gt; for a running application.&amp;lt;ref name=&amp;quot;monitoring&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/monitoring.html |title=Monitoring and Instrumentation (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Jobs tab ==&lt;br /&gt;
The Jobs tab lists every job of the application with its status, duration and progress, and shows an event timeline of executors being added and removed alongside the jobs.&amp;lt;ref name=&amp;quot;webui&amp;quot; /&amp;gt; A job is the work that one action, such as &amp;lt;code&amp;gt;count()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;write&amp;lt;/code&amp;gt;, triggers (see [[Job, stage and task]]).&lt;br /&gt;
&lt;br /&gt;
The job detail page shows the job&amp;#039;s stages grouped by status, a DAG visualization, and per-stage &amp;#039;&amp;#039;&amp;#039;Input&amp;#039;&amp;#039;&amp;#039; (bytes read from storage), &amp;#039;&amp;#039;&amp;#039;Output&amp;#039;&amp;#039;&amp;#039; (bytes written), &amp;#039;&amp;#039;&amp;#039;Shuffle read&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;Shuffle write&amp;#039;&amp;#039;&amp;#039;. It also links to the SQL query that created the job.&amp;lt;ref name=&amp;quot;webui&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;What to look for:&amp;#039;&amp;#039;&amp;#039; a job that is much slower than its neighbours, failed jobs, and long gaps in the timeline where no executors were available.&lt;br /&gt;
&lt;br /&gt;
== Stages tab ==&lt;br /&gt;
The Stages tab lists all stages by status: active, pending, completed, skipped and failed. Only failed stages show a failure reason, and an active stage can be cancelled with its &amp;#039;&amp;#039;&amp;#039;(kill)&amp;#039;&amp;#039;&amp;#039; link, which &amp;lt;code&amp;gt;spark.ui.killEnabled&amp;lt;/code&amp;gt; (default true) allows.&amp;lt;ref name=&amp;quot;webui&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;uiconf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The stage detail page is where most performance problems show up. It gives summary statistics (minimum, percentiles, maximum) over all tasks for these metrics:&amp;lt;ref name=&amp;quot;webui&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Duration&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;GC time&amp;#039;&amp;#039;&amp;#039;. A maximum far above the median means data skew or a straggler.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Scheduler delay&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;task deserialization time&amp;#039;&amp;#039;&amp;#039;, which are large when tasks are tiny or closures are big.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Shuffle Read Size / Records&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;Shuffle Read Fetch Wait Time&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;Shuffle Remote Reads&amp;#039;&amp;#039;&amp;#039;, which show how much the stage depends on the network.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Shuffle spill (memory)&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;Shuffle spill (disk)&amp;#039;&amp;#039;&amp;#039;. Any spill means execution memory ran out for this stage (see [[Shuffle]]).&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Peak execution memory&amp;#039;&amp;#039;&amp;#039; used by shuffles, aggregations and joins.&lt;br /&gt;
&lt;br /&gt;
The page also aggregates the metrics by executor, lists named accumulators, and has a task table with links to each task&amp;#039;s executor logs.&amp;lt;ref name=&amp;quot;webui&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Storage tab ==&lt;br /&gt;
The Storage tab lists the RDDs and DataFrames that the application has persisted, with their storage level, size in memory and on disk, and number of cached partitions. The detail page shows which executors hold each partition.&amp;lt;ref name=&amp;quot;webui&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;What to look for:&amp;#039;&amp;#039;&amp;#039; a cached DataFrame with fewer cached partitions than total partitions, which means part of it was evicted or never computed.&lt;br /&gt;
&lt;br /&gt;
== Environment tab ==&lt;br /&gt;
The Environment tab shows the configuration the application is actually running with, in sub-tabs: &amp;#039;&amp;#039;&amp;#039;Runtime Information&amp;#039;&amp;#039;&amp;#039; (JVM and Scala versions), &amp;#039;&amp;#039;&amp;#039;Spark Properties&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;Resource Profiles&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;Hadoop Properties&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;System Properties&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;Metrics Properties&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;Classpath Entries&amp;#039;&amp;#039;&amp;#039;. Properties set as &amp;lt;code&amp;gt;spark.hadoop.*&amp;lt;/code&amp;gt; appear under Spark Properties, not Hadoop Properties.&amp;lt;ref name=&amp;quot;webui&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;What to look for:&amp;#039;&amp;#039;&amp;#039; whether a setting passed at submit time was applied, and which jar versions are on the classpath when there is a class conflict.&lt;br /&gt;
&lt;br /&gt;
== Executors tab ==&lt;br /&gt;
The Executors tab lists every executor, including the driver, with its memory, disk, cores, storage memory used for cached data, task counts, shuffle totals and GC time. Each row has &amp;#039;&amp;#039;&amp;#039;Thread Dump&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;Heap Histogram&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;Flame Graph&amp;#039;&amp;#039;&amp;#039; links that open live data for that executor, and &amp;#039;&amp;#039;&amp;#039;stderr&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;stdout&amp;#039;&amp;#039;&amp;#039; links to its logs.&amp;lt;ref name=&amp;quot;webui&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;What to look for:&amp;#039;&amp;#039;&amp;#039; executors with high GC time, a few executors that ran most of the tasks, and executors that were lost (see [[Executor]]).&lt;br /&gt;
&lt;br /&gt;
== SQL tab ==&lt;br /&gt;
The SQL tab, sometimes called the SQL / DataFrame tab, lists every SQL query and every DataFrame action that triggered execution, not only queries written as SQL strings.&amp;lt;ref name=&amp;quot;webui&amp;quot; /&amp;gt; Each query has a graph of its physical operators with their metrics, and a detail page with the parsed, analyzed and optimized logical plans and the physical plan.&lt;br /&gt;
&lt;br /&gt;
The operator metrics are the most direct view of what a query did. Examples include &amp;lt;code&amp;gt;number of output rows&amp;lt;/code&amp;gt; on filters and joins, &amp;lt;code&amp;gt;data size&amp;lt;/code&amp;gt; on exchanges, &amp;lt;code&amp;gt;shuffle bytes written&amp;lt;/code&amp;gt; on a shuffle exchange, &amp;lt;code&amp;gt;spill size&amp;lt;/code&amp;gt; on sorts and hash aggregates, and the file and partition counts on scans.&amp;lt;ref name=&amp;quot;webui&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;What to look for:&amp;#039;&amp;#039;&amp;#039; an unexpected &amp;lt;code&amp;gt;Exchange&amp;lt;/code&amp;gt;, a scan that read many more files or partitions than the filter should allow (see [[Partition pruning]]), and a join whose output row count is far larger than its inputs.&lt;br /&gt;
&lt;br /&gt;
== Other tabs ==&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Structured Streaming&amp;#039;&amp;#039;&amp;#039; appears when micro-batch streaming queries run. It shows input rate, process rate, batch duration, operation durations, watermark gap and state store metrics for each query.&amp;lt;ref name=&amp;quot;webui&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Streaming (DStreams)&amp;#039;&amp;#039;&amp;#039; appears for applications that use the legacy [[Spark Streaming (DStreams)|DStream API]].&amp;lt;ref name=&amp;quot;webui&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;JDBC/ODBC Server&amp;#039;&amp;#039;&amp;#039; appears when Spark runs as a distributed SQL engine through the Thrift server.&amp;lt;ref name=&amp;quot;webui&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How much history does the Spark UI keep? ==&lt;br /&gt;
The live UI keeps a bounded amount of history in driver memory. By default it remembers 1000 jobs (&amp;lt;code&amp;gt;spark.ui.retainedJobs&amp;lt;/code&amp;gt;), 1000 stages (&amp;lt;code&amp;gt;spark.ui.retainedStages&amp;lt;/code&amp;gt;), 100000 tasks per stage (&amp;lt;code&amp;gt;spark.ui.retainedTasks&amp;lt;/code&amp;gt;) and 1000 finished SQL executions (&amp;lt;code&amp;gt;spark.sql.ui.retainedExecutions&amp;lt;/code&amp;gt;).&amp;lt;ref name=&amp;quot;statusconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/internal/config/Status.scala |title=config/Status.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref&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; Older entries are garbage collected, so a long-running application loses its early history from the live UI.&lt;br /&gt;
&lt;br /&gt;
To see an application after it ends, set &amp;lt;code&amp;gt;spark.eventLog.enabled&amp;lt;/code&amp;gt; to true before starting it, and read the logs with the [[Spark History Server]].&amp;lt;ref name=&amp;quot;monitoring&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Spark History Server]]&lt;br /&gt;
* [[Spark event log]]&lt;br /&gt;
* [[Spark listener]]&lt;br /&gt;
* [[Job, stage and task]]&lt;br /&gt;
* [[Executor]]&lt;br /&gt;
* [[Shuffle]]&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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:58 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Spark_UI</comments>
		</item>
		<item>
			<title>Spark SQL ANSI mode</title>
			<link>https://openlakehouse.io/w/index.php?title=Spark_SQL_ANSI_mode&amp;diff=197&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Spark_SQL_ANSI_mode&amp;diff=197&amp;oldid=0</guid>
			<description>&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            = Spark SQL ANSI mode&lt;br /&gt;
| also_known_as   = ANSI SQL mode, ANSI dialect&lt;br /&gt;
| field           = SQL query engines&lt;br /&gt;
| key_parts       = &amp;lt;code&amp;gt;spark.sql.ansi.enabled&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spark.sql.storeAssignmentPolicy&amp;lt;/code&amp;gt;, runtime errors on overflow and invalid casts, &amp;lt;code&amp;gt;try_*&amp;lt;/code&amp;gt; functions&lt;br /&gt;
| implementations = [[Apache Spark]]&lt;br /&gt;
| related         = [[Spark error classes]], [[Spark 3 to Spark 4 migration]], [[Spark SQL scripting]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (docs/sql-ref-ansi-compliance.md, docs/sql-migration-guide.md, SQLConf.scala, error-conditions.json) and the Spark 4.0.0, 4.1.0 and 4.3.0 release notes}}&lt;br /&gt;
&lt;br /&gt;
In [[Apache Spark]], &amp;#039;&amp;#039;&amp;#039;ANSI mode&amp;#039;&amp;#039;&amp;#039; is the Spark SQL dialect, controlled by &amp;lt;code&amp;gt;spark.sql.ansi.enabled&amp;lt;/code&amp;gt;, in which invalid operations such as integer overflow, division by zero and malformed casts raise runtime errors instead of returning null or a wrapped value, and type coercion follows rules aligned with the ANSI SQL standard.&amp;lt;ref name=&amp;quot;ansi&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-ref-ansi-compliance.html |title=ANSI Compliance (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; ANSI mode has been the default since Spark 4.0.&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; With ANSI mode off, Spark SQL uses a Hive-compatible dialect that returns null for many invalid operations.&amp;lt;ref name=&amp;quot;ansi&amp;quot; /&amp;gt; The change matters most when moving workloads from Spark 3 to Spark 4.&lt;br /&gt;
&lt;br /&gt;
== What is ANSI mode in Spark SQL? ==&lt;br /&gt;
Spark SQL has two settings that bring it closer to the SQL standard. &amp;lt;code&amp;gt;spark.sql.ansi.enabled&amp;lt;/code&amp;gt; switches the dialect: with it on, Spark throws runtime exceptions on invalid operations and uses type coercion rules based on a data type precedence list. &amp;lt;code&amp;gt;spark.sql.storeAssignmentPolicy&amp;lt;/code&amp;gt; separately controls implicit casts when rows are inserted into a table. Both settings exist since Spark 3.0.0; in Spark 4.3.0 their defaults are &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ANSI&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;ansi&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Spark documentation notes that some ANSI-mode behaviours do not come from the ANSI SQL standard itself but follow its style.&amp;lt;ref name=&amp;quot;ansi&amp;quot; /&amp;gt; ANSI mode is therefore a Spark dialect, not a certification of full standard compliance.&lt;br /&gt;
&lt;br /&gt;
== Is ANSI mode on by default in Spark 4? ==&lt;br /&gt;
Yes. SPARK-44444, listed in the Spark 4.0.0 release notes, made ANSI mode the default.&amp;lt;ref name=&amp;quot;r400&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4-0-0.html |title=Spark Release 4.0.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The migration guide says that since Spark 4.0 &amp;lt;code&amp;gt;spark.sql.ansi.enabled&amp;lt;/code&amp;gt; is on by default, and that the previous behaviour returns when either the configuration or the environment variable &amp;lt;code&amp;gt;SPARK_ANSI_SQL_MODE&amp;lt;/code&amp;gt; is set to &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;migration&amp;quot; /&amp;gt; In the v4.3.0 source the default is computed as true unless &amp;lt;code&amp;gt;SPARK_ANSI_SQL_MODE&amp;lt;/code&amp;gt; equals &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala |title=SQLConf.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The [[Spark 3 to Spark 4 migration]] page covers the upgrade work around this change.&lt;br /&gt;
&lt;br /&gt;
Spark 4.1.0 added two related changes: views now always persist the ANSI setting in force when they were created (SPARK-53348), and ANSI mode became the default for the pandas API on Spark (SPARK-53295).&amp;lt;ref name=&amp;quot;r410&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4.1.0.html |title=Spark Release 4.1.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Spark 4.3.0 made &amp;lt;code&amp;gt;ceil&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;floor&amp;lt;/code&amp;gt; throw overflow errors in ANSI mode (SPARK-58052).&amp;lt;ref name=&amp;quot;r430&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4-3-0.html |title=Spark Release 4.3.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What does ANSI mode change? ==&lt;br /&gt;
=== Arithmetic overflow ===&lt;br /&gt;
With ANSI mode on, Spark throws an arithmetic exception when a numeric or interval operation overflows. With it off, decimal overflow produces null and other numeric types wrap around as they do in Java or Scala, so &amp;lt;code&amp;gt;2147483647 + 1&amp;lt;/code&amp;gt; returns &amp;lt;code&amp;gt;-2147483648&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;ansi&amp;quot; /&amp;gt; In ANSI mode the same query fails with the error condition &amp;lt;code&amp;gt;ARITHMETIC_OVERFLOW&amp;lt;/code&amp;gt;, whose SQLSTATE is &amp;lt;code&amp;gt;22003&amp;lt;/code&amp;gt;; division by zero fails with &amp;lt;code&amp;gt;DIVIDE_BY_ZERO&amp;lt;/code&amp;gt; (SQLSTATE &amp;lt;code&amp;gt;22012&amp;lt;/code&amp;gt;).&amp;lt;ref name=&amp;quot;errjson&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/common/utils/src/main/resources/error/error-conditions.json |title=error-conditions.json (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Casts ===&lt;br /&gt;
In ANSI mode an explicit &amp;lt;code&amp;gt;CAST&amp;lt;/code&amp;gt; that cannot succeed raises an error: a string that does not parse as the target type, or a numeric value out of the target type&amp;#039;s range. ANSI mode also forbids some conversions that the non-ANSI dialect allows: numeric to and from binary, date to and from boolean, timestamp to and from boolean, and date to numeric.&amp;lt;ref name=&amp;quot;ansi&amp;quot; /&amp;gt; &amp;lt;code&amp;gt;CAST(&amp;#039;a&amp;#039; AS INT)&amp;lt;/code&amp;gt; fails with &amp;lt;code&amp;gt;CAST_INVALID_INPUT&amp;lt;/code&amp;gt; (SQLSTATE &amp;lt;code&amp;gt;22018&amp;lt;/code&amp;gt;) and &amp;lt;code&amp;gt;CAST(2147483648L AS INT)&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;CAST_OVERFLOW&amp;lt;/code&amp;gt; (SQLSTATE &amp;lt;code&amp;gt;22003&amp;lt;/code&amp;gt;); with ANSI mode off both return a value (null and &amp;lt;code&amp;gt;-2147483648&amp;lt;/code&amp;gt;).&amp;lt;ref name=&amp;quot;ansi&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;errjson&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Table inserts ===&lt;br /&gt;
Under the default &amp;lt;code&amp;gt;ANSI&amp;lt;/code&amp;gt; store assignment policy, inserting a value of an incompatible type, such as a string into an &amp;lt;code&amp;gt;INT&amp;lt;/code&amp;gt; column, fails at analysis time, and inserting an out-of-range number fails with &amp;lt;code&amp;gt;CAST_OVERFLOW_IN_TABLE_INSERT&amp;lt;/code&amp;gt;. The &amp;lt;code&amp;gt;LEGACY&amp;lt;/code&amp;gt; policy allows any valid cast, as Spark 2.x did, and the &amp;lt;code&amp;gt;STRICT&amp;lt;/code&amp;gt; policy forbids any cast that could lose precision.&amp;lt;ref name=&amp;quot;ansi&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Functions and operators ===&lt;br /&gt;
Several functions behave differently under ANSI mode. &amp;lt;code&amp;gt;element_at&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;elt&amp;lt;/code&amp;gt; and the &amp;lt;code&amp;gt;array[index]&amp;lt;/code&amp;gt; operator throw on an invalid index; &amp;lt;code&amp;gt;to_date&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;to_timestamp&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;unix_timestamp&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;make_date&amp;lt;/code&amp;gt; throw when input cannot be parsed or the result is invalid.&amp;lt;ref name=&amp;quot;ansi&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Keywords ===&lt;br /&gt;
ANSI mode does not by itself reserve SQL keywords. Spark uses the ANSI keyword parser, which forbids reserved keywords as identifiers, only when both &amp;lt;code&amp;gt;spark.sql.ansi.enabled&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spark.sql.ansi.enforceReservedKeywords&amp;lt;/code&amp;gt; are true, and the second defaults to false.&amp;lt;ref name=&amp;quot;ansi&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Summary of ANSI and non-ANSI behaviour ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Expression !! ANSI mode on (Spark 4 default) !! ANSI mode off&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;2147483647 + 1&amp;lt;/code&amp;gt; || Error &amp;lt;code&amp;gt;ARITHMETIC_OVERFLOW&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;-2147483648&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;1 / 0&amp;lt;/code&amp;gt; || Error &amp;lt;code&amp;gt;DIVIDE_BY_ZERO&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt;&amp;lt;ref&amp;gt;The non-ANSI divide behaves like &amp;lt;code&amp;gt;try_divide&amp;lt;/code&amp;gt;, per a comment in {{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala |title=arithmetic.scala (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;code&amp;gt;CAST(&amp;#039;a&amp;#039; AS INT)&amp;lt;/code&amp;gt; || Error &amp;lt;code&amp;gt;CAST_INVALID_INPUT&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;CAST(2147483648L AS INT)&amp;lt;/code&amp;gt; || Error &amp;lt;code&amp;gt;CAST_OVERFLOW&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;-2147483648&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;CAST(DATE&amp;#039;2020-01-01&amp;#039; AS INT)&amp;lt;/code&amp;gt; || Analysis error || &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
Sources: Spark ANSI compliance documentation and error condition list.&amp;lt;ref name=&amp;quot;ansi&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;errjson&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How to tolerate bad data in ANSI mode ==&lt;br /&gt;
Spark provides &amp;lt;code&amp;gt;try_*&amp;lt;/code&amp;gt; variants that return &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt; instead of raising an error. They include &amp;lt;code&amp;gt;try_cast&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;try_add&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;try_subtract&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;try_multiply&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;try_divide&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;try_mod&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;try_sum&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;try_avg&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;try_element_at&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;try_to_timestamp&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;try_to_date&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;try_parse_url&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;ansi&amp;quot; /&amp;gt; Using these functions on the columns that may hold bad values keeps the rest of a query strict, which is narrower than turning ANSI mode off for a whole session.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
-- Spark 4.3 default: spark.sql.ansi.enabled = true&lt;br /&gt;
SELECT CAST(&amp;#039;a&amp;#039; AS INT);             -- fails with CAST_INVALID_INPUT&lt;br /&gt;
SELECT try_cast(&amp;#039;a&amp;#039; AS INT);         -- NULL&lt;br /&gt;
SELECT try_add(2147483647, 1);       -- NULL&lt;br /&gt;
SELECT try_divide(10, 0);            -- NULL&lt;br /&gt;
&lt;br /&gt;
-- Restore the Spark 3 behaviour for one session only&lt;br /&gt;
SET spark.sql.ansi.enabled = false;&lt;br /&gt;
SELECT CAST(&amp;#039;a&amp;#039; AS INT);             -- NULL&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Apache Spark]]&lt;br /&gt;
* [[Spark 3 to Spark 4 migration]]&lt;br /&gt;
* [[Spark error classes]]&lt;br /&gt;
* [[Spark SQL scripting]]&lt;br /&gt;
* [[Variant type]]&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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:57 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Spark_SQL_ANSI_mode</comments>
		</item>
		<item>
			<title>Spark SQL scripting</title>
			<link>https://openlakehouse.io/w/index.php?title=Spark_SQL_scripting&amp;diff=198&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Spark_SQL_scripting&amp;diff=198&amp;oldid=0</guid>
			<description>&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            = Spark SQL scripting&lt;br /&gt;
| also_known_as   = SQL Scripting, procedural SQL in Spark&lt;br /&gt;
| field           = SQL query engines&lt;br /&gt;
| key_parts       = Compound statement (&amp;lt;code&amp;gt;BEGIN ... END&amp;lt;/code&amp;gt;), local variables, &amp;lt;code&amp;gt;IF&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;CASE&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;WHILE&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;REPEAT&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;LOOP&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;FOR&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;LEAVE&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ITERATE&amp;lt;/code&amp;gt;, condition handlers, cursors&lt;br /&gt;
| implementations = [[Apache Spark]]&lt;br /&gt;
| related         = [[Spark error classes]], [[Spark SQL ANSI mode]], [[SQL pipe syntax]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (docs/sql-ref-scripting.md, docs/control-flow/*.md, SqlBaseParser.g4, AstBuilder.scala, SQLConf.scala, classic SparkSession.scala), SPARK-48338, SPARK-54499 and the Spark 4.1.0 and 4.2.0 release notes}}&lt;br /&gt;
&lt;br /&gt;
In [[Apache Spark]], &amp;#039;&amp;#039;&amp;#039;SQL scripting&amp;#039;&amp;#039;&amp;#039; is the procedural extension of Spark SQL that runs a block of statements written between &amp;lt;code&amp;gt;BEGIN&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;END&amp;lt;/code&amp;gt;, with local variables, loops, conditional logic and error handlers, as a single request. The Spark documentation describes the syntax as based on the SQL/PSM standard.&amp;lt;ref name=&amp;quot;doc&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-ref-scripting.html |title=SQL Scripting (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; SQL scripting lets ETL and analysis logic that used to need Python or Scala driver code stay entirely in SQL; the umbrella ticket also names it as a step toward stored procedures and data warehouse migrations.&amp;lt;ref name=&amp;quot;jira48338&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-48338 |title=SPARK-48338: Sql Scripting support for Spark SQL |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Is SQL scripting enabled by default? ==&lt;br /&gt;
Yes, since Spark 4.1.0. The Spark 4.1.0 release notes state that SQL Scripting is generally available (GA) and enabled by default (SPARK-54499).&amp;lt;ref name=&amp;quot;r410&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4.1.0.html |title=Spark Release 4.1.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;jira54499&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-54499 |title=SPARK-54499: Enable SQL Scripting by default for Spark 4.1 release |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The switch is &amp;lt;code&amp;gt;spark.sql.scripting.enabled&amp;lt;/code&amp;gt;, a configuration added in Spark 4.0.0 whose default in Spark 4.3.0 is &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;. Its description in the 4.3.0 source still calls the feature &amp;quot;under development&amp;quot;, a wording older than the GA decision.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala |title=SQLConf.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Two parts of SQL scripting stay behind internal flags in Spark 4.3.0, both off by default. &amp;lt;code&amp;gt;CONTINUE&amp;lt;/code&amp;gt; handlers need &amp;lt;code&amp;gt;spark.sql.scripting.continueHandlerEnabled&amp;lt;/code&amp;gt; (added in 4.1.0), and cursors (&amp;lt;code&amp;gt;DECLARE CURSOR&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;OPEN&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;FETCH&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;CLOSE&amp;lt;/code&amp;gt;) need &amp;lt;code&amp;gt;spark.sql.scripting.cursorEnabled&amp;lt;/code&amp;gt; (added in 4.2.0). Without them the parser rejects these statements.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;astbuilder&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala |title=AstBuilder.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The release notes list &amp;lt;code&amp;gt;CONTINUE HANDLER&amp;lt;/code&amp;gt; support under 4.1.0 (SPARK-53621) and cursor support under 4.2.0 (SPARK-54759).&amp;lt;ref name=&amp;quot;r410&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;r420&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4-2-0.html |title=Spark Release 4.2.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What does Spark SQL scripting support? ==&lt;br /&gt;
Every SQL script is a compound statement: &amp;lt;code&amp;gt;BEGIN&amp;lt;/code&amp;gt;, an optional declaration section, a body of statements separated by semicolons, and &amp;lt;code&amp;gt;END&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;doc&amp;quot; /&amp;gt; The declaration section can declare local variables (with an optional &amp;lt;code&amp;gt;DEFAULT&amp;lt;/code&amp;gt;), named conditions, cursors and condition handlers.&amp;lt;ref name=&amp;quot;compound&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/control-flow/compound-stmt.html |title=Compound Statement (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The body of a Spark SQL script can contain:&amp;lt;ref name=&amp;quot;doc&amp;quot; /&amp;gt;&lt;br /&gt;
* control flow: &amp;lt;code&amp;gt;IF&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;CASE&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;WHILE&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;REPEAT&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;LOOP&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;FOR&amp;lt;/code&amp;gt; loops over query results, and &amp;lt;code&amp;gt;LEAVE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ITERATE&amp;lt;/code&amp;gt; to exit or continue a labelled loop;&lt;br /&gt;
* DDL such as &amp;lt;code&amp;gt;CREATE&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ALTER&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;DROP&amp;lt;/code&amp;gt;, and DML such as &amp;lt;code&amp;gt;INSERT&amp;lt;/code&amp;gt;;&lt;br /&gt;
* queries, whose result sets are returned to the caller;&lt;br /&gt;
* &amp;lt;code&amp;gt;SET&amp;lt;/code&amp;gt; for local and session variables, and &amp;lt;code&amp;gt;EXECUTE IMMEDIATE&amp;lt;/code&amp;gt;;&lt;br /&gt;
* nested compound statements, each with its own scope for variables, cursors, conditions and handlers.&lt;br /&gt;
&lt;br /&gt;
Compound statements are not atomic. The only supported mode is &amp;lt;code&amp;gt;NOT ATOMIC&amp;lt;/code&amp;gt;: when a statement fails, earlier statements in the block are not rolled back.&amp;lt;ref name=&amp;quot;compound&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does error handling work in SQL scripts? ==&lt;br /&gt;
A condition handler catches errors raised inside its compound statement. A handler can name a Spark error condition such as &amp;lt;code&amp;gt;DIVIDE_BY_ZERO&amp;lt;/code&amp;gt;, a user-declared condition, one or more SQLSTATE values, &amp;lt;code&amp;gt;SQLEXCEPTION&amp;lt;/code&amp;gt; (any SQLSTATE except the &amp;lt;code&amp;gt;XX&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;02&amp;lt;/code&amp;gt; classes) or &amp;lt;code&amp;gt;NOT FOUND&amp;lt;/code&amp;gt; (the &amp;lt;code&amp;gt;02&amp;lt;/code&amp;gt; class).&amp;lt;ref name=&amp;quot;doc&amp;quot; /&amp;gt; When several handlers apply, Spark uses the one in the innermost compound statement and, among those, the most specific: a named condition beats a SQLSTATE, which beats a generic handler.&amp;lt;ref name=&amp;quot;doc&amp;quot; /&amp;gt; The error names and SQLSTATEs are the ones described in [[Spark error classes]].&lt;br /&gt;
&lt;br /&gt;
An &amp;lt;code&amp;gt;EXIT&amp;lt;/code&amp;gt; handler runs its action and then leaves the compound statement that declared it. A &amp;lt;code&amp;gt;CONTINUE&amp;lt;/code&amp;gt; handler runs its action and resumes with the statement after the one that failed.&amp;lt;ref name=&amp;quot;doc&amp;quot; /&amp;gt; A user-declared condition without an explicit SQLSTATE gets &amp;lt;code&amp;gt;45000&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;compound&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
The following script, adapted from the Spark compound statement reference, catches a division by zero with an &amp;lt;code&amp;gt;EXIT&amp;lt;/code&amp;gt; handler. It runs with the Spark 4.3.0 defaults, because &amp;lt;code&amp;gt;EXIT&amp;lt;/code&amp;gt; handlers do not need an extra flag.&amp;lt;ref name=&amp;quot;compound&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
BEGIN&lt;br /&gt;
  DECLARE a INT DEFAULT 1;&lt;br /&gt;
  DECLARE b INT DEFAULT 5;&lt;br /&gt;
  DECLARE EXIT HANDLER FOR DIVIDE_BY_ZERO&lt;br /&gt;
    div0: BEGIN&lt;br /&gt;
      VALUES (15);&lt;br /&gt;
    END div0;&lt;br /&gt;
  SET a = 10;&lt;br /&gt;
  SET a = b / 0;      -- raises DIVIDE_BY_ZERO under ANSI mode&lt;br /&gt;
  VALUES (a);         -- not reached&lt;br /&gt;
END;&lt;br /&gt;
-- returns 15&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;code&amp;gt;FOR&amp;lt;/code&amp;gt; loop iterates over the rows of a query:&amp;lt;ref name=&amp;quot;for&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/control-flow/for-stmt.html |title=FOR Statement (Spark 4.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;sql&amp;quot;&amp;gt;&lt;br /&gt;
BEGIN&lt;br /&gt;
  DECLARE total INT DEFAULT 0;&lt;br /&gt;
  sumOdd: FOR r AS SELECT num FROM range(1, 20) AS t(num) DO&lt;br /&gt;
    IF r.num &amp;gt; 10 THEN&lt;br /&gt;
      LEAVE sumOdd;&lt;br /&gt;
    ELSEIF r.num % 2 = 0 THEN&lt;br /&gt;
      ITERATE sumOdd;&lt;br /&gt;
    END IF;&lt;br /&gt;
    SET total = total + r.num;&lt;br /&gt;
  END FOR sumOdd;&lt;br /&gt;
  VALUES (total);     -- 25&lt;br /&gt;
END;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Spark documentation notes that such loops can often be replaced by a single relational query, which is usually more efficient; here &amp;lt;code&amp;gt;SELECT sum(num) FROM range(1, 10) AS t(num) WHERE num % 2 = 1&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;for&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How to run a SQL script from PySpark or Scala ==&lt;br /&gt;
A script is passed as one string to &amp;lt;code&amp;gt;spark.sql()&amp;lt;/code&amp;gt;; the parser returns a compound body instead of a single query, and the returned DataFrame holds the result set of the last query the script ran.&amp;lt;ref name=&amp;quot;e2e&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/test/scala/org/apache/spark/sql/scripting/SqlScriptingE2eSuite.scala |title=SqlScriptingE2eSuite.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Named parameter markers can be passed in, but positional parameters are rejected for SQL scripts, and a script cannot be run through &amp;lt;code&amp;gt;EXECUTE IMMEDIATE&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;session&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/classic/SparkSession.scala |title=classic/SparkSession.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The documentation describes two ways to pass data in and out of a script: session variables and parameter markers.&amp;lt;ref name=&amp;quot;doc&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
df = spark.sql(&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
BEGIN&lt;br /&gt;
  DECLARE n INT DEFAULT 0;&lt;br /&gt;
  SET n = :iterations;&lt;br /&gt;
  WHILE n &amp;gt; 0 DO&lt;br /&gt;
    SET n = n - 1;&lt;br /&gt;
  END WHILE;&lt;br /&gt;
  VALUES (n);&lt;br /&gt;
END&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;, args={&amp;quot;iterations&amp;quot;: 3})&lt;br /&gt;
df.show()   # one row: 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Apache Spark]]&lt;br /&gt;
* [[Spark error classes]]&lt;br /&gt;
* [[Spark SQL ANSI mode]]&lt;br /&gt;
* [[SQL pipe syntax]]&lt;br /&gt;
* [[Spark Declarative Pipelines]]&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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:57 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Spark_SQL_scripting</comments>
		</item>
		<item>
			<title>Spark standalone cluster manager</title>
			<link>https://openlakehouse.io/w/index.php?title=Spark_standalone_cluster_manager&amp;diff=199&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Spark_standalone_cluster_manager&amp;diff=199&amp;oldid=0</guid>
			<description>&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 software&lt;br /&gt;
| name                = Spark standalone cluster manager&lt;br /&gt;
| developer           = [[Apache Software Foundation]] ([[Apache Spark]] project)&lt;br /&gt;
| initial_release     = Spark 0.6.0&lt;br /&gt;
| latest_release      = Spark 4.3.0&lt;br /&gt;
| latest_release_date = 2026-10-30&lt;br /&gt;
| written_in          = Scala&lt;br /&gt;
| type                = Cluster manager bundled with Apache Spark&lt;br /&gt;
| license             = Apache License 2.0&lt;br /&gt;
| website             = [https://spark.apache.org/docs/4.3.0/spark-standalone.html Spark Standalone Mode]&lt;br /&gt;
| repo                = [https://github.com/apache/spark/tree/v4.3.0/core/src/main/scala/org/apache/spark/deploy github.com/apache/spark (core/.../deploy)]&lt;br /&gt;
| related             = [[Spark on YARN]], [[Spark on Kubernetes]], [[Spark-submit|spark-submit]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (docs/spark-standalone.md, docs/cluster-overview.md, docs/submitting-applications.md, docs/core-migration-guide.md, docs/job-scheduling.md) and the Spark 0.6.0 release notes}}&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;Spark standalone cluster manager&amp;#039;&amp;#039;&amp;#039; is the cluster manager that ships with [[Apache Spark]]: a master process and one worker process per node, started with scripts in Spark&amp;#039;s &amp;lt;code&amp;gt;sbin&amp;lt;/code&amp;gt; directory, that allocate executors to Spark applications without an external resource manager such as YARN or Kubernetes.&amp;lt;ref name=&amp;quot;standalone&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/spark-standalone.html |title=Spark Standalone Mode (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;overview&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/cluster-overview.html |title=Cluster Mode Overview (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; It needs only a Spark distribution on each node, and it offers high availability through standby masters coordinated by Apache ZooKeeper.&amp;lt;ref name=&amp;quot;standalone&amp;quot; /&amp;gt; The standalone cluster manager is one of the three cluster managers that Spark 4.3.0 supports, with [[Spark on YARN|Hadoop YARN]] and [[Spark on Kubernetes|Kubernetes]].&amp;lt;ref name=&amp;quot;overview&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Is the standalone cluster manager deprecated? ==&lt;br /&gt;
No. The standalone cluster manager is not deprecated in Spark 4.3.0. The Spark 4.3.0 cluster mode overview lists it as a supported cluster manager, and recent releases still change it: Spark 4.1 turned on the master&amp;#039;s REST API by default, and Spark 4.3 changed which environment variables are forwarded to a driver submitted in cluster mode.&amp;lt;ref name=&amp;quot;overview&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;coremig&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/core-migration-guide.html |title=Migration Guide: Spark Core (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Only individual settings have been deprecated, such as &amp;lt;code&amp;gt;SPARK_WORKER_INSTANCES&amp;lt;/code&amp;gt;; the migration guide recommends one worker per node with several executors instead.&amp;lt;ref name=&amp;quot;coremig&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
Spark 0.6.0 added the standalone deploy mode, so that a cluster could be launched with only Java and Spark installed on each machine. At that time Spark otherwise ran on Apache Mesos.&amp;lt;ref&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-0-6-0.html |title=Spark Release 0.6.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Mesos support was later removed from Spark; see [[Apache Mesos support in Spark]].&lt;br /&gt;
&lt;br /&gt;
== How does a standalone cluster work? ==&lt;br /&gt;
A standalone cluster has one active &amp;#039;&amp;#039;&amp;#039;master&amp;#039;&amp;#039;&amp;#039; and any number of &amp;#039;&amp;#039;&amp;#039;workers&amp;#039;&amp;#039;&amp;#039;. The master tracks the workers and their free cores and memory, and launches executors on them for each application. Its web UI is on port 8080 by default, and it accepts applications at a &amp;lt;code&amp;gt;spark://HOST:PORT&amp;lt;/code&amp;gt; URL, port 7077 by default. Each worker has its own web UI on port 8081.&amp;lt;ref name=&amp;quot;standalone&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The cluster is started either by hand (&amp;lt;code&amp;gt;sbin/start-master.sh&amp;lt;/code&amp;gt;, then &amp;lt;code&amp;gt;sbin/start-worker.sh spark://HOST:7077&amp;lt;/code&amp;gt; on each node) or with launch scripts that read a &amp;lt;code&amp;gt;conf/workers&amp;lt;/code&amp;gt; file of host names and reach each host over SSH. &amp;lt;code&amp;gt;sbin/start-all.sh&amp;lt;/code&amp;gt; starts the master and all workers; &amp;lt;code&amp;gt;sbin/start-connect-server.sh&amp;lt;/code&amp;gt; starts a [[Spark Connect]] server on the local machine.&amp;lt;ref name=&amp;quot;standalone&amp;quot; /&amp;gt; The daemons can also all run on one machine for testing.&amp;lt;ref name=&amp;quot;standalone&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Executor placement depends on &amp;lt;code&amp;gt;spark.executor.cores&amp;lt;/code&amp;gt;. When it is set, the master can start several executors of one application on the same worker if the worker has enough cores and memory. When it is not set, each executor takes all available cores on its worker, so one application gets at most one executor per worker in each scheduling round.&amp;lt;ref name=&amp;quot;standalone&amp;quot; /&amp;gt; &amp;lt;code&amp;gt;--total-executor-cores&amp;lt;/code&amp;gt; caps the total cores an application takes.&amp;lt;ref name=&amp;quot;standalone&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How are applications submitted? ==&lt;br /&gt;
Applications are submitted with [[Spark-submit|spark-submit]] and &amp;lt;code&amp;gt;--master spark://HOST:7077&amp;lt;/code&amp;gt;. In &amp;lt;code&amp;gt;client&amp;lt;/code&amp;gt; mode the driver runs in the submitting process; in &amp;lt;code&amp;gt;cluster&amp;lt;/code&amp;gt; mode the master launches the driver on one of the workers and the client exits once submission is done.&amp;lt;ref name=&amp;quot;standalone&amp;quot; /&amp;gt; The Spark 4.3.0 documentation states that standalone cluster mode is not supported for Python applications, so PySpark jobs on a standalone cluster run in client mode.&amp;lt;ref name=&amp;quot;submit&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/submitting-applications.html |title=Submitting Applications (Spark 4.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;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Start a one-node cluster and run a PySpark job on it (client mode)&lt;br /&gt;
./sbin/start-master.sh&lt;br /&gt;
./sbin/start-worker.sh spark://$(hostname):7077&lt;br /&gt;
./bin/spark-submit \&lt;br /&gt;
  --master spark://$(hostname):7077 \&lt;br /&gt;
  --total-executor-cores 4 \&lt;br /&gt;
  --executor-memory 2g \&lt;br /&gt;
  examples/src/main/python/pi.py 100&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In cluster mode, &amp;lt;code&amp;gt;--supervise&amp;lt;/code&amp;gt; makes the master restart the driver if it exits with a non-zero code.&amp;lt;ref name=&amp;quot;standalone&amp;quot; /&amp;gt; The master also has a REST API for submitting, querying and killing drivers on &amp;lt;code&amp;gt;spark.master.rest.port&amp;lt;/code&amp;gt; (default 6066). Since Spark 4.1 the master starts this REST API by default; &amp;lt;code&amp;gt;spark.master.rest.enabled=false&amp;lt;/code&amp;gt; restores the earlier behavior.&amp;lt;ref name=&amp;quot;standalone&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;coremig&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does high availability work? ==&lt;br /&gt;
By default the standalone master is a single point of failure for scheduling: &amp;lt;code&amp;gt;spark.deploy.recoveryMode&amp;lt;/code&amp;gt; is &amp;lt;code&amp;gt;NONE&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;standalone&amp;quot; /&amp;gt; Spark 4.3.0 offers these recovery modes:&amp;lt;ref name=&amp;quot;standalone&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! &amp;lt;code&amp;gt;spark.deploy.recoveryMode&amp;lt;/code&amp;gt; !! How it works !! Use&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ZOOKEEPER&amp;lt;/code&amp;gt; || Several masters connect to the same ZooKeeper ensemble (&amp;lt;code&amp;gt;spark.deploy.zookeeper.url&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spark.deploy.zookeeper.dir&amp;lt;/code&amp;gt;). One is elected leader; if it dies, a standby is elected and recovers the state. || Production high availability&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FILESYSTEM&amp;lt;/code&amp;gt; || The master writes application and worker registrations to &amp;lt;code&amp;gt;spark.deploy.recoveryDirectory&amp;lt;/code&amp;gt; and recovers them when it restarts. || Single-node recovery after a restart&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ROCKSDB&amp;lt;/code&amp;gt; || Like &amp;lt;code&amp;gt;FILESYSTEM&amp;lt;/code&amp;gt;, but the state is kept in RocksDB. || Single-node recovery&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;CUSTOM&amp;lt;/code&amp;gt; || A class given in &amp;lt;code&amp;gt;spark.deploy.recoveryMode.factory&amp;lt;/code&amp;gt; provides the persistence. || Custom stores&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
With ZooKeeper, failover from the time the leader goes down takes between one and two minutes according to the Spark documentation, and it affects only the scheduling of new applications; applications already running continue.&amp;lt;ref name=&amp;quot;standalone&amp;quot; /&amp;gt; Applications and workers list every master in the URL, for example &amp;lt;code&amp;gt;spark://host1:7077,host2:7077&amp;lt;/code&amp;gt;, so that they can find the current leader at registration.&amp;lt;ref name=&amp;quot;submit&amp;quot; /&amp;gt; If several masters run without a correct ZooKeeper configuration, each one considers itself the leader and they schedule independently.&amp;lt;ref name=&amp;quot;standalone&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== When is the standalone cluster manager used today? ==&lt;br /&gt;
The Spark documentation describes the standalone manager as a simple cluster manager included with Spark that makes it easy to set up a cluster.&amp;lt;ref name=&amp;quot;overview&amp;quot; /&amp;gt; It fits cases where Spark is the only workload on a set of machines and no YARN or Kubernetes cluster is available, single-machine test clusters, and hosting a [[Spark Connect]] server started with the bundled launch scripts.&amp;lt;ref name=&amp;quot;standalone&amp;quot; /&amp;gt; The standalone manager supports dynamic allocation, and workers started with &amp;lt;code&amp;gt;spark.shuffle.service.enabled=true&amp;lt;/code&amp;gt; run the external shuffle service. Because an executor takes all of a worker&amp;#039;s cores when &amp;lt;code&amp;gt;spark.executor.cores&amp;lt;/code&amp;gt; is not set, the Spark documentation recommends setting it explicitly when dynamic allocation is on.&amp;lt;ref name=&amp;quot;jobsched&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/job-scheduling.html |title=Job Scheduling (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Security is off by default. The Spark documentation warns that a standalone cluster open to an untrusted network must have authentication configured, and notes that the standalone manager lacks the fine-grained access control of other resource managers.&amp;lt;ref name=&amp;quot;standalone&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Standalone compared with YARN and Kubernetes ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! !! Spark standalone !! [[Spark on YARN]] !! [[Spark on Kubernetes]]&lt;br /&gt;
|-&lt;br /&gt;
! Master URL&lt;br /&gt;
| &amp;lt;code&amp;gt;spark://HOST:7077&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;yarn&amp;lt;/code&amp;gt; (address from the Hadoop configuration) || &amp;lt;code&amp;gt;k8s://HOST:PORT&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Resource manager&lt;br /&gt;
| Spark master and workers || YARN ResourceManager and NodeManagers || Kubernetes API server; driver and executors run in pods&lt;br /&gt;
|-&lt;br /&gt;
! Default &amp;lt;code&amp;gt;spark.executor.cores&amp;lt;/code&amp;gt;&lt;br /&gt;
| All available cores on the worker || 1 || 1&lt;br /&gt;
|}&lt;br /&gt;
Sources: the Spark 4.3.0 standalone, YARN, Kubernetes and submission guides.&amp;lt;ref name=&amp;quot;standalone&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;k8s&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/running-on-kubernetes.html |title=Running Spark on Kubernetes (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;yarn&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/running-on-yarn.html |title=Running Spark on YARN (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;submit&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;ssargs&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/deploy/SparkSubmitArguments.scala |title=SparkSubmitArguments.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&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;
== See also ==&lt;br /&gt;
* [[Spark on YARN]]&lt;br /&gt;
* [[Spark on Kubernetes]]&lt;br /&gt;
* [[Spark-submit|spark-submit]]&lt;br /&gt;
* [[Apache Mesos support in Spark]]&lt;br /&gt;
* [[Executor]]&lt;br /&gt;
* [[Driver (Apache 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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:57 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Spark_standalone_cluster_manager</comments>
		</item>
		<item>
			<title>Spark plugin</title>
			<link>https://openlakehouse.io/w/index.php?title=Spark_plugin&amp;diff=194&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Spark_plugin&amp;diff=194&amp;oldid=0</guid>
			<description>&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            = Spark plugin&lt;br /&gt;
| also_known_as   = SparkPlugin, driver plugin, executor plugin&lt;br /&gt;
| field           = Extension APIs&lt;br /&gt;
| key_parts       = SparkPlugin, DriverPlugin, ExecutorPlugin, PluginContext (metrics, configuration, driver RPC), spark.plugins&lt;br /&gt;
| implementations = [[Apache Spark]] (since 3.0.0)&lt;br /&gt;
| related         = [[Spark listener]], [[Executor]], [[Native execution engine (Spark)]], [[Apache Gluten]], [[DataFusion Comet]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (SparkPlugin.java, DriverPlugin.java, ExecutorPlugin.java, PluginContext.java, config/package.scala, docs/monitoring.md), Spark JIRA SPARK-29397, the Apache Gluten v1.7.0 README, the Apache DataFusion Comet 1.2.0 README and source, and the spark-rapids v26.10.0 configuration docs}}&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;&amp;#039;Spark plugin&amp;#039;&amp;#039;&amp;#039; is a class implementing &amp;lt;code&amp;gt;org.apache.spark.api.plugin.SparkPlugin&amp;lt;/code&amp;gt; that [[Apache Spark]] loads into an application at startup, running one component inside the driver and one inside every [[executor]]. Plugins can initialize resources before tasks run, publish custom metrics through Spark&amp;#039;s metrics system, react to task start and end on executors, and send messages from executors to the driver. The API was added in Spark 3.0.0 and is marked as a developer API.&amp;lt;ref name=&amp;quot;sparkplugin&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/java/org/apache/spark/api/plugin/SparkPlugin.java |title=SparkPlugin.java (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-29397 |title=SPARK-29397: Create new plugin interface for driver and executor plugins |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How do you load a Spark plugin? ==&lt;br /&gt;
Plugins are loaded by listing their class names in &amp;lt;code&amp;gt;spark.plugins&amp;lt;/code&amp;gt; (since 3.0.0). A second setting, &amp;lt;code&amp;gt;spark.plugins.defaultList&amp;lt;/code&amp;gt;, is prepended to it, so that a platform can put its plugins in the default configuration file and users can still add more on the command line without overwriting them. Duplicate plugins are ignored.&amp;lt;ref name=&amp;quot;coreconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/internal/config/package.scala |title=config/package.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;monitoring&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/monitoring.html |title=Monitoring and Instrumentation (Spark 4.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;bash&amp;quot;&amp;gt;&lt;br /&gt;
spark-submit \&lt;br /&gt;
  --jars my-plugin.jar \&lt;br /&gt;
  --conf spark.plugins=com.example.MyPlugin \&lt;br /&gt;
  app.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The plugin jar must be on the classpath of both the driver and the executors, because Spark creates one instance in each.&lt;br /&gt;
&lt;br /&gt;
== What are the parts of the plugin API? ==&lt;br /&gt;
A &amp;lt;code&amp;gt;SparkPlugin&amp;lt;/code&amp;gt; returns two optional components. The driver component has a single instance per application, inside the driver; the executor component has one instance in each executor that Spark starts.&amp;lt;ref name=&amp;quot;sparkplugin&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;DriverPlugin&amp;#039;&amp;#039;&amp;#039; (since 3.0.0) has these methods:&amp;lt;ref name=&amp;quot;driver&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/java/org/apache/spark/api/plugin/DriverPlugin.java |title=DriverPlugin.java (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;init(SparkContext, PluginContext)&amp;lt;/code&amp;gt; runs early in driver startup, before the task scheduler is initialized, and blocks startup until it returns. The map it returns is passed to every executor plugin&amp;#039;s &amp;lt;code&amp;gt;init&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &amp;lt;code&amp;gt;registerMetrics(appId, PluginContext)&amp;lt;/code&amp;gt; runs later, once the application ID is known. Metrics added to the context&amp;#039;s registry by then are published as a metrics source named after the plugin.&lt;br /&gt;
* &amp;lt;code&amp;gt;receive(Object)&amp;lt;/code&amp;gt; handles messages sent from executor plugins.&lt;br /&gt;
* &amp;lt;code&amp;gt;shutdown()&amp;lt;/code&amp;gt; runs when the driver stops.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;ExecutorPlugin&amp;#039;&amp;#039;&amp;#039; (since 3.0.0) has these methods:&amp;lt;ref name=&amp;quot;executor&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/java/org/apache/spark/api/plugin/ExecutorPlugin.java |title=ExecutorPlugin.java (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;init(PluginContext, Map&amp;lt;String, String&amp;gt; extraConf)&amp;lt;/code&amp;gt; runs during executor startup and blocks it. Executor metrics must be registered here; metrics registered later may not show up.&lt;br /&gt;
* &amp;lt;code&amp;gt;onTaskStart()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;onTaskSucceeded()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;onTaskFailed(TaskFailedReason)&amp;lt;/code&amp;gt; (all since 3.1.0) run on the task&amp;#039;s own thread. The documentation warns against expensive work here, such as calls to remote services, because they run for every task.&lt;br /&gt;
* &amp;lt;code&amp;gt;shutdown()&amp;lt;/code&amp;gt; runs during executor shutdown and blocks it.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;PluginContext&amp;#039;&amp;#039;&amp;#039; gives both sides a Dropwizard &amp;lt;code&amp;gt;MetricRegistry&amp;lt;/code&amp;gt;, the &amp;lt;code&amp;gt;SparkConf&amp;lt;/code&amp;gt;, the executor ID, the host name and the resources assigned to the process. On executors, &amp;lt;code&amp;gt;send(Object)&amp;lt;/code&amp;gt; sends a message to the driver plugin without waiting, and &amp;lt;code&amp;gt;ask(Object)&amp;lt;/code&amp;gt; waits for a reply, up to &amp;lt;code&amp;gt;spark.rpc.askTimeout&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;context&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/java/org/apache/spark/api/plugin/PluginContext.java |title=PluginContext.java (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example: counting failed tasks per executor ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;scala&amp;quot;&amp;gt;&lt;br /&gt;
package com.example&lt;br /&gt;
&lt;br /&gt;
import java.util.{Collections, Map =&amp;gt; JMap}&lt;br /&gt;
import com.codahale.metrics.Counter&lt;br /&gt;
import org.apache.spark.TaskFailedReason&lt;br /&gt;
import org.apache.spark.api.plugin._&lt;br /&gt;
&lt;br /&gt;
class TaskFailurePlugin extends SparkPlugin {&lt;br /&gt;
  override def driverPlugin(): DriverPlugin = null   // no driver-side component&lt;br /&gt;
&lt;br /&gt;
  override def executorPlugin(): ExecutorPlugin = new ExecutorPlugin {&lt;br /&gt;
    private var failures: Counter = _&lt;br /&gt;
&lt;br /&gt;
    override def init(ctx: PluginContext, extraConf: JMap[String, String]): Unit = {&lt;br /&gt;
      failures = ctx.metricRegistry().counter(&amp;quot;failedTasks&amp;quot;)&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    override def onTaskFailed(reason: TaskFailedReason): Unit = failures.inc()&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Loaded with &amp;lt;code&amp;gt;--conf spark.plugins=com.example.TaskFailurePlugin&amp;lt;/code&amp;gt;, the counter appears in each executor&amp;#039;s metrics under the &amp;lt;code&amp;gt;plugin.&amp;lt;Plugin Class Name&amp;gt;&amp;lt;/code&amp;gt; namespace, alongside Spark&amp;#039;s own executor metrics.&amp;lt;ref name=&amp;quot;monitoring&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What is built on the Spark plugin API? ==&lt;br /&gt;
The plugin API is the entry point for several projects that replace or extend Spark&amp;#039;s execution:&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;[[Apache Gluten]]&amp;#039;&amp;#039;&amp;#039; offloads compute-intensive SQL processing to native engines such as Velox and ClickHouse while reusing Spark&amp;#039;s control flow. It translates Spark physical plans into Substrait plans and is enabled with &amp;lt;code&amp;gt;spark.plugins=org.apache.gluten.GlutenPlugin&amp;lt;/code&amp;gt;.&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/gluten/blob/v1.7.0/README.md |title=Apache Gluten README (v1.7.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Gluten graduated from the Apache Incubator on 2026-02-18.&amp;lt;ref&amp;gt;{{Cite web |url=https://incubator.apache.org/projects/gluten.html |title=Gluten Project Incubation Status |publisher=Apache Incubator |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;[[DataFusion Comet]]&amp;#039;&amp;#039;&amp;#039; (Apache DataFusion Comet), which describes itself as an accelerator for Apache Spark that runs on commodity hardware, is enabled with &amp;lt;code&amp;gt;spark.plugins=org.apache.spark.CometPlugin&amp;lt;/code&amp;gt;. Its &amp;lt;code&amp;gt;CometPlugin&amp;lt;/code&amp;gt; class implements both a driver and an executor plugin.&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/datafusion-comet/blob/1.2.0/README.md |title=Apache DataFusion Comet README (1.2.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/datafusion-comet/blob/1.2.0/spark/src/main/scala/org/apache/spark/Plugins.scala |title=Plugins.scala (Comet 1.2.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;RAPIDS Accelerator for Apache Spark&amp;#039;&amp;#039;&amp;#039;, from NVIDIA, runs SQL operations on GPUs and is enabled with &amp;lt;code&amp;gt;spark.plugins=com.nvidia.spark.SQLPlugin&amp;lt;/code&amp;gt;.&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/NVIDIA/spark-rapids/blob/v26.10.0/docs/configs.md |title=RAPIDS Accelerator for Apache Spark Configuration (v26.10.0) |publisher=NVIDIA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Spark plugin vs Spark listener ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! !! Spark plugin !! [[Spark listener]]&lt;br /&gt;
|-&lt;br /&gt;
! Runs on&lt;br /&gt;
| Driver and every executor&amp;lt;ref name=&amp;quot;sparkplugin&amp;quot; /&amp;gt;&lt;br /&gt;
| Driver only, on the listener bus&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/scheduler/LiveListenerBus.scala |title=LiveListenerBus.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Timing&lt;br /&gt;
| Synchronous; &amp;lt;code&amp;gt;init&amp;lt;/code&amp;gt; blocks startup&amp;lt;ref name=&amp;quot;driver&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;executor&amp;quot; /&amp;gt;&lt;br /&gt;
| Asynchronous; events can be dropped if a queue is full&lt;br /&gt;
|-&lt;br /&gt;
! Can publish metrics&lt;br /&gt;
| Yes, through the metrics system&amp;lt;ref name=&amp;quot;context&amp;quot; /&amp;gt;&lt;br /&gt;
| No built-in metrics registry&lt;br /&gt;
|-&lt;br /&gt;
! Configured with&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.plugins&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;coreconf&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.extraListeners&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;coreconf&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Typical use&lt;br /&gt;
| Native or GPU execution engines, executor-side instrumentation&lt;br /&gt;
| Lineage, auditing, job monitoring&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Spark listener]]&lt;br /&gt;
* [[Executor]]&lt;br /&gt;
* [[Native execution engine (Spark)]]&lt;br /&gt;
* [[Apache Gluten]]&lt;br /&gt;
* [[DataFusion Comet]]&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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:56 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Spark_plugin</comments>
		</item>
		<item>
			<title>Spark resource profiles</title>
			<link>https://openlakehouse.io/w/index.php?title=Spark_resource_profiles&amp;diff=195&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Spark_resource_profiles&amp;diff=195&amp;oldid=0</guid>
			<description>&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            = Spark resource profiles&lt;br /&gt;
| also_known_as   = Stage-level scheduling, ResourceProfile, accelerator-aware scheduling&lt;br /&gt;
| field           = Distributed data processing&lt;br /&gt;
| introduced      = Apache Spark 3.1 (stage-level scheduling); Apache Spark 3.0 (GPU and custom resource scheduling)&lt;br /&gt;
| key_parts       = &amp;lt;code&amp;gt;ResourceProfile&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ResourceProfileBuilder&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ExecutorResourceRequests&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;TaskResourceRequests&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;RDD.withResources&amp;lt;/code&amp;gt;&lt;br /&gt;
| implementations = [[Apache Spark]]&lt;br /&gt;
| related         = [[Executor]], [[GPU acceleration in Spark]], [[Shuffle]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (docs/configuration.md, docs/running-on-yarn.md, docs/running-on-kubernetes.md, docs/spark-standalone.md, python/pyspark/resource/, python/pyspark/core/rdd.py, python/pyspark/sql/dataframe.py), Apache JIRA SPARK-24615, SPARK-27495, SPARK-29150, SPARK-39853, SPARK-45495 and SPARK-46812, and the Spark 3.0.0, 3.1.1 and 4.0.0 release notes}}&lt;br /&gt;
&lt;br /&gt;
In [[Apache Spark]], a &amp;#039;&amp;#039;&amp;#039;resource profile&amp;#039;&amp;#039;&amp;#039; (&amp;lt;code&amp;gt;ResourceProfile&amp;lt;/code&amp;gt;) is a set of executor and task resource requirements, such as cores, memory and GPUs, that Spark applies to one stage of a job instead of to the whole application.&amp;lt;ref name=&amp;quot;conf&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; The feature is called &amp;#039;&amp;#039;&amp;#039;stage-level scheduling&amp;#039;&amp;#039;&amp;#039; and was added in Spark 3.1.&amp;lt;ref name=&amp;quot;r311&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-3-1-1.html |title=Spark Release 3.1.1 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; It builds on the accelerator-aware scheduling of Spark 3.0, which lets an application request GPUs and other custom resources for its [[executor]]s and tasks.&amp;lt;ref name=&amp;quot;r300&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-3-0-0.html |title=Spark Release 3.0.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What problem do resource profiles solve? ==&lt;br /&gt;
Without resource profiles, a Spark application asks for one kind of executor at startup and keeps it for every stage. The Spark documentation gives the case of an ETL stage that needs only CPUs followed by a machine learning stage that needs GPUs: with stage-level scheduling, the application can request GPU executors only when the ML stage runs, instead of holding idle GPUs during the ETL stage.&amp;lt;ref name=&amp;quot;conf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does GPU scheduling work in Apache Spark? ==&lt;br /&gt;
Spark 3.0 added accelerator-aware scheduling under the SPARK-24615 proposal, part of Project Hydrogen.&amp;lt;ref name=&amp;quot;r300&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;jira24615&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-24615 |title=SPARK-24615: SPIP: Accelerator-aware task scheduling for Spark |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; A resource is identified by a name such as &amp;lt;code&amp;gt;gpu&amp;lt;/code&amp;gt;, and Spark schedules its individual addresses (for example GPU indexes) to tasks. The cluster manager must support and be configured for the resource; the feature is not available in local mode.&amp;lt;ref name=&amp;quot;conf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Spark GPU settings, all added in Spark 3.0.0, are:&amp;lt;ref name=&amp;quot;conf&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;spark.executor.resource.gpu.amount&amp;lt;/code&amp;gt; (default 0): GPUs per executor.&lt;br /&gt;
* &amp;lt;code&amp;gt;spark.executor.resource.gpu.discoveryScript&amp;lt;/code&amp;gt; (no default): a script the executor runs at startup; it prints a JSON object with the resource name and an array of addresses. It is required on YARN and Kubernetes.&lt;br /&gt;
* &amp;lt;code&amp;gt;spark.executor.resource.gpu.vendor&amp;lt;/code&amp;gt; (no default): Kubernetes only; the device plugin vendor and domain, for example &amp;lt;code&amp;gt;nvidia.com&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;amd.com&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &amp;lt;code&amp;gt;spark.task.resource.gpu.amount&amp;lt;/code&amp;gt; (default 1): GPUs per task. Fractional values up to 0.5 let several tasks share one GPU; 0.25 means four tasks per GPU.&lt;br /&gt;
* &amp;lt;code&amp;gt;spark.driver.resource.gpu.amount&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spark.driver.resource.gpu.discoveryScript&amp;lt;/code&amp;gt;: the same for the driver.&lt;br /&gt;
&lt;br /&gt;
The Spark source tree ships a sample GPU discovery script, &amp;lt;code&amp;gt;examples/src/main/scripts/getGpusResources.sh&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;script&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/examples/src/main/scripts/getGpusResources.sh |title=getGpusResources.sh (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Inside a task, &amp;lt;code&amp;gt;TaskContext.get().resources()&amp;lt;/code&amp;gt; returns the addresses Spark assigned; Spark does not use the GPU itself, so the user code or the ML library must use those addresses.&amp;lt;ref name=&amp;quot;conf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How is a resource profile built? ==&lt;br /&gt;
A resource profile is built from two request objects. &amp;lt;code&amp;gt;ExecutorResourceRequests&amp;lt;/code&amp;gt; sets executor cores, memory, memory overhead, PySpark memory, off-heap memory and custom resources; &amp;lt;code&amp;gt;TaskResourceRequests&amp;lt;/code&amp;gt; sets the CPUs and custom resources each task needs. &amp;lt;code&amp;gt;ResourceProfileBuilder.require()&amp;lt;/code&amp;gt; adds both, and &amp;lt;code&amp;gt;build&amp;lt;/code&amp;gt; returns the &amp;lt;code&amp;gt;ResourceProfile&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;pyreq&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/resource/requests.py |title=pyspark/resource/requests.py (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;pyprof&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/resource/profile.py |title=pyspark/resource/profile.py (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The same classes exist in Scala and Java in the &amp;lt;code&amp;gt;org.apache.spark.resource&amp;lt;/code&amp;gt; package.&amp;lt;ref name=&amp;quot;conf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;RDD.withResources(profile)&amp;lt;/code&amp;gt; attaches a profile to an RDD, and the stage that computes that RDD uses it. The RDD API for stage-level scheduling was tracked as SPARK-29150 and released in Spark 3.1; the PySpark &amp;lt;code&amp;gt;withResources&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ResourceProfile&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ResourceProfileBuilder&amp;lt;/code&amp;gt; APIs are marked &amp;quot;new in version 3.1.0&amp;quot; and &amp;quot;evolving&amp;quot;.&amp;lt;ref name=&amp;quot;jira29150&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-29150 |title=SPARK-29150: Update RDD API for Stage level scheduling |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;pyrdd&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/api/python/reference/api/pyspark.RDD.withResources.html |title=pyspark.RDD.withResources (PySpark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;pyprof&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example in PySpark ==&lt;br /&gt;
The example asks for executors with 4 cores, 8 GiB of memory and one GPU for one stage, and lets four tasks share each GPU. It assumes dynamic allocation and a GPU discovery script on the executor image.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from pyspark.resource import (&lt;br /&gt;
    ExecutorResourceRequests,&lt;br /&gt;
    TaskResourceRequests,&lt;br /&gt;
    ResourceProfileBuilder,&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
ereqs = (ExecutorResourceRequests()&lt;br /&gt;
         .cores(4)&lt;br /&gt;
         .memory(&amp;quot;8g&amp;quot;)&lt;br /&gt;
         .resource(&amp;quot;gpu&amp;quot;, 1, &amp;quot;/opt/spark/examples/src/main/scripts/getGpusResources.sh&amp;quot;))&lt;br /&gt;
treqs = TaskResourceRequests().cpus(1).resource(&amp;quot;gpu&amp;quot;, 0.25)&lt;br /&gt;
gpu_profile = ResourceProfileBuilder().require(ereqs).require(treqs).build&lt;br /&gt;
&lt;br /&gt;
rdd = spark.sparkContext.parallelize(range(1000), 8)&lt;br /&gt;
result = rdd.withResources(gpu_profile).mapPartitions(lambda it: [sum(it)]).collect()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In PySpark, &amp;lt;code&amp;gt;build&amp;lt;/code&amp;gt; is a property, not a method.&amp;lt;ref name=&amp;quot;pyprof&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Which cluster managers support stage-level scheduling? ==&lt;br /&gt;
In Spark 4.3, stage-level scheduling works on YARN, Kubernetes and Spark standalone.&amp;lt;ref name=&amp;quot;conf&amp;quot; /&amp;gt; Spark 3.1 shipped it with Kubernetes support listed as a separate item (SPARK-33288) under the SPARK-27495 umbrella.&amp;lt;ref name=&amp;quot;r311&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;jira27495&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-27495 |title=SPARK-27495: SPIP: Support Stage level resource configuration and scheduling |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;
! Cluster manager !! With dynamic allocation !! Without dynamic allocation&lt;br /&gt;
|-&lt;br /&gt;
| YARN&lt;br /&gt;
| New executors per profile; each profile id becomes a YARN container priority&amp;lt;ref name=&amp;quot;yarn&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/running-on-yarn.html |title=Running Spark on YARN (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| Task requirements only, on the startup executors&amp;lt;ref name=&amp;quot;yarn&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Kubernetes&lt;br /&gt;
| New executors per profile; requires &amp;lt;code&amp;gt;spark.dynamicAllocation.shuffleTracking.enabled&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;k8s&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/running-on-kubernetes.html |title=Running Spark on Kubernetes (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| Task requirements only (SPARK-45495, Spark 3.5.1 and 4.0.0)&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;jira45495&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-45495 |title=SPARK-45495: Support stage level task resource profile for k8s cluster when dynamic allocation disabled |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Standalone&lt;br /&gt;
| New executors per profile; only executor memory, cores and custom resources take effect&amp;lt;ref name=&amp;quot;standalone&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/spark-standalone.html |title=Spark Standalone Mode (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| Task requirements only (SPARK-39853, Spark 3.4.0)&amp;lt;ref name=&amp;quot;standalone&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;jira39853&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-39853 |title=SPARK-39853: Support stage level schedule for standalone cluster when dynamic allocation is disabled |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Why does stage-level scheduling need dynamic allocation? ==&lt;br /&gt;
A profile that changes executor resources needs new executors, and Spark gets them through dynamic allocation. With dynamic allocation on, Spark acquires new executors for each profile, and a task runs only on an executor created with exactly its profile; unused executors time out under the normal dynamic allocation rules. With dynamic allocation off, tasks with different task requirements share the executors of the default profile (&amp;lt;code&amp;gt;DEFAULT_RESOURCE_PROFILE&amp;lt;/code&amp;gt;).&amp;lt;ref name=&amp;quot;conf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On Kubernetes, shuffle tracking keeps executors that hold shuffle data, so executors from an earlier profile may not time out. The Spark documentation warns that this can use more cluster resources and, if the cluster runs out, the application can hang; &amp;lt;code&amp;gt;spark.dynamicAllocation.shuffleTracking.timeout&amp;lt;/code&amp;gt; limits this at the cost of possible recomputation.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What happens when two profiles meet in one stage? ==&lt;br /&gt;
By default Spark allows one profile per stage and throws an exception if RDDs with different profiles are combined into the same stage. Setting &amp;lt;code&amp;gt;spark.scheduler.resource.profileMergeConflicts&amp;lt;/code&amp;gt; (default false, since 3.1.0) to true makes Spark merge them into a new profile that takes the maximum of each resource.&amp;lt;ref name=&amp;quot;conf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Can DataFrames use resource profiles? ==&lt;br /&gt;
The Spark 4.3 configuration guide still describes stage-level scheduling as available &amp;quot;only for the RDD API in Scala, Java, and Python&amp;quot;.&amp;lt;ref name=&amp;quot;conf&amp;quot; /&amp;gt; One exception exists in PySpark: since Spark 4.0.0, &amp;lt;code&amp;gt;DataFrame.mapInPandas&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;DataFrame.mapInArrow&amp;lt;/code&amp;gt; take an optional &amp;lt;code&amp;gt;profile&amp;lt;/code&amp;gt; argument with a &amp;lt;code&amp;gt;ResourceProfile&amp;lt;/code&amp;gt; (SPARK-46812).&amp;lt;ref name=&amp;quot;pydf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/sql/dataframe.py |title=pyspark/sql/dataframe.py (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;jira46812&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-46812 |title=SPARK-46812: Make mapInPandas / mapInArrow support ResourceProfile (Stage-Level scheduling) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;r400&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4-0-0.html |title=Spark Release 4.0.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Other DataFrame and Spark SQL operators run with the application&amp;#039;s default profile.&lt;br /&gt;
&lt;br /&gt;
== What a resource profile is not ==&lt;br /&gt;
A Spark resource profile is not a Kubernetes pod resource request or a YARN container size, although Spark translates it into one. On YARN, Spark converts &amp;lt;code&amp;gt;gpu&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;fpga&amp;lt;/code&amp;gt; to the built-in types &amp;lt;code&amp;gt;yarn.io/gpu&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;yarn.io/fpga&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;yarn&amp;quot; /&amp;gt; On Kubernetes, resources from a pod template apply only to the default profile and are not copied into custom profiles.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt; A resource profile also does not make Spark SQL operators run on a GPU; that is the role of plugins such as the RAPIDS Accelerator, described in [[GPU acceleration in Spark]].&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Executor]]&lt;br /&gt;
* [[GPU acceleration in Spark]]&lt;br /&gt;
* [[Native execution engine (Spark)]]&lt;br /&gt;
* [[Shuffle]]&lt;br /&gt;
* [[RDD]]&lt;br /&gt;
* [[Apache 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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:56 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Spark_resource_profiles</comments>
		</item>
		<item>
			<title>SparkSession</title>
			<link>https://openlakehouse.io/w/index.php?title=SparkSession&amp;diff=196&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=SparkSession&amp;diff=196&amp;oldid=0</guid>
			<description>&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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:56 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:SparkSession</comments>
		</item>
		<item>
			<title>Spark memory management</title>
			<link>https://openlakehouse.io/w/index.php?title=Spark_memory_management&amp;diff=191&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Spark_memory_management&amp;diff=191&amp;oldid=0</guid>
			<description>&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            = Spark memory management&lt;br /&gt;
| also_known_as   = Unified memory model, unified memory manager&lt;br /&gt;
| field           = Distributed data processing&lt;br /&gt;
| introduced      = Apache Spark 1.6.0 (unified memory manager)&lt;br /&gt;
| key_parts       = Reserved memory, user memory, unified region (execution and storage), memory overhead, off-heap memory&lt;br /&gt;
| implementations = [[Apache Spark]]&lt;br /&gt;
| related         = [[Executor]], [[Executor memory overhead]], [[Spill (memory)]], [[Caching and persistence]], [[Garbage collection in Spark]], [[Project Tungsten]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (docs/tuning.md, docs/configuration.md, core/memory/UnifiedMemoryManager.scala) and SPARK-10000}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Spark memory management&amp;#039;&amp;#039;&amp;#039; is the way [[Apache Spark]] divides the memory of each [[executor]] between running tasks, cached data, user code and the JVM itself. Since Spark 1.6.0, a &amp;#039;&amp;#039;&amp;#039;unified memory manager&amp;#039;&amp;#039;&amp;#039; lets execution memory (for shuffles, joins, sorts and aggregations) and storage memory (for cached data) share one region and borrow from each other.&amp;lt;ref name=&amp;quot;spark10000&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-10000 |title=SPARK-10000: Consolidate storage and execution memory management |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;tuning&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/tuning.html |title=Tuning Spark (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Memory outside the JVM heap is requested separately as [[executor memory overhead]].&lt;br /&gt;
&lt;br /&gt;
== How is executor memory divided? ==&lt;br /&gt;
An executor&amp;#039;s JVM heap is set by &amp;lt;code&amp;gt;spark.executor.memory&amp;lt;/code&amp;gt; (default &amp;lt;code&amp;gt;1g&amp;lt;/code&amp;gt;).&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; Spark splits the heap into three parts:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Part !! Size !! What it holds&lt;br /&gt;
|-&lt;br /&gt;
| Reserved memory&lt;br /&gt;
| 300 MiB, fixed&lt;br /&gt;
| Kept back by Spark; the heap must be at least 1.5 times this (450 MiB) or the executor does not start&amp;lt;ref name=&amp;quot;umm&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/memory/UnifiedMemoryManager.scala |title=UnifiedMemoryManager.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| User memory&lt;br /&gt;
| (heap − 300 MiB) × (1 − &amp;lt;code&amp;gt;spark.memory.fraction&amp;lt;/code&amp;gt;), 40% by default&lt;br /&gt;
| User data structures, Spark internal metadata, and a margin for unusually large records&amp;lt;ref name=&amp;quot;tuning&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Unified region (M)&lt;br /&gt;
| (heap − 300 MiB) × &amp;lt;code&amp;gt;spark.memory.fraction&amp;lt;/code&amp;gt; (default 0.6)&lt;br /&gt;
| Execution memory and storage memory, shared&amp;lt;ref name=&amp;quot;tuning&amp;quot; /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For an 8 GiB heap with the defaults, the unified region is (8192 − 300) × 0.6 ≈ 4,735 MiB and user memory is about 3,157 MiB. This follows the formula in &amp;lt;code&amp;gt;UnifiedMemoryManager&amp;lt;/code&amp;gt;, which subtracts the 300 MiB reserve from the heap size the JVM reports (&amp;lt;code&amp;gt;Runtime.getRuntime.maxMemory&amp;lt;/code&amp;gt;) and multiplies the rest by &amp;lt;code&amp;gt;spark.memory.fraction&amp;lt;/code&amp;gt;; the JVM may report slightly less than &amp;lt;code&amp;gt;spark.executor.memory&amp;lt;/code&amp;gt;, so the real figures can be a little lower.&amp;lt;ref name=&amp;quot;umm&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;tuning&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Execution memory and storage memory ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Execution memory&amp;#039;&amp;#039;&amp;#039; is used for computation in shuffles, joins, sorts and aggregations. &amp;#039;&amp;#039;&amp;#039;Storage memory&amp;#039;&amp;#039;&amp;#039; is used for caching and for propagating internal data across the cluster.&amp;lt;ref name=&amp;quot;tuning&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The two share the unified region M. When no execution memory is in use, storage can take all of M, and the other way round. Execution can evict cached blocks to get memory back, but only until storage falls to a protected share R, set by &amp;lt;code&amp;gt;spark.memory.storageFraction&amp;lt;/code&amp;gt; (default 0.5 of M). Storage cannot evict execution memory.&amp;lt;ref name=&amp;quot;tuning&amp;quot; /&amp;gt; Applications that do not cache can therefore use the whole region for execution, and applications that cache keep at least R for their blocks.&amp;lt;ref name=&amp;quot;tuning&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When execution memory runs out, tasks [[Spill (memory)|spill]] to disk instead of failing. When storage memory runs out, cached blocks are dropped in least-recently-used order, or written to disk if their storage level allows it.&amp;lt;ref name=&amp;quot;rddguide&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/rdd-programming-guide.html#rdd-persistence |title=RDD Programming Guide: RDD Persistence (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The Spark docs recommend leaving both fractions at their defaults for most workloads.&amp;lt;ref name=&amp;quot;tuning&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Off-heap memory ==&lt;br /&gt;
With &amp;lt;code&amp;gt;spark.memory.offHeap.enabled&amp;lt;/code&amp;gt; (default false) set to true, Spark can use off-heap memory for certain operations, in an amount set by &amp;lt;code&amp;gt;spark.memory.offHeap.size&amp;lt;/code&amp;gt; (default 0, must be positive when enabled). This memory is outside the JVM heap and does not change heap usage, so the heap should be shrunk if the total must fit a fixed limit.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt; The &amp;lt;code&amp;gt;OFF_HEAP&amp;lt;/code&amp;gt; storage level, marked experimental in the Spark docs, caches data in this memory.&amp;lt;ref name=&amp;quot;rddguide&amp;quot; /&amp;gt; Spark&amp;#039;s task memory manager allocates the memory pages for sorting, hashing and shuffle either on the heap or, with this setting, off-heap; see [[Project Tungsten]].&amp;lt;ref name=&amp;quot;tmm&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/java/org/apache/spark/memory/TaskMemoryManager.java |title=TaskMemoryManager.java (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Memory outside the heap ==&lt;br /&gt;
On YARN and Kubernetes, the container for an executor is the sum of &amp;lt;code&amp;gt;spark.executor.memory&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spark.executor.memoryOverhead&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spark.memory.offHeap.size&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spark.executor.pyspark.memory&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt; Overhead covers JVM overheads, interned strings and other native memory, and by default is 10% of executor memory with a minimum of 384 MiB. Python worker memory is part of the overhead unless &amp;lt;code&amp;gt;spark.executor.pyspark.memory&amp;lt;/code&amp;gt; is set.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt; See [[Executor memory overhead]].&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
spark.executor.memory              8g&lt;br /&gt;
spark.executor.cores               4&lt;br /&gt;
spark.memory.fraction              0.6&lt;br /&gt;
spark.memory.storageFraction       0.5&lt;br /&gt;
spark.memory.offHeap.enabled       true&lt;br /&gt;
spark.memory.offHeap.size          2g&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With this configuration on YARN or Kubernetes, each executor container is sized at 8 GiB of heap plus about 819 MiB of overhead (10% of 8 GiB) plus 2 GiB of off-heap memory. The four tasks that run at once on the executor share one pool of execution memory.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Executor]]&lt;br /&gt;
* [[Executor memory overhead]]&lt;br /&gt;
* [[Spill (memory)]]&lt;br /&gt;
* [[Caching and persistence]]&lt;br /&gt;
* [[Garbage collection in Spark]]&lt;br /&gt;
* [[Project Tungsten]]&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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:55 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Spark_memory_management</comments>
		</item>
		<item>
			<title>Spark on Kubernetes</title>
			<link>https://openlakehouse.io/w/index.php?title=Spark_on_Kubernetes&amp;diff=192&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Spark_on_Kubernetes&amp;diff=192&amp;oldid=0</guid>
			<description>&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            = Spark on Kubernetes&lt;br /&gt;
| also_known_as   = Spark K8s, Kubernetes scheduler backend for Spark&lt;br /&gt;
| field           = Cluster management for distributed data processing&lt;br /&gt;
| introduced      = Spark 2.3.0 (experimental); generally available in Spark 3.1.1&lt;br /&gt;
| key_parts       = Driver pod, executor pods, container image, service account, pod templates, volumes&lt;br /&gt;
| implementations = [[Apache Spark]], [[Kubernetes Operator for Apache Spark]]&lt;br /&gt;
| related         = [[Spark-submit|spark-submit]], [[Executor]], [[Spark on YARN]], [[Spark standalone cluster manager]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (docs/running-on-kubernetes.md, docs/configuration.md, docs/job-scheduling.md), the Spark 2.3.0 and 3.1.1 release notes, SPARK-18278, SPARK-33005 and the Apache Spark Kubernetes Operator 1.1.0 release}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Spark on Kubernetes&amp;#039;&amp;#039;&amp;#039; is the mode of [[Apache Spark]] in which Kubernetes is the cluster manager: the Spark driver and each [[executor]] run as Kubernetes pods, and Spark asks the Kubernetes API server for executor pods directly through its native Kubernetes scheduler backend.&amp;lt;ref name=&amp;quot;k8s&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/running-on-kubernetes.html |title=Running Spark on Kubernetes (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Applications are submitted with [[Spark-submit|spark-submit]] using a &amp;lt;code&amp;gt;k8s://&amp;lt;/code&amp;gt; master URL, or declaratively through the [[Kubernetes Operator for Apache Spark]], a separate Apache Spark subproject that uses the same scheduler backend.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt; Spark 4.3.0 documents Kubernetes 1.34 or newer as a prerequisite.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does Spark run on Kubernetes? ==&lt;br /&gt;
When an application is submitted in cluster mode, Spark creates the driver inside a Kubernetes pod. The driver then creates executor pods, connects to them and runs the application code. When the application finishes, the executor pods terminate and are cleaned up, while the driver pod stays in the &amp;quot;completed&amp;quot; state, keeping its logs, until it is garbage collected or deleted; a completed driver pod uses no compute or memory resources.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Kubernetes, not Spark, schedules the driver and executor pods onto nodes. Spark talks to the Kubernetes API through the fabric8 Kubernetes client, and node selectors can restrict pods to a subset of nodes.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt; Spark launches executor pods in rounds; &amp;lt;code&amp;gt;spark.kubernetes.allocation.batch.size&amp;lt;/code&amp;gt; (default 20) is the number of pods launched in each round.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The driver needs permission to manage its executors. The service account used by the driver pod must be allowed to create pods, services and configmaps, and it is set with &amp;lt;code&amp;gt;spark.kubernetes.authenticate.driver.serviceAccountName&amp;lt;/code&amp;gt; (default &amp;lt;code&amp;gt;default&amp;lt;/code&amp;gt;).&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How do you submit a PySpark application to Kubernetes? ==&lt;br /&gt;
The master URL has the form &amp;lt;code&amp;gt;k8s://&amp;lt;api_server_host&amp;gt;:&amp;lt;port&amp;gt;&amp;lt;/code&amp;gt;; the port is required even when it is 443, and the scheme defaults to HTTPS.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt; The application name is used to name the Kubernetes resources, so it must contain only lowercase alphanumeric characters, &amp;lt;code&amp;gt;-&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;.&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt; The image comes from &amp;lt;code&amp;gt;spark.kubernetes.container.image&amp;lt;/code&amp;gt;; Spark ships Dockerfiles and &amp;lt;code&amp;gt;bin/docker-image-tool.sh&amp;lt;/code&amp;gt; to build images (including a PySpark image), and the Apache Spark images on Docker Hub (&amp;lt;code&amp;gt;apache/spark&amp;lt;/code&amp;gt;) can be used directly.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./bin/spark-submit \&lt;br /&gt;
  --master k8s://https://k8s-apiserver.example.com:6443 \&lt;br /&gt;
  --deploy-mode cluster \&lt;br /&gt;
  --name daily-orders \&lt;br /&gt;
  --conf spark.kubernetes.namespace=spark-jobs \&lt;br /&gt;
  --conf spark.kubernetes.authenticate.driver.serviceAccountName=spark \&lt;br /&gt;
  --conf spark.kubernetes.container.image=apache/spark:4.3.0-python3 \&lt;br /&gt;
  --conf spark.executor.instances=4 \&lt;br /&gt;
  local:///opt/app/daily_orders.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;local://&amp;lt;/code&amp;gt; scheme points to a file already inside the image. Dependencies on the submitting machine (&amp;lt;code&amp;gt;file://&amp;lt;/code&amp;gt; or a plain path) are uploaded to a Hadoop-compatible file system set by &amp;lt;code&amp;gt;spark.kubernetes.file.upload.path&amp;lt;/code&amp;gt;, for example an S3 bucket, and downloaded by the driver pod.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt; The namespace defaults to &amp;lt;code&amp;gt;default&amp;lt;/code&amp;gt; when &amp;lt;code&amp;gt;spark.kubernetes.namespace&amp;lt;/code&amp;gt; is not set.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In cluster mode, &amp;lt;code&amp;gt;spark-submit --status&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spark-submit --kill&amp;lt;/code&amp;gt; take a submission ID of the form &amp;lt;code&amp;gt;namespace:driver-pod-name&amp;lt;/code&amp;gt;, and both accept glob patterns.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What is the difference between cluster mode and client mode on Kubernetes? ==&lt;br /&gt;
In cluster mode the driver runs in a pod that Spark creates. Client mode, supported since Spark 2.4.0, lets the driver run in an existing pod or on a host outside the cluster.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt; In client mode the executors must be able to reach the driver at a routable host name and port (&amp;lt;code&amp;gt;spark.driver.host&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spark.driver.port&amp;lt;/code&amp;gt;); for a driver in a pod, the documentation suggests a headless service.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In client mode inside a pod, setting &amp;lt;code&amp;gt;spark.kubernetes.driver.pod.name&amp;lt;/code&amp;gt; to the driver pod&amp;#039;s name makes Spark add an OwnerReference to each executor pod, so Kubernetes deletes the executors when the driver pod is deleted. Without it, executor pods can remain in the cluster if Spark&amp;#039;s own deletion request fails.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What are pod templates? ==&lt;br /&gt;
A pod template is a Kubernetes pod specification file that Spark uses as the starting point for the driver or executor pod, for settings that Spark configuration properties do not cover (for example security contexts or sidecar containers). The files are set with &amp;lt;code&amp;gt;spark.kubernetes.driver.podTemplateFile&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spark.kubernetes.executor.podTemplateFile&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spark does not validate pod templates and leaves validation to the API server. Spark always overwrites some fields, such as the namespace and the driver&amp;#039;s service account, so a template only gives Spark a non-empty pod to start from. When a template defines several containers, &amp;lt;code&amp;gt;spark.kubernetes.driver.podTemplateContainerName&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spark.kubernetes.executor.podTemplateContainerName&amp;lt;/code&amp;gt; choose the Spark container; otherwise the first container is used.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How are volumes and local storage configured? ==&lt;br /&gt;
Spark on Kubernetes can mount four volume types into driver and executor pods: &amp;lt;code&amp;gt;hostPath&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;emptyDir&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;nfs&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;persistentVolumeClaim&amp;lt;/code&amp;gt;. Volumes are declared with properties of the form &amp;lt;code&amp;gt;spark.kubernetes.[driver|executor].volumes.[VolumeType].[VolumeName].mount.path&amp;lt;/code&amp;gt;, plus type-specific &amp;lt;code&amp;gt;options.*&amp;lt;/code&amp;gt; properties.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt; The documentation warns that &amp;lt;code&amp;gt;hostPath&amp;lt;/code&amp;gt; volumes have known security risks and recommends the Pod Security Admission controller to limit them.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For executors, a claim name of &amp;lt;code&amp;gt;OnDemand&amp;lt;/code&amp;gt; creates a persistent volume claim per executor, with &amp;lt;code&amp;gt;storageClass&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sizeLimit&amp;lt;/code&amp;gt; options. Since Spark 3.4 the driver can own these claims and reuse them for new executors (&amp;lt;code&amp;gt;spark.kubernetes.driver.ownPersistentVolumeClaim&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spark.kubernetes.driver.reusePersistentVolumeClaim&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spark.kubernetes.driver.waitToReusePersistentVolumeClaim&amp;lt;/code&amp;gt;).&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Volumes whose names start with &amp;lt;code&amp;gt;spark-local-dir-&amp;lt;/code&amp;gt; are used as Spark local storage for shuffle and spill data. Without one, Spark uses an &amp;lt;code&amp;gt;emptyDir&amp;lt;/code&amp;gt; volume, which does not outlive the pod; &amp;lt;code&amp;gt;spark.kubernetes.local.dirs.tmpfs=true&amp;lt;/code&amp;gt; makes these volumes RAM-backed, which counts toward the pod&amp;#039;s memory.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;properties&amp;quot;&amp;gt;&lt;br /&gt;
spark.kubernetes.executor.volumes.persistentVolumeClaim.spark-local-dir-1.options.claimName=OnDemand&lt;br /&gt;
spark.kubernetes.executor.volumes.persistentVolumeClaim.spark-local-dir-1.options.storageClass=gp&lt;br /&gt;
spark.kubernetes.executor.volumes.persistentVolumeClaim.spark-local-dir-1.options.sizeLimit=500Gi&lt;br /&gt;
spark.kubernetes.executor.volumes.persistentVolumeClaim.spark-local-dir-1.mount.path=/data&lt;br /&gt;
spark.kubernetes.executor.volumes.persistentVolumeClaim.spark-local-dir-1.mount.readOnly=false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does memory and dynamic allocation differ on Kubernetes? ==&lt;br /&gt;
Each executor pod requests its heap plus overhead memory. &amp;lt;code&amp;gt;spark.executor.memoryOverheadFactor&amp;lt;/code&amp;gt; defaults to 0.10, except for Kubernetes non-JVM jobs (such as PySpark), where it defaults to 0.40 because non-JVM tasks need more memory outside the heap.&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; CPU requests and limits for pods can be set separately with &amp;lt;code&amp;gt;spark.kubernetes.executor.request.cores&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spark.kubernetes.executor.limit.cores&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Dynamic allocation works on Kubernetes, but Spark on Kubernetes does not support the external shuffle service, so &amp;lt;code&amp;gt;spark.shuffle.service.enabled=true&amp;lt;/code&amp;gt; cannot be used to keep shuffle files.&amp;lt;ref name=&amp;quot;jobsched&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/job-scheduling.html |title=Job Scheduling (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Shuffle tracking, decommissioning with shuffle block migration, or a shuffle storage plugin are used instead; see [[Executor#Dynamic allocation|Executor: dynamic allocation]]. Spark 4.3.0 also ships a &amp;lt;code&amp;gt;KubernetesLocalDiskShuffleDataIO&amp;lt;/code&amp;gt; plugin that recovers shuffle data from reused persistent volume claims.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does it relate to the Kubernetes Operator for Apache Spark? ==&lt;br /&gt;
{{Main|Kubernetes Operator for Apache Spark}}&lt;br /&gt;
The Apache Spark Kubernetes Operator is a separate Apache Spark project that manages Spark workloads declaratively through custom resources: &amp;lt;code&amp;gt;SparkApplication&amp;lt;/code&amp;gt; for applications and &amp;lt;code&amp;gt;SparkCluster&amp;lt;/code&amp;gt; for [[Spark standalone cluster manager|standalone]] clusters. The Spark documentation calls the two approaches complementary, because the operator runs applications on the same native Kubernetes scheduler backend that spark-submit uses.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt; Its latest release is 1.1.0, published on 12 November 2026.&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark-kubernetes-operator/releases/tag/1.1.0 |title=Release 1.1.0 |publisher=apache/spark-kubernetes-operator on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
Spark 2.3.0 added the Kubernetes scheduler backend for native submission to Kubernetes (SPARK-18278) and marked it experimental.&amp;lt;ref&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-2-3-0.html |title=Spark Release 2.3.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Spark 3.1.1 declared Kubernetes support generally available (SPARK-33005).&amp;lt;ref&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-3-1-1.html |title=Spark Release 3.1.1 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-33005 |title=SPARK-33005: Kubernetes GA Preparation |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Spark on Kubernetes is not deprecated in Spark 4.3.0.&lt;br /&gt;
&lt;br /&gt;
== Spark on Kubernetes compared with other cluster managers ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! !! Spark on Kubernetes !! [[Spark on YARN]] !! [[Spark standalone cluster manager|Spark standalone]]&lt;br /&gt;
|-&lt;br /&gt;
! Driver and executors run in&lt;br /&gt;
| Kubernetes pods&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt; || YARN containers&amp;lt;ref name=&amp;quot;yarn&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/running-on-yarn.html |title=Running Spark on YARN (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; || Processes on standalone workers&amp;lt;ref name=&amp;quot;standalone&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/spark-standalone.html |title=Spark Standalone Mode (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Master URL&lt;br /&gt;
| &amp;lt;code&amp;gt;k8s://HOST:PORT&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;yarn&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;spark://HOST:PORT&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;submit&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/submitting-applications.html |title=Submitting Applications (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! External shuffle service&lt;br /&gt;
| Not supported || Supported || Supported&amp;lt;ref name=&amp;quot;jobsched&amp;quot; /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Kubernetes Operator for Apache Spark]]&lt;br /&gt;
* [[Spark-submit|spark-submit]]&lt;br /&gt;
* [[Executor]]&lt;br /&gt;
* [[Spark on YARN]]&lt;br /&gt;
* [[Spark standalone cluster manager]]&lt;br /&gt;
* [[Spark configuration precedence]]&lt;br /&gt;
* [[Spark Connect]]&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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:55 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Spark_on_Kubernetes</comments>
		</item>
		<item>
			<title>Spark on YARN</title>
			<link>https://openlakehouse.io/w/index.php?title=Spark_on_YARN&amp;diff=193&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Spark_on_YARN&amp;diff=193&amp;oldid=0</guid>
			<description>&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            = Spark on YARN&lt;br /&gt;
| also_known_as   = Running Spark on Hadoop YARN&lt;br /&gt;
| field           = Cluster resource management&lt;br /&gt;
| key_parts       = YARN ResourceManager, NodeManagers, containers, the Spark application master, queues&lt;br /&gt;
| implementations = [[Apache Spark]] with Apache Hadoop YARN&lt;br /&gt;
| related         = [[Spark standalone cluster manager]], [[Spark on Kubernetes]], [[Spark-submit|spark-submit]], [[Executor]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (docs/running-on-yarn.md, docs/submitting-applications.md, docs/configuration.md, docs/job-scheduling.md, docs/cluster-overview.md, docs/core-migration-guide.md) and the Spark 0.6.0 release notes}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Spark on YARN&amp;#039;&amp;#039;&amp;#039; is the deployment of [[Apache Spark]] applications on Apache Hadoop YARN (Yet Another Resource Negotiator), where the YARN ResourceManager grants containers on cluster nodes and Spark runs its application master, its driver (in cluster mode) and its [[Executor|executors]] inside those containers.&amp;lt;ref name=&amp;quot;yarn&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/running-on-yarn.html |title=Running Spark on YARN (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; It lets Spark share a Hadoop cluster with other YARN workloads under the same queues and Kerberos security.&amp;lt;ref name=&amp;quot;yarn&amp;quot; /&amp;gt; YARN is one of the three cluster managers supported in Spark 4.3.0, with the [[Spark standalone cluster manager|standalone manager]] and [[Spark on Kubernetes|Kubernetes]].&amp;lt;ref name=&amp;quot;overview&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/cluster-overview.html |title=Cluster Mode 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;
== Is Spark on YARN deprecated? ==&lt;br /&gt;
No. YARN support is not deprecated in Spark 4.3.0; the cluster mode overview lists Hadoop YARN as a supported cluster manager.&amp;lt;ref name=&amp;quot;overview&amp;quot; /&amp;gt; Individual YARN settings have been deprecated: since Spark 3.5, &amp;lt;code&amp;gt;spark.yarn.max.executor.failures&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spark.yarn.executor.failuresValidityInterval&amp;lt;/code&amp;gt; are replaced by &amp;lt;code&amp;gt;spark.executor.maxNumFailures&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spark.executor.failuresValidityInterval&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;coremig&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/core-migration-guide.html |title=Migration Guide: Spark Core (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
Spark 0.6.0 added experimental support for running on YARN, then in a separate branch; the Spark documentation dates YARN support to that release.&amp;lt;ref&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-0-6-0.html |title=Spark Release 0.6.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;yarn&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does Spark run on YARN? ==&lt;br /&gt;
Every Spark application on YARN has an &amp;#039;&amp;#039;&amp;#039;application master&amp;#039;&amp;#039;&amp;#039; (AM), a process managed by YARN that requests executor containers from the ResourceManager; in cluster mode the driver also runs inside it. In YARN terminology, both executors and the AM run inside &amp;#039;&amp;#039;&amp;#039;containers&amp;#039;&amp;#039;&amp;#039;.&amp;lt;ref name=&amp;quot;yarn&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spark does not take the ResourceManager address from &amp;lt;code&amp;gt;--master&amp;lt;/code&amp;gt;. The master URL is simply &amp;lt;code&amp;gt;yarn&amp;lt;/code&amp;gt;, and Spark reads the cluster location from the Hadoop configuration directory given by &amp;lt;code&amp;gt;HADOOP_CONF_DIR&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;YARN_CONF_DIR&amp;lt;/code&amp;gt;; that configuration is also shipped to every container.&amp;lt;ref name=&amp;quot;yarn&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What is the difference between client and cluster mode on YARN? ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! !! Cluster mode !! Client mode&lt;br /&gt;
|-&lt;br /&gt;
! Where the driver runs&lt;br /&gt;
| Inside the YARN application master container || In the client process that ran &amp;lt;code&amp;gt;spark-submit&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Role of the AM&lt;br /&gt;
| Runs the driver and requests executors || Only requests executors&lt;br /&gt;
|-&lt;br /&gt;
! Can the client exit?&lt;br /&gt;
| Yes, after the application starts || No, the driver lives in it&lt;br /&gt;
|-&lt;br /&gt;
! AM sizing&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.driver.memory&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spark.driver.cores&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;spark.yarn.am.memory&amp;lt;/code&amp;gt; (default &amp;lt;code&amp;gt;512m&amp;lt;/code&amp;gt;), &amp;lt;code&amp;gt;spark.yarn.am.cores&amp;lt;/code&amp;gt; (default 1)&lt;br /&gt;
|-&lt;br /&gt;
! Local directories of the driver&lt;br /&gt;
| YARN&amp;#039;s &amp;lt;code&amp;gt;yarn.nodemanager.local-dirs&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;spark.local.dir&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
Source: Running Spark on YARN (Spark 4.3.0).&amp;lt;ref name=&amp;quot;yarn&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Spark documentation runs interactive shells such as &amp;lt;code&amp;gt;spark-shell&amp;lt;/code&amp;gt; in client mode, where the console stays attached to the driver. In cluster mode, local files that the driver needs must be shipped with &amp;lt;code&amp;gt;--jars&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;--files&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;--archives&amp;lt;/code&amp;gt;, because the driver runs on another machine.&amp;lt;ref name=&amp;quot;yarn&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export HADOOP_CONF_DIR=/etc/hadoop/conf&lt;br /&gt;
./bin/spark-submit \&lt;br /&gt;
  --master yarn \&lt;br /&gt;
  --deploy-mode cluster \&lt;br /&gt;
  --queue analytics \&lt;br /&gt;
  --driver-memory 4g \&lt;br /&gt;
  --executor-memory 8g \&lt;br /&gt;
  --executor-cores 4 \&lt;br /&gt;
  --num-executors 20 \&lt;br /&gt;
  etl_job.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How do queues work? ==&lt;br /&gt;
YARN schedules applications into queues defined by the cluster&amp;#039;s YARN scheduler configuration. A Spark application chooses its queue with &amp;lt;code&amp;gt;--queue&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;spark.yarn.queue&amp;lt;/code&amp;gt;, which defaults to &amp;lt;code&amp;gt;default&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;yarn&amp;quot; /&amp;gt; Whether YARN honors the number of cores requested when placing containers depends on which YARN scheduler is in use and how it is configured.&amp;lt;ref name=&amp;quot;yarn&amp;quot; /&amp;gt; &amp;lt;code&amp;gt;spark.yarn.tags&amp;lt;/code&amp;gt; attaches YARN application tags that can be used to filter applications.&amp;lt;ref name=&amp;quot;yarn&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How is container memory sized? ==&lt;br /&gt;
Each executor container on YARN holds the executor heap (&amp;lt;code&amp;gt;spark.executor.memory&amp;lt;/code&amp;gt;) plus non-heap overhead (&amp;lt;code&amp;gt;spark.executor.memoryOverhead&amp;lt;/code&amp;gt;), which defaults to the executor memory times &amp;lt;code&amp;gt;spark.executor.memoryOverheadFactor&amp;lt;/code&amp;gt; with a minimum of &amp;lt;code&amp;gt;spark.executor.minMemoryOverhead&amp;lt;/code&amp;gt;. The overhead covers JVM overheads, interned strings and other native memory, and includes PySpark worker memory unless &amp;lt;code&amp;gt;spark.executor.pyspark.memory&amp;lt;/code&amp;gt; is set.&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; In client mode the AM has its own overhead, &amp;lt;code&amp;gt;spark.yarn.am.memoryOverhead&amp;lt;/code&amp;gt;, which defaults to 10% of the AM memory with a minimum of 384 MiB.&amp;lt;ref name=&amp;quot;yarn&amp;quot; /&amp;gt; The [[Executor]] article covers the memory layout inside the heap.&lt;br /&gt;
&lt;br /&gt;
On YARN, &amp;lt;code&amp;gt;spark.executor.cores&amp;lt;/code&amp;gt; defaults to 1 and &amp;lt;code&amp;gt;spark.executor.instances&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;--num-executors&amp;lt;/code&amp;gt;) to 2.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;yarn&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What still matters when running Spark on YARN? ==&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Java version.&amp;#039;&amp;#039;&amp;#039; Spark 4.0.0 and later need at least Java 17, and Hadoop supports Java 17 from 3.5.0. On a YARN cluster with an older Hadoop, the Spark documentation says to configure a separate JDK for Spark by setting &amp;lt;code&amp;gt;JAVA_HOME&amp;lt;/code&amp;gt; for the AM (&amp;lt;code&amp;gt;spark.yarn.appMasterEnv.JAVA_HOME&amp;lt;/code&amp;gt;) and executors (&amp;lt;code&amp;gt;spark.executorEnv.JAVA_HOME&amp;lt;/code&amp;gt;).&amp;lt;ref name=&amp;quot;yarn&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Spark JARs.&amp;#039;&amp;#039;&amp;#039; Unless &amp;lt;code&amp;gt;spark.yarn.archive&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;spark.yarn.jars&amp;lt;/code&amp;gt; points to a prepared copy, Spark zips every JAR under &amp;lt;code&amp;gt;$SPARK_HOME/jars&amp;lt;/code&amp;gt; and uploads it to the distributed cache for each application.&amp;lt;ref name=&amp;quot;yarn&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Hadoop classpath.&amp;#039;&amp;#039;&amp;#039; A Spark distribution built with Hadoop does not add YARN&amp;#039;s classpath to the application by default (since Spark 3.1), to avoid dependency conflicts; &amp;lt;code&amp;gt;spark.yarn.populateHadoopClasspath=true&amp;lt;/code&amp;gt; changes this.&amp;lt;ref name=&amp;quot;yarn&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;coremig&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Dynamic allocation and shuffle files.&amp;#039;&amp;#039;&amp;#039; To remove executors without losing their shuffle files, Spark needs an external shuffle service, shuffle tracking, shuffle block migration on decommission, or a reliable shuffle storage plugin.&amp;lt;ref name=&amp;quot;jobsched&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/job-scheduling.html |title=Job Scheduling (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; On YARN the external shuffle service runs inside each NodeManager as the auxiliary service &amp;lt;code&amp;gt;spark_shuffle&amp;lt;/code&amp;gt;, implemented by &amp;lt;code&amp;gt;org.apache.spark.network.yarn.YarnShuffleService&amp;lt;/code&amp;gt; from the &amp;lt;code&amp;gt;spark-&amp;amp;lt;version&amp;amp;gt;-yarn-shuffle.jar&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;yarn&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Kerberos.&amp;#039;&amp;#039;&amp;#039; On YARN, Spark obtains delegation tokens for the default Hadoop file system and for the service that hosts the application&amp;#039;s staging directory; an application can log in to the Kerberos KDC with &amp;lt;code&amp;gt;--principal&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;--keytab&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;yarn&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;ssargs&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/deploy/SparkSubmitArguments.scala |title=SparkSubmitArguments.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Logs.&amp;#039;&amp;#039;&amp;#039; With YARN log aggregation (&amp;lt;code&amp;gt;yarn.log-aggregation-enable&amp;lt;/code&amp;gt;), container logs are copied to HDFS after the application ends and can be read with &amp;lt;code&amp;gt;yarn logs -applicationId &amp;amp;lt;app ID&amp;amp;gt;&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;yarn&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Retries.&amp;#039;&amp;#039;&amp;#039; &amp;lt;code&amp;gt;spark.yarn.maxAppAttempts&amp;lt;/code&amp;gt; sets how many times YARN attempts the application, and must not exceed YARN&amp;#039;s own &amp;lt;code&amp;gt;yarn.resourcemanager.am.max-attempts&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;yarn&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Spark-submit|spark-submit]]&lt;br /&gt;
* [[Spark on Kubernetes]]&lt;br /&gt;
* [[Spark standalone cluster manager]]&lt;br /&gt;
* [[Spark configuration precedence]]&lt;br /&gt;
* [[Executor]]&lt;br /&gt;
* [[Driver (Apache Spark)]]&lt;br /&gt;
* [[Hive on 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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:55 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Spark_on_YARN</comments>
		</item>
		<item>
			<title>Spark Kubernetes pod template</title>
			<link>https://openlakehouse.io/w/index.php?title=Spark_Kubernetes_pod_template&amp;diff=188&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Spark_Kubernetes_pod_template&amp;diff=188&amp;oldid=0</guid>
			<description>&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            = Spark Kubernetes pod template&lt;br /&gt;
| also_known_as   = Pod template file, driver pod template, executor pod template&lt;br /&gt;
| field           = Cluster resource management&lt;br /&gt;
| introduced      = Apache Spark 3.0.0&lt;br /&gt;
| key_parts       = &amp;lt;code&amp;gt;spark.kubernetes.driver.podTemplateFile&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spark.kubernetes.executor.podTemplateFile&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;podTemplateContainerName&amp;lt;/code&amp;gt;&lt;br /&gt;
| implementations = [[Apache Spark]]&lt;br /&gt;
| related         = [[Spark on Kubernetes]], [[Executor]], [[Spark Kubernetes shuffle storage]], [[Executor decommissioning]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (docs/running-on-kubernetes.md and resource-managers/kubernetes/core/.../deploy/k8s/Config.scala), SPARK-24434 and the Kubernetes sidecar containers page}}&lt;br /&gt;
&lt;br /&gt;
In [[Apache Spark]], a &amp;#039;&amp;#039;&amp;#039;Kubernetes pod template&amp;#039;&amp;#039;&amp;#039; is a YAML or JSON pod specification that Spark uses as the starting point when it builds the driver pod or the executor pods of an application on Kubernetes.&amp;lt;ref name=&amp;quot;k8s&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/running-on-kubernetes.html |title=Running Spark on Kubernetes (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; A pod template sets pod fields that have no Spark configuration property, such as tolerations, security contexts, priority classes and extra containers. Spark still overwrites a fixed list of fields, so the template is a base that Spark completes rather than a final pod definition.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt; The feature is part of [[Spark on Kubernetes]] and is also used by the [[Kubernetes Operator for Apache Spark]], which runs applications on the same scheduler backend.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Which configuration keys control a pod template? ==&lt;br /&gt;
Four Spark properties control pod templates. All four were added in Apache Spark 3.0.0 and have no default value.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;config&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/Config.scala |title=Config.scala (Kubernetes resource manager, v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;jira24434&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-24434 |title=SPARK-24434: Support user-specified driver and executor pod templates |publisher=Apache Software Foundation JIRA |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;
! Property !! Purpose&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.kubernetes.driver.podTemplateFile&amp;lt;/code&amp;gt; || File with the template for the driver pod&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.kubernetes.executor.podTemplateFile&amp;lt;/code&amp;gt; || File with the template for every executor pod&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.kubernetes.driver.podTemplateContainerName&amp;lt;/code&amp;gt; || Name of the container in the driver template that becomes the Spark driver container&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.kubernetes.executor.podTemplateContainerName&amp;lt;/code&amp;gt; || Name of the container in the executor template that becomes the Spark executor container&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The template files must be readable by the &amp;lt;code&amp;gt;spark-submit&amp;lt;/code&amp;gt; process, and the Spark documentation shows them read from object storage, for example &amp;lt;code&amp;gt;s3a://bucket/executor.yml&amp;lt;/code&amp;gt;. In cluster mode Spark mounts the executor template into the driver pod as a volume, because the driver creates the executor pods.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spark does not validate a template after parsing it. Validation is left to the Kubernetes API server, so an invalid field shows up as a rejected pod creation rather than a Spark error.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does Spark choose the Spark container in a template? ==&lt;br /&gt;
A pod template can list several containers. Spark uses the container named by &amp;lt;code&amp;gt;spark.kubernetes.driver.podTemplateContainerName&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;spark.kubernetes.executor.podTemplateContainerName&amp;lt;/code&amp;gt; as the basis for the driver or executor container. If the property is unset, or names a container that does not exist, Spark takes the first container in the list.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spark changes only the driver or executor container. Every other container in the template is passed to Kubernetes unchanged.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt; If the template does not name the Spark container, Spark calls it &amp;lt;code&amp;gt;spark-kubernetes-driver&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;spark-kubernetes-executor&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Which pod template fields does Spark override? ==&lt;br /&gt;
The Spark documentation lists the fields that Spark always sets or adds to, whatever the template says.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Level !! Field !! What Spark does&lt;br /&gt;
|-&lt;br /&gt;
| Pod metadata || &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; || Sets the driver pod name from &amp;lt;code&amp;gt;spark.kubernetes.driver.pod.name&amp;lt;/code&amp;gt;; executor pod names are not taken from the template&lt;br /&gt;
|-&lt;br /&gt;
| Pod metadata || &amp;lt;code&amp;gt;namespace&amp;lt;/code&amp;gt; || Replaced by &amp;lt;code&amp;gt;spark.kubernetes.namespace&amp;lt;/code&amp;gt; for driver and executors&lt;br /&gt;
|-&lt;br /&gt;
| Pod metadata || &amp;lt;code&amp;gt;labels&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;annotations&amp;lt;/code&amp;gt; || Keeps the template&amp;#039;s entries and adds those from &amp;lt;code&amp;gt;spark.kubernetes.{driver,executor}.label.*&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;.annotation.*&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Pod spec || &amp;lt;code&amp;gt;restartPolicy&amp;lt;/code&amp;gt; || Always &amp;lt;code&amp;gt;Never&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Pod spec || &amp;lt;code&amp;gt;nodeSelector&amp;lt;/code&amp;gt; || Adds selectors from &amp;lt;code&amp;gt;spark.kubernetes.node.selector.*&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Pod spec || &amp;lt;code&amp;gt;imagePullSecrets&amp;lt;/code&amp;gt; || Adds secrets from &amp;lt;code&amp;gt;spark.kubernetes.container.image.pullSecrets&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Pod spec || &amp;lt;code&amp;gt;serviceAccount&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;serviceAccountName&amp;lt;/code&amp;gt; || Driver only, and only when &amp;lt;code&amp;gt;spark.kubernetes.authenticate.driver.serviceAccountName&amp;lt;/code&amp;gt; is set and no driver credentials are mounted&lt;br /&gt;
|-&lt;br /&gt;
| Pod spec || &amp;lt;code&amp;gt;volumes&amp;lt;/code&amp;gt; || Adds volumes from &amp;lt;code&amp;gt;spark.kubernetes.{driver,executor}.volumes.*&amp;lt;/code&amp;gt; plus the volumes that carry the Spark configuration and template files&lt;br /&gt;
|-&lt;br /&gt;
| Spark container || &amp;lt;code&amp;gt;image&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;imagePullPolicy&amp;lt;/code&amp;gt; || Set from &amp;lt;code&amp;gt;spark.kubernetes.{driver,executor}.container.image&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spark.kubernetes.container.image.pullPolicy&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Spark container || &amp;lt;code&amp;gt;resources&amp;lt;/code&amp;gt; || CPU from &amp;lt;code&amp;gt;spark.{driver,executor}.cores&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spark.kubernetes.{driver,executor}.limit.cores&amp;lt;/code&amp;gt;; memory request and limit from memory plus memory overhead&lt;br /&gt;
|-&lt;br /&gt;
| Spark container || &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;volumeMounts&amp;lt;/code&amp;gt; || Adds environment variables and mounts from the Spark configuration&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Fields not in this list, such as &amp;lt;code&amp;gt;tolerations&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;affinity&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;priorityClassName&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;securityContext&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;initContainers&amp;lt;/code&amp;gt;, are taken from the template as written.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt; The documentation uses &amp;lt;code&amp;gt;priorityClassName&amp;lt;/code&amp;gt; in a template as its example of priority scheduling.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Resources in a template apply only to the default resource profile. With stage-level scheduling, custom ResourceProfiles do not inherit resources from the template file, so they must declare every resource they need.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What is a pod template commonly used for? ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Scheduling.&amp;#039;&amp;#039;&amp;#039; Node selectors can be set without a template: &amp;lt;code&amp;gt;spark.kubernetes.node.selector.[labelKey]&amp;lt;/code&amp;gt; (since Spark 2.3.0) applies to driver and executors, and the driver-only and executor-only variants were added in Spark 3.3.0.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt; Tolerations and affinity rules have no Spark property and are set through the template.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Volumes.&amp;#039;&amp;#039;&amp;#039; Spark properties can mount &amp;lt;code&amp;gt;hostPath&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;emptyDir&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;nfs&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;persistentVolumeClaim&amp;lt;/code&amp;gt; volumes.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt; Other volume types, such as a ConfigMap or projected volume, are declared in the template. Volumes for shuffle and spill data are described in [[Spark Kubernetes shuffle storage]].&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Sidecars.&amp;#039;&amp;#039;&amp;#039; A template can add containers next to the Spark container, for example a log shipper. Kubernetes treats an init container with &amp;lt;code&amp;gt;restartPolicy: Always&amp;lt;/code&amp;gt; as a native sidecar; it is stable since Kubernetes 1.33, and the kubelet waits until the main container has stopped before it terminates the sidecar.&amp;lt;ref name=&amp;quot;sidecar&amp;quot;&amp;gt;{{Cite web |url=https://kubernetes.io/docs/concepts/workloads/pods/sidecar-containers/ |title=Sidecar Containers |publisher=The Kubernetes Authors |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Spark 4.3.0 documents Kubernetes 1.34 or later as a prerequisite.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Security contexts.&amp;#039;&amp;#039;&amp;#039; The Spark images built from the project Dockerfiles run as UID 185. The documentation names the pod template as the way to add a security context with &amp;lt;code&amp;gt;runAsUser&amp;lt;/code&amp;gt; that overrides the image&amp;#039;s user.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt; Apache Spark 4.3.0 added &amp;lt;code&amp;gt;spark.kubernetes.securityContext.allowPrivilegeEscalation&amp;lt;/code&amp;gt; (default false) and driver and executor variants, which set the &amp;lt;code&amp;gt;allowPrivilegeEscalation&amp;lt;/code&amp;gt; field of the Spark containers.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
An executor pod template that pins executors to a tainted node pool, runs them as a non-root user and adds a native sidecar. The &amp;lt;code&amp;gt;image&amp;lt;/code&amp;gt; value is replaced by Spark.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;yaml&amp;quot;&amp;gt;&lt;br /&gt;
apiVersion: v1&lt;br /&gt;
kind: Pod&lt;br /&gt;
spec:&lt;br /&gt;
  nodeSelector:&lt;br /&gt;
    pool: spark&lt;br /&gt;
  tolerations:&lt;br /&gt;
  - key: dedicated&lt;br /&gt;
    operator: Equal&lt;br /&gt;
    value: spark&lt;br /&gt;
    effect: NoSchedule&lt;br /&gt;
  securityContext:&lt;br /&gt;
    runAsUser: 185&lt;br /&gt;
    runAsNonRoot: true&lt;br /&gt;
  initContainers:&lt;br /&gt;
  - name: log-shipper&lt;br /&gt;
    image: example.org/log-shipper:1.0&lt;br /&gt;
    restartPolicy: Always&lt;br /&gt;
  containers:&lt;br /&gt;
  - name: spark-executor&lt;br /&gt;
    image: will-be-overwritten&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
spark.kubernetes.executor.podTemplateFile           s3a://bucket/executor.yml&lt;br /&gt;
spark.kubernetes.executor.podTemplateContainerName  spark-executor&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Spark on Kubernetes]]&lt;br /&gt;
* [[Kubernetes Operator for Apache Spark]]&lt;br /&gt;
* [[Executor]]&lt;br /&gt;
* [[Spark Kubernetes shuffle storage]]&lt;br /&gt;
* [[Executor decommissioning]]&lt;br /&gt;
* [[Apache 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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:54 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Spark_Kubernetes_pod_template</comments>
		</item>
		<item>
			<title>Spark Kubernetes shuffle storage</title>
			<link>https://openlakehouse.io/w/index.php?title=Spark_Kubernetes_shuffle_storage&amp;diff=189&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Spark_Kubernetes_shuffle_storage&amp;diff=189&amp;oldid=0</guid>
			<description>&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            = Spark Kubernetes shuffle storage&lt;br /&gt;
| also_known_as   = Spark local storage on Kubernetes, spark-local-dir volumes&lt;br /&gt;
| field           = Distributed data processing&lt;br /&gt;
| key_parts       = &amp;lt;code&amp;gt;emptyDir&amp;lt;/code&amp;gt; scratch volumes, &amp;lt;code&amp;gt;spark-local-dir-*&amp;lt;/code&amp;gt; volumes, on-demand persistent volume claims, &amp;lt;code&amp;gt;KubernetesLocalDiskShuffleDataIO&amp;lt;/code&amp;gt;&lt;br /&gt;
| implementations = [[Apache Spark]]&lt;br /&gt;
| related         = [[Shuffle]], [[Executor]], [[Spark on Kubernetes]], [[Executor decommissioning]], [[Spark Kubernetes pod template]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (docs/running-on-kubernetes.md, docs/job-scheduling.md, docs/configuration.md, docs/core-migration-guide.md, deploy/k8s/Config.scala, KubernetesLocalDiskShuffleDataIO.scala) and SPARK-25262, SPARK-28042, SPARK-32971, SPARK-35182, SPARK-35416, SPARK-35593}}&lt;br /&gt;
&lt;br /&gt;
In [[Apache Spark]], &amp;#039;&amp;#039;&amp;#039;shuffle storage on Kubernetes&amp;#039;&amp;#039;&amp;#039; is the set of pod volumes where executors write [[shuffle]] files and spill data; by default these are Kubernetes &amp;lt;code&amp;gt;emptyDir&amp;lt;/code&amp;gt; volumes that last only as long as the executor pod.&amp;lt;ref name=&amp;quot;k8s&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/running-on-kubernetes.html |title=Running Spark on Kubernetes (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Spark on Kubernetes has no external shuffle service, so shuffle files written by an [[Executor|executor]] are normally lost when its pod goes away.&amp;lt;ref name=&amp;quot;jobsched&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/job-scheduling.html |title=Job Scheduling (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Spark offers RAM-backed volumes, host disks, persistent volume claims (PVCs) that the driver reuses, and a shuffle plugin that recovers files from reused PVCs.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Where does Spark write shuffle and spill data on Kubernetes by default? ==&lt;br /&gt;
When no volume is configured as local storage, Spark on Kubernetes mounts one &amp;lt;code&amp;gt;emptyDir&amp;lt;/code&amp;gt; volume for each directory in &amp;lt;code&amp;gt;spark.local.dir&amp;lt;/code&amp;gt; or the &amp;lt;code&amp;gt;SPARK_LOCAL_DIRS&amp;lt;/code&amp;gt; environment variable. If neither is set, Spark creates and configures a default directory.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
An &amp;lt;code&amp;gt;emptyDir&amp;lt;/code&amp;gt; volume uses the ephemeral storage of the node and does not outlive the pod. Shuffle files on it disappear when the executor pod is deleted.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does spark.kubernetes.local.dirs.tmpfs work? ==&lt;br /&gt;
&amp;lt;code&amp;gt;spark.kubernetes.local.dirs.tmpfs&amp;lt;/code&amp;gt; (default false, added in Spark 3.0.0) sets the medium of the scratch &amp;lt;code&amp;gt;emptyDir&amp;lt;/code&amp;gt; volumes to &amp;lt;code&amp;gt;Memory&amp;lt;/code&amp;gt;, so they are tmpfs, RAM-backed volumes.&amp;lt;ref name=&amp;quot;config&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/Config.scala |title=Config.scala (Kubernetes resource manager, v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-25262 |title=SPARK-25262: Support tmpfs for local dirs in k8s |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The documentation suggests it for nodes without local disks, where many executors writing to network-mounted storage can be slow.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With tmpfs, data in the local directories counts against the pod&amp;#039;s memory. The Spark documentation suggests raising &amp;lt;code&amp;gt;spark.{driver,executor}.memoryOverheadFactor&amp;lt;/code&amp;gt; to leave room for it.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How do spark-local-dir volumes work? ==&lt;br /&gt;
Any volume mounted through the Spark volume properties whose name starts with &amp;lt;code&amp;gt;spark-local-dir-&amp;lt;/code&amp;gt; is used as local storage for shuffle and spill instead of the default &amp;lt;code&amp;gt;emptyDir&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt; Volume properties have the form &amp;lt;code&amp;gt;spark.kubernetes.executor.volumes.[VolumeType].[VolumeName].mount.path&amp;lt;/code&amp;gt;, and the supported types are &amp;lt;code&amp;gt;hostPath&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;emptyDir&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;nfs&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;persistentVolumeClaim&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;code&amp;gt;hostPath&amp;lt;/code&amp;gt; volume puts local directories on a directory of the node itself; support for mapping &amp;lt;code&amp;gt;spark.local.dir&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;hostPath&amp;lt;/code&amp;gt; volumes arrived in Spark 3.0.0.&amp;lt;ref&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-28042 |title=SPARK-28042: Support mapping spark.local.dir to hostPath volume |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The Spark documentation warns that &amp;lt;code&amp;gt;hostPath&amp;lt;/code&amp;gt; volumes have known security weaknesses and advises cluster administrators to restrict them with the Pod Security Admission controller.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How do on-demand persistent volume claims work for shuffle? ==&lt;br /&gt;
Setting a volume&amp;#039;s &amp;lt;code&amp;gt;claimName&amp;lt;/code&amp;gt; option to &amp;lt;code&amp;gt;OnDemand&amp;lt;/code&amp;gt; makes Spark create one PVC per executor, with the size and storage class from the &amp;lt;code&amp;gt;sizeLimit&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;storageClass&amp;lt;/code&amp;gt; options.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt; Dynamic PVC creation and deletion for executors was added in Spark 3.1.0.&amp;lt;ref&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-32971 |title=SPARK-32971: Support dynamic PVC creation/deletion for K8s executors |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The Spark documentation recommends a PVC named &amp;lt;code&amp;gt;spark-local-dir-*&amp;lt;/code&amp;gt; for jobs with large shuffles and sorts.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
spark.kubernetes.executor.volumes.persistentVolumeClaim.spark-local-dir-1.options.claimName     OnDemand&lt;br /&gt;
spark.kubernetes.executor.volumes.persistentVolumeClaim.spark-local-dir-1.options.storageClass  gp&lt;br /&gt;
spark.kubernetes.executor.volumes.persistentVolumeClaim.spark-local-dir-1.options.sizeLimit     500Gi&lt;br /&gt;
spark.kubernetes.executor.volumes.persistentVolumeClaim.spark-local-dir-1.mount.path            /data&lt;br /&gt;
spark.kubernetes.executor.volumes.persistentVolumeClaim.spark-local-dir-1.mount.readOnly        false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since Spark 4.2.0, the &amp;lt;code&amp;gt;ExecutorPVCResizePlugin&amp;lt;/code&amp;gt; plugin can grow the storage request of an executor&amp;#039;s &amp;lt;code&amp;gt;spark-local-dir-*&amp;lt;/code&amp;gt; PVCs while the executor runs. It is controlled by &amp;lt;code&amp;gt;spark.kubernetes.executor.pvc.resizeInterval&amp;lt;/code&amp;gt; (default 5 minutes), &amp;lt;code&amp;gt;resizeThreshold&amp;lt;/code&amp;gt; (default 0.5) and &amp;lt;code&amp;gt;resizeFactor&amp;lt;/code&amp;gt; (default 1.0), and requires a storage class that allows volume expansion.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Which configuration keys control PVC reuse? ==&lt;br /&gt;
Three driver properties let on-demand PVCs outlive the executor that first used them.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Property !! Added in !! Default in 4.3.0 !! Effect&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.kubernetes.driver.ownPersistentVolumeClaim&amp;lt;/code&amp;gt; || 3.2.0 || true || The driver pod, not the executor pod, owns on-demand PVCs&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.kubernetes.driver.reusePersistentVolumeClaim&amp;lt;/code&amp;gt; || 3.2.0 || true || The driver gives PVCs of deleted executors to new executors; requires driver ownership&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.kubernetes.driver.waitToReusePersistentVolumeClaim&amp;lt;/code&amp;gt; || 3.4.0 || false || The driver holds back new executors while it already owns as many PVCs as the job may have; requires both settings above&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The first two properties defaulted to false when they were introduced. Since Spark 3.4, the driver owns PVCs and tries to reuse those not attached to live executors; setting both properties to false restores the earlier behaviour.&amp;lt;ref name=&amp;quot;migration&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/core-migration-guide.html |title=Migration Guide: Spark Core (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; A pod in &amp;lt;code&amp;gt;Terminating&amp;lt;/code&amp;gt; state has not yet released its PVCs, so the total number of PVCs can exceed the number of running executors.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What is KubernetesLocalDiskShuffleDataIO? ==&lt;br /&gt;
&amp;lt;code&amp;gt;org.apache.spark.shuffle.KubernetesLocalDiskShuffleDataIO&amp;lt;/code&amp;gt; is a built-in shuffle storage plugin that recovers shuffle data from reused PVCs, so a new executor that mounts a reused PVC tries to recover the shuffle data that dead executors left in its local directories.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;execcomp&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/shuffle/KubernetesLocalDiskShuffleExecutorComponents.scala |title=KubernetesLocalDiskShuffleExecutorComponents.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; It was added in Spark 3.2.0 under SPARK-35593 and requires &amp;lt;code&amp;gt;spark.kubernetes.driver.reusePersistentVolumeClaim=true&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;plugin&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/shuffle/KubernetesLocalDiskShuffleDataIO.scala |title=KubernetesLocalDiskShuffleDataIO.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-35593 |title=SPARK-35593: Support shuffle data recovery on the reused PVCs |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The documented setup mounts the PVC at a path such as &amp;lt;code&amp;gt;/data/spark-x/executor-x&amp;lt;/code&amp;gt; and sets &amp;lt;code&amp;gt;spark.shuffle.sort.io.plugin.class&amp;lt;/code&amp;gt; to the plugin class. The documentation also suggests enabling &amp;lt;code&amp;gt;spark.kubernetes.driver.waitToReusePersistentVolumeClaim&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does shuffle storage relate to dynamic allocation and decommissioning? ==&lt;br /&gt;
Dynamic allocation needs shuffle files to survive executor removal. On other cluster managers the external shuffle service can do this, but Spark on Kubernetes does not support it, so setting &amp;lt;code&amp;gt;spark.shuffle.service.enabled&amp;lt;/code&amp;gt; to true is not an option there.&amp;lt;ref name=&amp;quot;jobsched&amp;quot; /&amp;gt; The remaining options are shuffle tracking (&amp;lt;code&amp;gt;spark.dynamicAllocation.shuffleTracking.enabled&amp;lt;/code&amp;gt;), shuffle block migration through [[executor decommissioning]], or a shuffle plugin whose driver components support reliable storage.&amp;lt;ref name=&amp;quot;jobsched&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;configdoc&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;
Decommissioning and PVC reuse address different failures. Decommissioning copies shuffle blocks from an executor that is being shut down to other executors, or to &amp;lt;code&amp;gt;spark.storage.decommission.fallbackStorage.path&amp;lt;/code&amp;gt;, before the pod ends.&amp;lt;ref name=&amp;quot;configdoc&amp;quot; /&amp;gt; PVC reuse with &amp;lt;code&amp;gt;KubernetesLocalDiskShuffleDataIO&amp;lt;/code&amp;gt; recovers files after a pod is already gone, as long as its PVC survives.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Shuffle]]&lt;br /&gt;
* [[Executor]]&lt;br /&gt;
* [[Executor decommissioning]]&lt;br /&gt;
* [[Spark Kubernetes pod template]]&lt;br /&gt;
* [[Spark on Kubernetes]]&lt;br /&gt;
* [[Kubernetes Operator for Apache 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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:54 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Spark_Kubernetes_shuffle_storage</comments>
		</item>
		<item>
			<title>Spark listener</title>
			<link>https://openlakehouse.io/w/index.php?title=Spark_listener&amp;diff=190&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Spark_listener&amp;diff=190&amp;oldid=0</guid>
			<description>&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            = Spark listener&lt;br /&gt;
| also_known_as   = SparkListener, QueryExecutionListener, StreamingQueryListener&lt;br /&gt;
| field           = Monitoring and extension APIs&lt;br /&gt;
| key_parts       = Listener bus with asynchronous event queues, SparkListener callbacks, SQL and streaming listener interfaces, registration by configuration or code&lt;br /&gt;
| implementations = [[Apache Spark]]&lt;br /&gt;
| related         = [[Spark event log]], [[Spark UI]], [[Spark History Server]], [[Spark plugin]], [[MLflow]], [[OpenLineage]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (SparkListener.scala, LiveListenerBus.scala, AsyncEventQueue.scala, SparkContext.scala, QueryExecutionListener.scala, StreamingQueryListener.scala, python/pyspark/sql/streaming/listener.py, config/package.scala, StaticSQLConf.scala), the OpenLineage 1.55.0 Spark integration docs and MLflow v3.18.0 source}}&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;&amp;#039;Spark listener&amp;#039;&amp;#039;&amp;#039; is a class that [[Apache Spark]] calls back when something happens inside an application, such as a job starting, a task ending, an executor being added or a SQL query finishing.&amp;lt;ref name=&amp;quot;listener&amp;quot; /&amp;gt; The core interface is &amp;lt;code&amp;gt;org.apache.spark.scheduler.SparkListener&amp;lt;/code&amp;gt;; the SQL module adds &amp;lt;code&amp;gt;QueryExecutionListener&amp;lt;/code&amp;gt; for completed queries, and [[Structured Streaming]] adds &amp;lt;code&amp;gt;StreamingQueryListener&amp;lt;/code&amp;gt; for query progress. Listeners are how Spark builds its own [[Spark UI]] and [[Spark event log]], and how external tools such as [[OpenLineage]] and [[MLflow]] observe Spark applications.&lt;br /&gt;
&lt;br /&gt;
== How do Spark listeners work? ==&lt;br /&gt;
The driver posts every scheduler event to a &amp;#039;&amp;#039;&amp;#039;listener bus&amp;#039;&amp;#039;&amp;#039;, which delivers events to listeners on background threads, so that a slow listener does not block the scheduler. In Spark 4.3.0 the bus has separate queues: &amp;lt;code&amp;gt;shared&amp;lt;/code&amp;gt; for user listeners, &amp;lt;code&amp;gt;appStatus&amp;lt;/code&amp;gt; for the listener that feeds the Spark UI, &amp;lt;code&amp;gt;executorManagement&amp;lt;/code&amp;gt; for dynamic allocation, and &amp;lt;code&amp;gt;eventLog&amp;lt;/code&amp;gt; for the event log writer.&amp;lt;ref name=&amp;quot;bus&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/scheduler/LiveListenerBus.scala |title=LiveListenerBus.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each queue has a fixed capacity, &amp;lt;code&amp;gt;spark.scheduler.listenerbus.eventqueue.capacity&amp;lt;/code&amp;gt; (default 10000, since 2.3.0), which can be overridden for one queue with &amp;lt;code&amp;gt;spark.scheduler.listenerbus.eventqueue.&amp;amp;lt;queueName&amp;amp;gt;.capacity&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;coreconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/internal/config/package.scala |title=config/package.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; When a queue is full, Spark drops events and logs an error saying that a listener is probably too slow to keep up.&amp;lt;ref name=&amp;quot;queue&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/scheduler/AsyncEventQueue.scala |title=AsyncEventQueue.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Dropped events in the &amp;lt;code&amp;gt;appStatus&amp;lt;/code&amp;gt; queue show up as missing or stuck jobs and stages in the UI, so listener code should return quickly.&lt;br /&gt;
&lt;br /&gt;
== SparkListener ==&lt;br /&gt;
&amp;lt;code&amp;gt;SparkListener&amp;lt;/code&amp;gt; is an abstract class with an empty method for each event, so a subclass overrides only what it needs. The methods include &amp;lt;code&amp;gt;onApplicationStart&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;onApplicationEnd&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;onJobStart&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;onJobEnd&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;onStageSubmitted&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;onStageCompleted&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;onTaskStart&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;onTaskEnd&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;onExecutorAdded&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;onExecutorRemoved&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;onEnvironmentUpdate&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;onOtherEvent&amp;lt;/code&amp;gt;, which receives events from other modules such as SQL execution start and end.&amp;lt;ref name=&amp;quot;listener&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/scheduler/SparkListener.scala |title=SparkListener.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The event classes are marked &amp;lt;code&amp;gt;@DeveloperApi&amp;lt;/code&amp;gt;, and the underlying trait is documented as an internal interface that might change between releases; the source recommends extending &amp;lt;code&amp;gt;SparkListener&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;SparkFirehoseListener&amp;lt;/code&amp;gt; instead of implementing it directly.&amp;lt;ref name=&amp;quot;listener&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A listener is registered in one of two ways:&lt;br /&gt;
* In configuration, with &amp;lt;code&amp;gt;spark.extraListeners&amp;lt;/code&amp;gt; (since 1.3.0), a list of class names that Spark adds to the &amp;lt;code&amp;gt;SparkContext&amp;lt;/code&amp;gt; when it starts. This catches events from the very start of the application.&amp;lt;ref name=&amp;quot;coreconf&amp;quot; /&amp;gt;&lt;br /&gt;
* In code, with &amp;lt;code&amp;gt;SparkContext.addSparkListener&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;removeSparkListener&amp;lt;/code&amp;gt;.&amp;lt;ref&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;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;scala&amp;quot;&amp;gt;&lt;br /&gt;
import org.apache.spark.scheduler.{SparkListener, SparkListenerStageCompleted}&lt;br /&gt;
&lt;br /&gt;
class SlowStageListener extends SparkListener {&lt;br /&gt;
  override def onStageCompleted(e: SparkListenerStageCompleted): Unit = {&lt;br /&gt;
    val info = e.stageInfo&lt;br /&gt;
    for (start &amp;lt;- info.submissionTime; end &amp;lt;- info.completionTime if end - start &amp;gt; 60000) {&lt;br /&gt;
      println(s&amp;quot;Stage ${info.stageId} (${info.name}) took ${(end - start) / 1000}s&amp;quot;)&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
// spark-submit --conf spark.extraListeners=com.example.SlowStageListener ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== QueryExecutionListener ==&lt;br /&gt;
&amp;lt;code&amp;gt;org.apache.spark.sql.util.QueryExecutionListener&amp;lt;/code&amp;gt; is called once per completed DataFrame or SQL action, with &amp;lt;code&amp;gt;onSuccess(funcName, qe, durationNs)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;onFailure(funcName, qe, exception)&amp;lt;/code&amp;gt;. The &amp;lt;code&amp;gt;QueryExecution&amp;lt;/code&amp;gt; argument gives access to the logical and physical plans of the query.&amp;lt;ref name=&amp;quot;qel&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/util/QueryExecutionListener.scala |title=QueryExecutionListener.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The interface documentation notes that implementations must be thread-safe, because they can be called from several threads.&lt;br /&gt;
&lt;br /&gt;
A query execution listener is registered per session with &amp;lt;code&amp;gt;spark.listenerManager.register(...)&amp;lt;/code&amp;gt;, or for every new session with the static setting &amp;lt;code&amp;gt;spark.sql.queryExecutionListeners&amp;lt;/code&amp;gt; (since 2.3.0).&amp;lt;ref name=&amp;quot;qel&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;static&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/StaticSQLConf.scala |title=StaticSQLConf.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Internally, Spark delivers these callbacks from SQL execution end events on the listener bus.&amp;lt;ref name=&amp;quot;qel&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== StreamingQueryListener ==&lt;br /&gt;
&amp;lt;code&amp;gt;StreamingQueryListener&amp;lt;/code&amp;gt; (since 2.0.0) receives &amp;lt;code&amp;gt;onQueryStarted&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;onQueryProgress&amp;lt;/code&amp;gt; after each micro-batch, &amp;lt;code&amp;gt;onQueryIdle&amp;lt;/code&amp;gt; (since 3.5.0) and &amp;lt;code&amp;gt;onQueryTerminated&amp;lt;/code&amp;gt; for [[Structured Streaming]] queries.&amp;lt;ref name=&amp;quot;sql&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/streaming/StreamingQueryListener.scala |title=StreamingQueryListener.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; It is registered with &amp;lt;code&amp;gt;spark.streams.addListener(...)&amp;lt;/code&amp;gt; or the static setting &amp;lt;code&amp;gt;spark.sql.streaming.streamingQueryListeners&amp;lt;/code&amp;gt; (since 2.4.0).&amp;lt;ref name=&amp;quot;static&amp;quot; /&amp;gt; PySpark has its own &amp;lt;code&amp;gt;StreamingQueryListener&amp;lt;/code&amp;gt; class since 3.4.0, so a streaming listener can be written in Python:&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/sql/streaming/listener.py |title=listener.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.streaming import StreamingQueryListener&lt;br /&gt;
&lt;br /&gt;
class ProgressLogger(StreamingQueryListener):&lt;br /&gt;
    def onQueryStarted(self, event):&lt;br /&gt;
        print(f&amp;quot;started {event.id}&amp;quot;)&lt;br /&gt;
    def onQueryProgress(self, event):&lt;br /&gt;
        p = event.progress&lt;br /&gt;
        print(f&amp;quot;batch {p.batchId}: {p.numInputRows} rows&amp;quot;)&lt;br /&gt;
    def onQueryIdle(self, event):&lt;br /&gt;
        pass&lt;br /&gt;
    def onQueryTerminated(self, event):&lt;br /&gt;
        print(f&amp;quot;terminated {event.id}&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
spark.streams.addListener(ProgressLogger())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What is built on Spark listeners? ==&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;The [[Spark UI]] and [[Spark History Server]].&amp;#039;&amp;#039;&amp;#039; Spark&amp;#039;s status listener, on the &amp;lt;code&amp;gt;appStatus&amp;lt;/code&amp;gt; queue, builds the data behind the UI, and the History Server replays event logs through the same kind of listener.&amp;lt;ref name=&amp;quot;bus&amp;quot; /&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala |title=FsHistoryProvider.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;The [[Spark event log]]&amp;#039;&amp;#039;&amp;#039;, written by &amp;lt;code&amp;gt;EventLoggingListener&amp;lt;/code&amp;gt; on the &amp;lt;code&amp;gt;eventLog&amp;lt;/code&amp;gt; queue.&amp;lt;ref name=&amp;quot;bus&amp;quot; /&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/scheduler/EventLoggingListener.scala |title=EventLoggingListener.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;[[MLflow]] autologging for Spark.&amp;#039;&amp;#039;&amp;#039; MLflow&amp;#039;s &amp;lt;code&amp;gt;SparkDataSourceListener&amp;lt;/code&amp;gt; extends &amp;lt;code&amp;gt;SparkListener&amp;lt;/code&amp;gt; to detect data source reads, so that autologging can record which tables and paths a model was trained on.&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/mlflow/mlflow/blob/v3.18.0/mlflow/java/spark/src/main/scala/org/mlflow/spark/autologging/SparkDataSourceListener.scala |title=SparkDataSourceListener.scala (MLflow v3.18.0) |publisher=MLflow Project |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;[[OpenLineage]] lineage collection.&amp;#039;&amp;#039;&amp;#039; The OpenLineage Spark integration is a &amp;lt;code&amp;gt;SparkListener&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;io.openlineage.spark.agent.OpenLineageSparkListener&amp;lt;/code&amp;gt;, enabled with &amp;lt;code&amp;gt;spark.extraListeners&amp;lt;/code&amp;gt;; it reads the events that the SparkContext emits and extracts metadata about jobs and datasets from the RDD and DataFrame dependency graphs.&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/OpenLineage/OpenLineage/blob/1.55.0/website/docs/integrations/spark/spark.md |title=Apache Spark integration (OpenLineage 1.55.0) |publisher=OpenLineage |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Spark listener vs Spark plugin ==&lt;br /&gt;
A listener only observes events on the driver. A [[Spark plugin]] runs code inside the driver and every executor, can register metrics, and can send messages from executors to the driver. Monitoring tools that need executor-side data use a plugin; tools that only need scheduler events use a listener.&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/java/org/apache/spark/api/plugin/SparkPlugin.java |title=SparkPlugin.java (v4.3.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;
* [[Spark event log]]&lt;br /&gt;
* [[Spark UI]]&lt;br /&gt;
* [[Spark History Server]]&lt;br /&gt;
* [[Spark plugin]]&lt;br /&gt;
* [[Structured Streaming]]&lt;br /&gt;
* [[MLflow]]&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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:54 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Spark_listener</comments>
		</item>
		<item>
			<title>Spark error classes</title>
			<link>https://openlakehouse.io/w/index.php?title=Spark_error_classes&amp;diff=185&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Spark_error_classes&amp;diff=185&amp;oldid=0</guid>
			<description>&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            = Spark error classes&lt;br /&gt;
| also_known_as   = Error conditions, error states, SQLSTATE codes&lt;br /&gt;
| field           = SQL query engines&lt;br /&gt;
| key_parts       = Error condition name, sub-condition, SQLSTATE (class and sub-class), message template with parameters&lt;br /&gt;
| implementations = [[Apache Spark]]&lt;br /&gt;
| related         = [[Spark SQL ANSI mode]], [[Spark SQL scripting]], [[Spark Connect]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (common/utils/src/main/resources/error/, SparkThrowable.java, python/pyspark/errors/exceptions/base.py, docs/sql-error-conditions.md, SQLConf.scala), SPARK-46810 and the Spark 4.0.0 release notes}}&lt;br /&gt;
&lt;br /&gt;
In [[Apache Spark]], &amp;#039;&amp;#039;&amp;#039;error classes&amp;#039;&amp;#039;&amp;#039; (now documented as &amp;#039;&amp;#039;&amp;#039;error conditions&amp;#039;&amp;#039;&amp;#039;) are the structured identifiers that Spark attaches to user-facing errors: a stable name such as &amp;lt;code&amp;gt;DIVIDE_BY_ZERO&amp;lt;/code&amp;gt;, an optional sub-condition, a five-character SQLSTATE code and a message template with named parameters.&amp;lt;ref name=&amp;quot;readme&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/common/utils/src/main/resources/error/README.md |title=Guidelines for Throwing User-Facing Errors (common/utils/src/main/resources/error/README.md at v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; They let programs and people identify an error without parsing its message text, which can change between releases. The Spark documentation lists them on the &amp;quot;Error Conditions&amp;quot; page, ordered by SQLSTATE.&amp;lt;ref name=&amp;quot;docs&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-error-conditions.html |title=Error Conditions (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Error class or error condition? ==&lt;br /&gt;
Spark uses the terms of the SQL standard, in which an &amp;quot;error class&amp;quot; is only the first two characters of a SQLSTATE. Spark&amp;#039;s contributor guide defines a hierarchy of three levels: the error state (SQLSTATE), the error condition, and the error sub-condition. The SQLSTATE in turn has two parts, a class (for example &amp;lt;code&amp;gt;42&amp;lt;/code&amp;gt;) and a sub-class (for example &amp;lt;code&amp;gt;K01&amp;lt;/code&amp;gt;).&amp;lt;ref name=&amp;quot;readme&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spark historically called a name like &amp;lt;code&amp;gt;DATATYPE_MISSING_SIZE&amp;lt;/code&amp;gt; an &amp;quot;error class&amp;quot; as well, which clashed with the standard meaning. SPARK-46810, &amp;quot;Clarify error class terminology&amp;quot;, fixed in Spark 4.0.0, settled on &amp;quot;error condition&amp;quot; for these names in user-facing documentation.&amp;lt;ref name=&amp;quot;jira46810&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-46810 |title=SPARK-46810: Clarify error class terminology |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The guide notes that the code still calls the field &amp;lt;code&amp;gt;errorClass&amp;lt;/code&amp;gt; in many places, so the same string is an &amp;quot;error condition&amp;quot; in the docs and an &amp;quot;error class&amp;quot; in the code.&amp;lt;ref name=&amp;quot;readme&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The public APIs followed the rename. In Spark 4.3.0 the Java and Scala interface &amp;lt;code&amp;gt;SparkThrowable&amp;lt;/code&amp;gt; exposes &amp;lt;code&amp;gt;getCondition()&amp;lt;/code&amp;gt; and marks &amp;lt;code&amp;gt;getErrorClass()&amp;lt;/code&amp;gt; as deprecated.&amp;lt;ref name=&amp;quot;throwable&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/common/utils/src/main/java/org/apache/spark/SparkThrowable.java |title=SparkThrowable.java (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; In PySpark, SPARK-50915 added &amp;lt;code&amp;gt;PySparkException.getCondition()&amp;lt;/code&amp;gt; and deprecated &amp;lt;code&amp;gt;getErrorClass()&amp;lt;/code&amp;gt; as of 4.0.0.&amp;lt;ref name=&amp;quot;r400&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4-0-0.html |title=Spark Release 4.0.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;pybase&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/errors/exceptions/base.py |title=pyspark/errors/exceptions/base.py (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How are Spark errors structured? ==&lt;br /&gt;
Spark defines its errors in three JSON files in the source tree: &amp;lt;code&amp;gt;error-conditions.json&amp;lt;/code&amp;gt; (the conditions, their messages and SQLSTATEs), &amp;lt;code&amp;gt;error-states.json&amp;lt;/code&amp;gt; (the SQLSTATE values) and &amp;lt;code&amp;gt;error-classes.json&amp;lt;/code&amp;gt; (the two-character SQLSTATE classes).&amp;lt;ref name=&amp;quot;readme&amp;quot; /&amp;gt; An error condition is unique, stays the same across releases, and has a message template whose parameters are written in angle brackets, such as &amp;lt;code&amp;gt;&amp;amp;lt;relationName&amp;amp;gt;&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;readme&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some conditions have sub-conditions that add detail. For example &amp;lt;code&amp;gt;UNRESOLVED_COLUMN&amp;lt;/code&amp;gt; (SQLSTATE &amp;lt;code&amp;gt;42703&amp;lt;/code&amp;gt;) has the sub-conditions &amp;lt;code&amp;gt;WITH_SUGGESTION&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;WITHOUT_SUGGESTION&amp;lt;/code&amp;gt;, and the full name is written &amp;lt;code&amp;gt;UNRESOLVED_COLUMN.WITH_SUGGESTION&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;errjson&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/common/utils/src/main/resources/error/error-conditions.json |title=error-conditions.json (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Errors that have not yet been given a proper name use a legacy condition with the prefix &amp;lt;code&amp;gt;_LEGACY_ERROR_TEMP_&amp;lt;/code&amp;gt; and a number. The contributor guide asks that no new uncategorized errors be added and that existing ones be converted.&amp;lt;ref name=&amp;quot;readme&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What is a SQLSTATE in Spark? ==&lt;br /&gt;
A SQLSTATE is a five-character code that identifies an error category across SQL engines; the first two characters are the class and the last three the sub-class.&amp;lt;ref name=&amp;quot;readme&amp;quot; /&amp;gt; Spark&amp;#039;s &amp;lt;code&amp;gt;error-states.json&amp;lt;/code&amp;gt; records, for each state, its description, whether it comes from the SQL standard and which other systems use it. For example &amp;lt;code&amp;gt;22003&amp;lt;/code&amp;gt; (&amp;quot;numeric value out of range&amp;quot;) comes from SQL/Foundation, while &amp;lt;code&amp;gt;42P01&amp;lt;/code&amp;gt; (&amp;quot;undefined table&amp;quot;) originates in PostgreSQL.&amp;lt;ref name=&amp;quot;states&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/common/utils/src/main/resources/error/error-states.json |title=error-states.json (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Spark 4.0.0 made a SQLSTATE mandatory for error conditions (SPARK-45581) and exposed it in error messages (SPARK-45595).&amp;lt;ref name=&amp;quot;r400&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Error condition !! SQLSTATE !! Typical cause&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;DIVIDE_BY_ZERO&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;22012&amp;lt;/code&amp;gt; || Division by zero in [[Spark SQL ANSI mode|ANSI mode]]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ARITHMETIC_OVERFLOW&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;22003&amp;lt;/code&amp;gt; || Numeric overflow in ANSI mode&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;CAST_INVALID_INPUT&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;22018&amp;lt;/code&amp;gt; || A string that cannot be cast to the target type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;TABLE_OR_VIEW_NOT_FOUND&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;42P01&amp;lt;/code&amp;gt; || A table or view name that does not resolve&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;UNRESOLVED_COLUMN&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;42703&amp;lt;/code&amp;gt; || A column, variable or parameter name that does not resolve&lt;br /&gt;
|}&lt;br /&gt;
Source: &amp;lt;code&amp;gt;error-conditions.json&amp;lt;/code&amp;gt; at v4.3.0.&amp;lt;ref name=&amp;quot;errjson&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How to search Spark error conditions ==&lt;br /&gt;
The &amp;quot;Error Conditions&amp;quot; page of the Spark documentation is generated from &amp;lt;code&amp;gt;error-conditions.json&amp;lt;/code&amp;gt; and lists every condition with its SQLSTATE and message, sorted by SQLSTATE and then by name.&amp;lt;ref name=&amp;quot;docs&amp;quot; /&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/docs/_plugins/build-error-docs.py |title=docs/_plugins/build-error-docs.py (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Searching that page, or the JSON file at the matching release tag, for the condition name shown in brackets at the start of an error message (for example &amp;lt;code&amp;gt;[CAST_INVALID_INPUT]&amp;lt;/code&amp;gt;) gives the message template and SQLSTATE for that release.&lt;br /&gt;
&lt;br /&gt;
Programs can read the same fields from the exception. Every Spark exception that implements &amp;lt;code&amp;gt;SparkThrowable&amp;lt;/code&amp;gt; provides &amp;lt;code&amp;gt;getCondition()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;getSqlState()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;getMessageParameters()&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;throwable&amp;quot; /&amp;gt; PySpark exceptions provide methods of the same names.&amp;lt;ref name=&amp;quot;pybase&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from pyspark.errors import PySparkException&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
    spark.sql(&amp;quot;SELECT 1 / 0&amp;quot;).collect()   # ANSI mode is on by default in Spark 4&lt;br /&gt;
except PySparkException as e:&lt;br /&gt;
    print(e.getCondition())          # DIVIDE_BY_ZERO&lt;br /&gt;
    print(e.getSqlState())           # 22012&lt;br /&gt;
    print(e.getMessageParameters())  # e.g. {&amp;#039;config&amp;#039;: &amp;#039;&amp;quot;spark.sql.ansi.enabled&amp;quot;&amp;#039;}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Branching on &amp;lt;code&amp;gt;getCondition()&amp;lt;/code&amp;gt; or on the SQLSTATE class is more robust than matching message text. The contributor guide shows a check of the form &amp;lt;code&amp;gt;getSqlState.startsWith(&amp;quot;42&amp;quot;)&amp;lt;/code&amp;gt; to catch all syntax and analysis errors.&amp;lt;ref name=&amp;quot;readme&amp;quot; /&amp;gt; In [[Spark SQL scripting]], condition handlers can name an error condition such as &amp;lt;code&amp;gt;DIVIDE_BY_ZERO&amp;lt;/code&amp;gt; or a SQLSTATE directly.&amp;lt;ref name=&amp;quot;scripting&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-ref-scripting.html |title=SQL Scripting (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 are error messages formatted? ==&lt;br /&gt;
&amp;lt;code&amp;gt;spark.sql.error.messageFormat&amp;lt;/code&amp;gt; sets how the Thrift Server and the SQL command-line interface print errors. The default, &amp;lt;code&amp;gt;PRETTY&amp;lt;/code&amp;gt;, prints the error condition, message and query context and shows stack traces only for internal errors (SQLSTATE &amp;lt;code&amp;gt;XX***&amp;lt;/code&amp;gt;); &amp;lt;code&amp;gt;DEBUG&amp;lt;/code&amp;gt; always adds stack traces; &amp;lt;code&amp;gt;MINIMAL&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;STANDARD&amp;lt;/code&amp;gt; produce JSON, with &amp;lt;code&amp;gt;STANDARD&amp;lt;/code&amp;gt; adding a &amp;lt;code&amp;gt;message&amp;lt;/code&amp;gt; field.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala |title=SQLConf.scala (v4.3.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;
* [[Apache Spark]]&lt;br /&gt;
* [[Spark SQL ANSI mode]]&lt;br /&gt;
* [[Spark SQL scripting]]&lt;br /&gt;
* [[Spark Connect]]&lt;br /&gt;
* [[Spark 3 to Spark 4 migration]]&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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:53 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Spark_error_classes</comments>
		</item>
		<item>
			<title>Spark event log</title>
			<link>https://openlakehouse.io/w/index.php?title=Spark_event_log&amp;diff=186&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Spark_event_log&amp;diff=186&amp;oldid=0</guid>
			<description>&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            = Spark event log&lt;br /&gt;
| also_known_as   = Event log, eventLog&lt;br /&gt;
| field           = Monitoring and debugging&lt;br /&gt;
| key_parts       = EventLoggingListener, JSON lines (one listener event per line), compression codec, rolling files, compaction&lt;br /&gt;
| implementations = [[Apache Spark]]&lt;br /&gt;
| related         = [[Spark History Server]], [[Spark UI]], [[Spark listener]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (EventLoggingListener.scala, EventLogFileWriters.scala, config/package.scala, config/History.scala, docs/configuration.md, docs/monitoring.md, docs/core-migration-guide.md) and Spark JIRA SPARK-28594 and SPARK-45771}}&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;Spark event log&amp;#039;&amp;#039;&amp;#039; is a file, or a directory of files, in which an [[Apache Spark]] application records the listener events that its driver posts for jobs, stages, tasks, executors and SQL query executions, so that the application&amp;#039;s [[Spark UI]] can be rebuilt after it ends. Not every event is written: some are recorded only when a setting turns them on, events can opt out of logging, and &amp;lt;code&amp;gt;spark.eventLog.excludedPatterns&amp;lt;/code&amp;gt; suppresses named events.&amp;lt;ref name=&amp;quot;ell&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/scheduler/EventLoggingListener.scala |title=EventLoggingListener.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The [[Spark History Server]] reads event logs to show finished applications. Event logging is off by default and is turned on with &amp;lt;code&amp;gt;spark.eventLog.enabled&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;coreconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/internal/config/package.scala |title=config/package.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What does the event log record? ==&lt;br /&gt;
The event log is written by &amp;lt;code&amp;gt;EventLoggingListener&amp;lt;/code&amp;gt;, a [[Spark listener]] that the driver registers when event logging is on. Each event that it logs is serialized to JSON and written as one line; the first line records the Spark version.&amp;lt;ref name=&amp;quot;ell&amp;quot; /&amp;gt; The events include application start and end, job start and end, stage submission and completion, task start and end with task metrics, executors added and removed, environment updates, and SQL execution start and end with the query plans. These are the kinds of events that also build the live Spark UI.&lt;br /&gt;
&lt;br /&gt;
Some events are left out by default. &amp;lt;code&amp;gt;EventLoggingListener&amp;lt;/code&amp;gt; writes block updates and stage executor metrics only when their settings are on, writes events from other modules only if the event&amp;#039;s &amp;lt;code&amp;gt;logEvent&amp;lt;/code&amp;gt; flag is true, and the log writer drops any line that starts with a pattern listed in &amp;lt;code&amp;gt;spark.eventLog.excludedPatterns&amp;lt;/code&amp;gt;:&amp;lt;ref name=&amp;quot;ell&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;writers&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;coreconf&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;confdoc&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;
* &amp;lt;code&amp;gt;spark.eventLog.logBlockUpdates.enabled&amp;lt;/code&amp;gt; (default false) logs every block update. The documentation warns that this increases the size of the event log considerably.&lt;br /&gt;
* &amp;lt;code&amp;gt;spark.eventLog.logStageExecutorMetrics&amp;lt;/code&amp;gt; (default false) writes per-stage peaks of executor metrics.&lt;br /&gt;
&lt;br /&gt;
== Where is the event log written? ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;properties&amp;quot;&amp;gt;&lt;br /&gt;
spark.eventLog.enabled  true&lt;br /&gt;
spark.eventLog.dir      hdfs://namenode/shared/spark-logs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;spark.eventLog.dir&amp;lt;/code&amp;gt; defaults to &amp;lt;code&amp;gt;/tmp/spark-events&amp;lt;/code&amp;gt;, a path on the driver&amp;#039;s local file system, so on a cluster it is set to a shared location such as HDFS or object storage that the [[Spark History Server]] also reads.&amp;lt;ref name=&amp;quot;coreconf&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;ell&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;monitoring&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/monitoring.html |title=Monitoring and Instrumentation (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A single-file event log is named after the application ID and carries an &amp;lt;code&amp;gt;.inprogress&amp;lt;/code&amp;gt; suffix until the application ends. A rolling event log is a directory named &amp;lt;code&amp;gt;eventlog_v2_&amp;amp;lt;appId&amp;amp;gt;&amp;lt;/code&amp;gt; that holds numbered &amp;lt;code&amp;gt;events_&amp;amp;lt;index&amp;amp;gt;_&amp;amp;lt;appId&amp;amp;gt;&amp;lt;/code&amp;gt; files and an &amp;lt;code&amp;gt;appstatus_&amp;amp;lt;appId&amp;amp;gt;&amp;lt;/code&amp;gt; file, which also has the &amp;lt;code&amp;gt;.inprogress&amp;lt;/code&amp;gt; suffix while the application runs.&amp;lt;ref name=&amp;quot;writers&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/deploy/history/EventLogFileWriters.scala |title=EventLogFileWriters.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What changed in Spark 4.0? ==&lt;br /&gt;
Two event log defaults changed in Spark 4.0. The Spark migration guide says that since 4.0, Spark rolls event logs to archive them incrementally, and that it compresses event logs; setting &amp;lt;code&amp;gt;spark.eventLog.rolling.enabled&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;spark.eventLog.compress&amp;lt;/code&amp;gt; to false restores the earlier behaviour.&amp;lt;ref name=&amp;quot;migration&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/core-migration-guide.html |title=Migration Guide: Spark Core (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The rolling default came from SPARK-45771.&amp;lt;ref&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-45771 |title=SPARK-45771: Enable spark.eventLog.rolling.enabled by default |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Since Spark 3.2, the event log codec defaults to &amp;lt;code&amp;gt;zstd&amp;lt;/code&amp;gt; and no longer falls back to &amp;lt;code&amp;gt;spark.io.compression.codec&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;migration&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Setting !! Default in 4.3.0 !! Since&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.eventLog.enabled&amp;lt;/code&amp;gt; || false || 1.0.0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.eventLog.dir&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;/tmp/spark-events&amp;lt;/code&amp;gt; || 1.0.0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.eventLog.compress&amp;lt;/code&amp;gt; || true || 1.0.0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.eventLog.compression.codec&amp;lt;/code&amp;gt; || zstd || 3.0.0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.eventLog.rolling.enabled&amp;lt;/code&amp;gt; || true || 3.0.0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.eventLog.rolling.maxFileSize&amp;lt;/code&amp;gt; || 128m || 3.0.0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.eventLog.excludedPatterns&amp;lt;/code&amp;gt; || (none) || 4.1.0&lt;br /&gt;
|}&lt;br /&gt;
All values are from the Spark 4.3.0 source.&amp;lt;ref name=&amp;quot;coreconf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Why do event logs get so large? ==&lt;br /&gt;
An event log grows with the number of tasks, because every task end event carries the task&amp;#039;s metrics. Applications with many small tasks, long-running [[Structured Streaming]] queries that run a job for every micro-batch, and queries with very large plans produce the largest logs. A large single-file log is slow for the History Server to replay, because the whole file must be read to build the UI.&amp;lt;ref name=&amp;quot;monitoring&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ways to keep event logs manageable:&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Rolling.&amp;#039;&amp;#039;&amp;#039; With &amp;lt;code&amp;gt;spark.eventLog.rolling.enabled&amp;lt;/code&amp;gt; (on by default since 4.0), Spark starts a new file when the current one reaches &amp;lt;code&amp;gt;spark.eventLog.rolling.maxFileSize&amp;lt;/code&amp;gt; (default 128m). Rolling was added for running streaming applications in Spark 3.0.0 (SPARK-28594).&amp;lt;ref name=&amp;quot;coreconf&amp;quot; /&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-28594 |title=SPARK-28594: Allow event logs for running streaming apps to be rolled over |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Compaction.&amp;#039;&amp;#039;&amp;#039; Rolling alone does not reduce the total size. Setting &amp;lt;code&amp;gt;spark.history.fs.eventLog.rolling.maxFilesToRetain&amp;lt;/code&amp;gt; on the History Server compacts older rolled files and drops events for finished jobs, terminated executors and finished SQL executions. The documentation describes compaction as lossy.&amp;lt;ref name=&amp;quot;monitoring&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;history&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/internal/config/History.scala |title=config/History.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Excluding events.&amp;#039;&amp;#039;&amp;#039; &amp;lt;code&amp;gt;spark.eventLog.excludedPatterns&amp;lt;/code&amp;gt; (since 4.1.0) takes a comma-separated list of event names that are not written.&amp;lt;ref name=&amp;quot;confdoc&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Leaving verbose events off&amp;#039;&amp;#039;&amp;#039;, such as block updates.&amp;lt;ref name=&amp;quot;confdoc&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Retention.&amp;#039;&amp;#039;&amp;#039; The History Server cleaner (&amp;lt;code&amp;gt;spark.history.fs.cleaner.enabled&amp;lt;/code&amp;gt;, default false) deletes old logs.&amp;lt;ref name=&amp;quot;history&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reading an event log without the History Server ==&lt;br /&gt;
Because each line is a JSON object whose &amp;lt;code&amp;gt;Event&amp;lt;/code&amp;gt; field names the event class (for example &amp;lt;code&amp;gt;SparkListenerStageCompleted&amp;lt;/code&amp;gt;),&amp;lt;ref name=&amp;quot;jsonprotocol&amp;quot; /&amp;gt; a compressed log can be decompressed and read with ordinary JSON tools. Spark itself can read one as a JSON data source, which is a quick way to find the slowest stages of a finished run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
events = spark.read.json(&amp;quot;/tmp/spark-events/app-20261123120000-0000&amp;quot;)&lt;br /&gt;
(events.filter(&amp;quot;Event = &amp;#039;SparkListenerStageCompleted&amp;#039;&amp;quot;)&lt;br /&gt;
       .selectExpr(&amp;quot;`Stage Info`.`Stage ID` AS stage&amp;quot;,&lt;br /&gt;
                   &amp;quot;`Stage Info`.`Completion Time` - `Stage Info`.`Submission Time` AS ms&amp;quot;)&lt;br /&gt;
       .orderBy(&amp;quot;ms&amp;quot;, ascending=False)&lt;br /&gt;
       .show(5))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JSON format comes from Spark&amp;#039;s &amp;lt;code&amp;gt;JsonProtocol&amp;lt;/code&amp;gt;, an internal class whose source states that any version of Spark should be able to read event logs written by any other version, and that JSON fields are never deleted, only added as optional fields.&amp;lt;ref name=&amp;quot;jsonprotocol&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/util/JsonProtocol.scala |title=JsonProtocol.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; For tools, the REST API of the History Server or the live UI, at &amp;lt;code&amp;gt;/api/v1&amp;lt;/code&amp;gt;, is the documented interface to the same data and has its own versioning policy.&amp;lt;ref name=&amp;quot;monitoring&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Spark History Server]]&lt;br /&gt;
* [[Spark UI]]&lt;br /&gt;
* [[Spark listener]]&lt;br /&gt;
* [[Structured Streaming]]&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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:53 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Spark_event_log</comments>
		</item>
		<item>
			<title>Spark History Server</title>
			<link>https://openlakehouse.io/w/index.php?title=Spark_History_Server&amp;diff=187&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Spark_History_Server&amp;diff=187&amp;oldid=0</guid>
			<description>&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            = Spark History Server&lt;br /&gt;
| also_known_as   = History server, port 18080&lt;br /&gt;
| field           = Monitoring and debugging&lt;br /&gt;
| key_parts       = Event log directory, FsHistoryProvider, local KV store, cleaner, REST API at /api/v1&lt;br /&gt;
| implementations = [[Apache Spark]]&lt;br /&gt;
| related         = [[Spark UI]], [[Spark event log]], [[Spark listener]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (docs/monitoring.md, config/History.scala, config/package.scala, EventLoggingListener.scala, docs/core-migration-guide.md)}}&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;Spark History Server&amp;#039;&amp;#039;&amp;#039; is a long-running [[Apache Spark]] service that reads the [[Spark event log|event logs]] of applications and rebuilds their [[Spark UI]], so that jobs, stages, SQL queries and executors can be inspected after an application has finished. It is started with &amp;lt;code&amp;gt;./sbin/start-history-server.sh&amp;lt;/code&amp;gt; and serves a web interface at &amp;lt;code&amp;gt;http://&amp;amp;lt;server-url&amp;amp;gt;:18080&amp;lt;/code&amp;gt; by default, listing completed and incomplete applications.&amp;lt;ref name=&amp;quot;monitoring&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/monitoring.html |title=Monitoring and Instrumentation (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The live Spark UI on port 4040 disappears when the driver exits; the History Server is how finished applications are debugged.&lt;br /&gt;
&lt;br /&gt;
== How does the Spark History Server work? ==&lt;br /&gt;
The History Server and the applications share a directory. Each application writes its event log there, and the server reads it:&amp;lt;ref name=&amp;quot;monitoring&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;properties&amp;quot;&amp;gt;&lt;br /&gt;
# On the applications&lt;br /&gt;
spark.eventLog.enabled   true&lt;br /&gt;
spark.eventLog.dir       hdfs://namenode/shared/spark-logs&lt;br /&gt;
&lt;br /&gt;
# On the History Server&lt;br /&gt;
spark.history.fs.logDirectory  hdfs://namenode/shared/spark-logs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Event logging is off by default (&amp;lt;code&amp;gt;spark.eventLog.enabled&amp;lt;/code&amp;gt;, default false), and both &amp;lt;code&amp;gt;spark.eventLog.dir&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spark.history.fs.logDirectory&amp;lt;/code&amp;gt; default to &amp;lt;code&amp;gt;/tmp/spark-events&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;coreconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/internal/config/package.scala |title=config/package.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;history&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/internal/config/History.scala |title=config/History.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;ell&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/scheduler/EventLoggingListener.scala |title=EventLoggingListener.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; &amp;lt;code&amp;gt;spark.history.fs.logDirectory&amp;lt;/code&amp;gt; accepts a comma-separated list of directories, so one server can watch several locations.&amp;lt;ref name=&amp;quot;history&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The default provider, &amp;lt;code&amp;gt;org.apache.spark.deploy.history.FsHistoryProvider&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;spark.history.provider&amp;lt;/code&amp;gt;), scans the directory every &amp;lt;code&amp;gt;spark.history.fs.update.interval&amp;lt;/code&amp;gt; (default 10s) for new or changed logs.&amp;lt;ref name=&amp;quot;history&amp;quot; /&amp;gt; When a user opens an application, the server replays its event log through the same status listeners that build the live UI, and caches the result. &amp;lt;code&amp;gt;spark.history.retainedApplications&amp;lt;/code&amp;gt; (default 50) sets how many applications&amp;#039; UI data stay in the cache; others are loaded from disk again when opened.&amp;lt;ref name=&amp;quot;history&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reading finished applications ==&lt;br /&gt;
The History Server shows the same tabs as the live [[Spark UI]]: Jobs, Stages, Storage, Environment, Executors and SQL. The same data is available from the REST API, at &amp;lt;code&amp;gt;http://&amp;amp;lt;server-url&amp;amp;gt;:18080/api/v1&amp;lt;/code&amp;gt;, which is useful for scripts that compare runs.&amp;lt;ref name=&amp;quot;monitoring&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Spark documentation lists several behaviours that surprise new users:&amp;lt;ref name=&amp;quot;monitoring&amp;quot; /&amp;gt;&lt;br /&gt;
* An application with several attempts shows its failed attempts, as well as the ongoing or final successful attempt.&lt;br /&gt;
* Incomplete (running) applications are refreshed only at each update interval. The documentation recommends viewing a running application in its own live UI.&lt;br /&gt;
* An application that exits without registering as complete, for example after a crash, stays listed as incomplete. Stopping the session explicitly (&amp;lt;code&amp;gt;spark.stop()&amp;lt;/code&amp;gt;) marks it complete.&lt;br /&gt;
&lt;br /&gt;
== Retention: how long are event logs kept? ==&lt;br /&gt;
The History Server does not delete event logs unless its cleaner is turned on. The cleaner settings at Spark 4.3.0 are:&amp;lt;ref name=&amp;quot;history&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;monitoring&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Setting !! Default !! Meaning&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.history.fs.cleaner.enabled&amp;lt;/code&amp;gt; || false || Turns on periodic deletion of event logs.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.history.fs.cleaner.interval&amp;lt;/code&amp;gt; || 1d || How often the cleaner runs.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.history.fs.cleaner.maxAge&amp;lt;/code&amp;gt; || 7d || Logs older than this are deleted.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.history.fs.cleaner.maxNum&amp;lt;/code&amp;gt; || Int.MaxValue || If there are more logs than this, the oldest completed attempts are deleted.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
A log is deleted if either condition holds. When several log directories are configured, one cleaner cycle covers all of them.&amp;lt;ref name=&amp;quot;monitoring&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For long-running applications, the History Server can also compact rolled event logs. Setting &amp;lt;code&amp;gt;spark.history.fs.eventLog.rolling.maxFilesToRetain&amp;lt;/code&amp;gt; (default: all files kept) makes the server rewrite older rolled files into one compact file, dropping events for finished jobs, terminated executors and finished SQL executions. The documentation calls compaction lossy, notes that it may not run if little space would be saved, and asks users to use it with caution.&amp;lt;ref name=&amp;quot;monitoring&amp;quot; /&amp;gt; See [[Spark event log]] for rolling.&lt;br /&gt;
&lt;br /&gt;
== Running a History Server at scale ==&lt;br /&gt;
Replaying a large event log takes time and memory. Several settings help:&amp;lt;ref name=&amp;quot;history&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;monitoring&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;spark.history.store.path&amp;lt;/code&amp;gt; (no default) stores application data on local disk instead of in memory, and reuses it after a restart. &amp;lt;code&amp;gt;spark.history.store.maxDiskUsage&amp;lt;/code&amp;gt; (default 10g) caps that disk.&lt;br /&gt;
* &amp;lt;code&amp;gt;spark.history.store.hybridStore.enabled&amp;lt;/code&amp;gt; (default false, since 3.1.0) first parses logs into memory and then moves the result to disk, limited by &amp;lt;code&amp;gt;spark.history.store.hybridStore.maxMemoryUsage&amp;lt;/code&amp;gt; (default 2g).&lt;br /&gt;
* &amp;lt;code&amp;gt;spark.history.fs.numReplayThreads&amp;lt;/code&amp;gt; sets how many threads replay logs; its default is a quarter of the available cores.&lt;br /&gt;
* &amp;lt;code&amp;gt;SPARK_DAEMON_MEMORY&amp;lt;/code&amp;gt; sets the server&amp;#039;s memory (default 1g).&lt;br /&gt;
&lt;br /&gt;
Access control uses &amp;lt;code&amp;gt;spark.history.ui.acls.enable&amp;lt;/code&amp;gt; and the admin ACL settings, and Kerberos is supported with &amp;lt;code&amp;gt;spark.history.kerberos.enabled&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;history&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Spark UI]]&lt;br /&gt;
* [[Spark event log]]&lt;br /&gt;
* [[Spark listener]]&lt;br /&gt;
* [[Apache 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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:53 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Spark_History_Server</comments>
		</item>
		<item>
			<title>Spark Connect plugin</title>
			<link>https://openlakehouse.io/w/index.php?title=Spark_Connect_plugin&amp;diff=182&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Spark_Connect_plugin&amp;diff=182&amp;oldid=0</guid>
			<description>&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            = Spark Connect plugin&lt;br /&gt;
| also_known_as   = Spark Connect extension, Spark Server Library&lt;br /&gt;
| field           = Distributed data processing, client-server protocols&lt;br /&gt;
| introduced      = Apache Spark 3.4.0&lt;br /&gt;
| key_parts       = &amp;lt;code&amp;gt;google.protobuf.Any&amp;lt;/code&amp;gt; extension fields, &amp;lt;code&amp;gt;RelationPlugin&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ExpressionPlugin&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;CommandPlugin&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spark.connect.extensions.*.classes&amp;lt;/code&amp;gt;, client wrapper&lt;br /&gt;
| implementations = [[Apache Spark]]; used by [[Delta Lake]] (Delta Connect)&lt;br /&gt;
| related         = [[Spark Connect]], [[Spark Connect server]], [[Spark Connect client]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (sql/connect/server plugin interfaces, SparkConnectPluginRegistry.scala, SparkConnectPlanner.scala, config/Connect.scala, ConnectProtoUtils.scala, the Spark Connect protobuf files, SparkConnectPluginRegistrySuite.scala), the Spark 4.3.0 Application Development with Spark Connect and configuration pages, SPARK-47062, SPARK-51343, and the Delta Lake Delta Connect documentation}}&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;&amp;#039;Spark Connect plugin&amp;#039;&amp;#039;&amp;#039; is a server-side class that extends [[Spark Connect]] in [[Apache Spark]] with new relations, expressions or commands: the client packs a custom Protocol Buffers message into an extension field of the Spark Connect protocol, and the plugin on the server turns that message into a Spark logical plan, a Catalyst expression, or an action.&amp;lt;ref name=&amp;quot;appdev&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/app-dev-spark-connect.html |title=Application Development with Spark Connect (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Plugins let a library such as [[Delta Lake]] expose features that classic PySpark reached through the driver JVM to clients that only speak the Spark Connect protocol. The Spark documentation calls a plugin together with its protocol messages and client package a &amp;#039;&amp;#039;Spark Server Library&amp;#039;&amp;#039; and says these extension points were offered with Spark 3.4.&amp;lt;ref name=&amp;quot;appdev&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does a Spark Connect plugin work? ==&lt;br /&gt;
The Spark Connect protocol reserves a field of type &amp;lt;code&amp;gt;google.protobuf.Any&amp;lt;/code&amp;gt; in its three main message types: &amp;lt;code&amp;gt;Relation.extension&amp;lt;/code&amp;gt; (field 998), &amp;lt;code&amp;gt;Expression.extension&amp;lt;/code&amp;gt; (field 999) and &amp;lt;code&amp;gt;Command.extension&amp;lt;/code&amp;gt; (field 999).&amp;lt;ref name=&amp;quot;relproto&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/connect/common/src/main/protobuf/spark/connect/relations.proto |title=relations.proto (tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;exprproto&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/connect/common/src/main/protobuf/spark/connect/expressions.proto |title=expressions.proto (tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;cmdproto&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/connect/common/src/main/protobuf/spark/connect/commands.proto |title=commands.proto (tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; An &amp;lt;code&amp;gt;Any&amp;lt;/code&amp;gt; holds any serialized protobuf message together with its type URL, so an extension author defines its own message and the core protocol does not change.&amp;lt;ref name=&amp;quot;appdev&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A Spark Server Library has four parts, according to the Spark documentation: the protocol extension (the custom protobuf messages), the Spark Connect plugin, the application logic it calls, and a client package that builds the messages for PySpark or Scala users.&amp;lt;ref name=&amp;quot;appdev&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the Spark Connect planner meets an extension field, it passes the serialized &amp;lt;code&amp;gt;Any&amp;lt;/code&amp;gt; to every registered plugin of the matching kind, in order, and uses the first one that handles it. A plugin signals &amp;quot;not mine&amp;quot; by returning an empty &amp;lt;code&amp;gt;Optional&amp;lt;/code&amp;gt; (relations and expressions) or &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt; (commands). If no plugin handles the message, the request fails with an error that names the type URL.&amp;lt;ref name=&amp;quot;planner&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/connect/server/src/main/scala/org/apache/spark/sql/connect/planner/SparkConnectPlanner.scala |title=SparkConnectPlanner.scala (tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Which plugin interfaces does Spark provide? ==&lt;br /&gt;
In Spark 4.3.0 the plugin interfaces are Java interfaces in the package &amp;lt;code&amp;gt;org.apache.spark.sql.connect.plugin&amp;lt;/code&amp;gt;, each registered with a static configuration key:&amp;lt;ref name=&amp;quot;iface&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/tree/v4.3.0/sql/connect/server/src/main/java/org/apache/spark/sql/connect/plugin |title=sql/connect/server/src/main/java/org/apache/spark/sql/connect/plugin (tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;connectconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/connect/server/src/main/scala/org/apache/spark/sql/connect/config/Connect.scala |title=Connect.scala (tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&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;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Interface !! Method !! Returns !! Configuration key !! Since&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;RelationPlugin&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;transform(byte[] relation, SparkConnectPlanner planner)&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;Optional&amp;amp;lt;LogicalPlan&amp;amp;gt;&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;spark.connect.extensions.relation.classes&amp;lt;/code&amp;gt; || 3.4.0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ExpressionPlugin&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;transform(byte[] relation, SparkConnectPlanner planner)&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;Optional&amp;amp;lt;Expression&amp;amp;gt;&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;spark.connect.extensions.expression.classes&amp;lt;/code&amp;gt; || 3.4.0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;CommandPlugin&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;process(byte[] command, SparkConnectPlanner planner)&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;boolean&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;spark.connect.extensions.command.classes&amp;lt;/code&amp;gt; || 3.4.0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;GetStatusPlugin&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;processRequestExtensions&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;processOperationExtensions&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;Optional&amp;amp;lt;List&amp;amp;lt;Any&amp;amp;gt;&amp;amp;gt;&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;spark.connect.extensions.getStatus.classes&amp;lt;/code&amp;gt; || 4.1.0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;MLBackendPlugin&amp;lt;/code&amp;gt; (experimental) || &amp;lt;code&amp;gt;transform(String mlName)&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;Optional&amp;amp;lt;String&amp;amp;gt;&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;spark.connect.ml.backend.classes&amp;lt;/code&amp;gt; || 4.0.0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Each key takes a comma-separated list of class names. Plugin classes must be trivially constructable and should not rely on internal state; the registry creates them by reflection the first time a plugin is needed.&amp;lt;ref name=&amp;quot;iface&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;registry&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/connect/server/src/main/scala/org/apache/spark/sql/connect/plugin/SparkConnectPluginRegistry.scala |title=SparkConnectPluginRegistry.scala (tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The JAR with the plugin goes on the server&amp;#039;s classpath, for example with &amp;lt;code&amp;gt;spark.jars&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;appdev&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Why do plugins receive bytes instead of protobuf objects? ==&lt;br /&gt;
Spark shades its copy of the protobuf library inside the Spark Connect server, so a plugin compiled against &amp;lt;code&amp;gt;com.google.protobuf&amp;lt;/code&amp;gt; cannot share protobuf classes with the server. A 2025 bug report, SPARK-51343, describes the resulting mismatch for the older Scala &amp;lt;code&amp;gt;RelationPlugin&amp;lt;/code&amp;gt; trait, whose bytecode referred to &amp;lt;code&amp;gt;org.sparkproject.connect.protobuf.Any&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;jira51343&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-51343 |title=SPARK-51343: RelationPlugin scala signature does not match bytecode |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; SPARK-47062, &amp;quot;Make Spark Connect Plugins Java Compatible&amp;quot;, was fixed in Spark 4.0.0.&amp;lt;ref name=&amp;quot;jira47062&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-47062 |title=SPARK-47062: Make Spark Connect Plugins Java Compatible |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; In the 4.3.0 source, the planner calls each plugin with &amp;lt;code&amp;gt;extension.toByteArray&amp;lt;/code&amp;gt;, the bytes of the whole &amp;lt;code&amp;gt;Any&amp;lt;/code&amp;gt; message.&amp;lt;ref name=&amp;quot;planner&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A plugin therefore parses the bytes with its own protobuf library. To turn nested Spark Connect messages (for example a child expression or input relation inside the custom message) back into Spark&amp;#039;s own classes, Spark provides &amp;lt;code&amp;gt;org.apache.spark.sql.connect.ConnectProtoUtils&amp;lt;/code&amp;gt;, whose documentation states that it exists for plugins because of the shading of &amp;lt;code&amp;gt;com.google.protobuf&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;protoutils&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/connect/common/src/main/scala/org/apache/spark/sql/connect/ConnectProtoUtils.scala |title=ConnectProtoUtils.scala (tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The code samples on the Application Development page still show the older signature that takes a &amp;lt;code&amp;gt;protobuf.Any&amp;lt;/code&amp;gt; and returns a Scala &amp;lt;code&amp;gt;Option&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;appdev&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
The following expression plugin follows the pattern of the plugin tests in Spark 4.3.0.&amp;lt;ref name=&amp;quot;suite&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/connect/server/src/test/scala/org/apache/spark/sql/connect/plugin/SparkConnectPluginRegistrySuite.scala |title=SparkConnectPluginRegistrySuite.scala (tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; A custom message &amp;lt;code&amp;gt;MyUpper&amp;lt;/code&amp;gt; (fields &amp;lt;code&amp;gt;spark.connect.Expression child = 1;&amp;lt;/code&amp;gt;) is generated in the package &amp;lt;code&amp;gt;com.example.proto&amp;lt;/code&amp;gt;, and the plugin turns it into Spark&amp;#039;s &amp;lt;code&amp;gt;Upper&amp;lt;/code&amp;gt; expression:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;scala&amp;quot;&amp;gt;&lt;br /&gt;
package com.example&lt;br /&gt;
&lt;br /&gt;
import java.util.Optional&lt;br /&gt;
&lt;br /&gt;
import com.google.protobuf&lt;br /&gt;
import org.apache.spark.sql.catalyst.expressions.{Expression, Upper}&lt;br /&gt;
import org.apache.spark.sql.connect.ConnectProtoUtils&lt;br /&gt;
import org.apache.spark.sql.connect.planner.SparkConnectPlanner&lt;br /&gt;
import org.apache.spark.sql.connect.plugin.ExpressionPlugin&lt;br /&gt;
&lt;br /&gt;
class MyUpperPlugin extends ExpressionPlugin {&lt;br /&gt;
  override def transform(&lt;br /&gt;
      relation: Array[Byte],&lt;br /&gt;
      planner: SparkConnectPlanner): Optional[Expression] = {&lt;br /&gt;
    val any = protobuf.Any.parseFrom(relation)&lt;br /&gt;
    if (!any.is(classOf[com.example.proto.MyUpper])) {&lt;br /&gt;
      return Optional.empty()&lt;br /&gt;
    }&lt;br /&gt;
    val msg = any.unpack(classOf[com.example.proto.MyUpper])&lt;br /&gt;
    // Re-parse the nested Spark Connect message into Spark&amp;#039;s own (shaded) classes.&lt;br /&gt;
    val child = ConnectProtoUtils.parseExpressionWithRecursionLimit(&lt;br /&gt;
      msg.getChild.toByteArray, recursionLimit = 1024)&lt;br /&gt;
    Optional.of(Upper(planner.transformExpression(child)))&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The server is then started with the JAR and the class name, for example &amp;lt;code&amp;gt;--jars my-upper.jar --conf spark.connect.extensions.expression.classes=com.example.MyUpperPlugin&amp;lt;/code&amp;gt;. On the client side, the Spark documentation shows a PySpark wrapper that subclasses the Spark Connect &amp;lt;code&amp;gt;Expression&amp;lt;/code&amp;gt; class, packs the custom message into &amp;lt;code&amp;gt;proto.Expression().extension&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;to_plan()&amp;lt;/code&amp;gt;, and wraps it in a &amp;lt;code&amp;gt;Column&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;appdev&amp;quot; /&amp;gt; The Scala client offers the developer APIs &amp;lt;code&amp;gt;SparkSession.newDataFrame(f: proto.Relation.Builder =&amp;gt; Unit)&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;SparkSession.execute(command: proto.Command)&amp;lt;/code&amp;gt;, both since 4.0.0, for sending custom relations and commands.&amp;lt;ref name=&amp;quot;scalasession&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/connect/common/src/main/scala/org/apache/spark/sql/connect/SparkSession.scala |title=SparkSession.scala (Spark Connect Scala client, tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Spark Connect plugin vs other Spark extension points ==&lt;br /&gt;
The Spark documentation says Spark Connect extension points differ from existing ones such as &amp;lt;code&amp;gt;SparkSessionExtensions&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;SparkPlugin&amp;lt;/code&amp;gt;, because they expose functionality to a client.&amp;lt;ref name=&amp;quot;appdev&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! !! Spark Connect plugin !! &amp;lt;code&amp;gt;SparkSessionExtensions&amp;lt;/code&amp;gt; !! &amp;lt;code&amp;gt;SparkPlugin&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Purpose&lt;br /&gt;
| Map a new protocol message to a plan, expression or command&lt;br /&gt;
| Inject rules, parsers and functions into a Spark session&lt;br /&gt;
| Run driver and executor components inside a Spark application&lt;br /&gt;
|-&lt;br /&gt;
! Visible to remote clients&lt;br /&gt;
| Yes; clients send the custom message&lt;br /&gt;
| Only through SQL or plans the client can already build&lt;br /&gt;
| No&lt;br /&gt;
|-&lt;br /&gt;
! Registered with&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.connect.extensions.*.classes&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.sql.extensions&amp;lt;/code&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/StaticSQLConf.scala |title=StaticSQLConf.scala (tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.plugins&amp;lt;/code&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/internal/config/package.scala |title=core/src/main/scala/org/apache/spark/internal/config/package.scala (tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The Spark Connect server is itself loaded as a &amp;lt;code&amp;gt;SparkPlugin&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;org.apache.spark.sql.connect.SparkConnectPlugin&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;sparkplugin&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/connect/server/src/main/scala/org/apache/spark/sql/connect/SparkConnectPlugin.scala |title=SparkConnectPlugin.scala (tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Use in an open lakehouse ==&lt;br /&gt;
[[Delta Lake]] uses Spark Connect plugins for Delta Connect, available from Delta Lake 4.0.0 and described in its documentation as a preview. The documented server command sets &amp;lt;code&amp;gt;spark.connect.extensions.relation.classes&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;org.apache.spark.sql.connect.delta.DeltaRelationPlugin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spark.connect.extensions.command.classes&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;org.apache.spark.sql.connect.delta.DeltaCommandPlugin&amp;lt;/code&amp;gt;, alongside the usual Delta session extension and catalog. The Python &amp;lt;code&amp;gt;DeltaTable&amp;lt;/code&amp;gt; API then works with a remote Spark Connect session.&amp;lt;ref name=&amp;quot;deltaconnect&amp;quot;&amp;gt;{{Cite web |url=https://github.com/delta-io/delta/blob/master/docs/src/content/docs/delta-spark-connect.mdx |title=Delta Connect (aka Spark Connect Support in Delta) |publisher=Delta Lake project |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Spark Connect]]&lt;br /&gt;
* [[Spark Connect server]]&lt;br /&gt;
* [[Spark Connect client]]&lt;br /&gt;
* [[Delta Lake]]&lt;br /&gt;
* [[Apache 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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:52 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Spark_Connect_plugin</comments>
		</item>
		<item>
			<title>Spark Connect server</title>
			<link>https://openlakehouse.io/w/index.php?title=Spark_Connect_server&amp;diff=183&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Spark_Connect_server&amp;diff=183&amp;oldid=0</guid>
			<description>&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            = Spark Connect server&lt;br /&gt;
| also_known_as   = Spark Connect endpoint, Spark Connect service&lt;br /&gt;
| field           = Distributed data processing, client-server protocols&lt;br /&gt;
| introduced      = Apache Spark 3.4.0&lt;br /&gt;
| key_parts       = gRPC service in the Spark driver, session manager, execution manager, interceptors, &amp;lt;code&amp;gt;sbin/start-connect-server.sh&amp;lt;/code&amp;gt;&lt;br /&gt;
| implementations = [[Apache Spark]] (&amp;lt;code&amp;gt;org.apache.spark.sql.connect.service.SparkConnectServer&amp;lt;/code&amp;gt;)&lt;br /&gt;
| related         = [[Spark Connect]], [[Spark Connect client]], [[Spark Connect plugin]], [[Executor]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (sbin/start-connect-server.sh, sql/connect/server config/Connect.scala, SparkConnectService.scala, SparkConnectSessionManager.scala, PreSharedKeyAuthenticationInterceptor.scala, SparkConnectPlugin.scala, sql/connect/docs/client-connection-string.md, python/pyspark/sql/connect/client/core.py), the Spark 4.3.0 configuration, monitoring and Spark Connect overview pages, and the Apache Spark 4.3.0 download directory}}&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;Spark Connect server&amp;#039;&amp;#039;&amp;#039; is the server side of [[Spark Connect]] in [[Apache Spark]]: a gRPC service that runs inside a Spark driver, accepts unresolved logical plans from remote clients, runs them in per-client Spark sessions and streams the results back as Apache Arrow batches.&amp;lt;ref name=&amp;quot;overview&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; Spark implements the server as a driver plugin, so any Spark application can host it, and ships a launcher script that starts a standalone server. By default it listens on port 15002 without TLS, and Spark&amp;#039;s only built-in authentication is an optional pre-shared bearer token.&amp;lt;ref name=&amp;quot;connectconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/connect/server/src/main/scala/org/apache/spark/sql/connect/config/Connect.scala |title=Connect.scala (tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;service&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/connect/server/src/main/scala/org/apache/spark/sql/connect/service/SparkConnectService.scala |title=SparkConnectService.scala (tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How is a Spark Connect server deployed? ==&lt;br /&gt;
The usual way to start a Spark Connect server is &amp;lt;code&amp;gt;sbin/start-connect-server.sh&amp;lt;/code&amp;gt; from a Spark distribution.&amp;lt;ref name=&amp;quot;overview&amp;quot; /&amp;gt; The script runs the class &amp;lt;code&amp;gt;org.apache.spark.sql.connect.service.SparkConnectServer&amp;lt;/code&amp;gt; through &amp;lt;code&amp;gt;spark-submit&amp;lt;/code&amp;gt; as a daemon named &amp;quot;Spark Connect server&amp;quot;, and it accepts the normal &amp;lt;code&amp;gt;spark-submit&amp;lt;/code&amp;gt; options such as &amp;lt;code&amp;gt;--master&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;--conf&amp;lt;/code&amp;gt;. With &amp;lt;code&amp;gt;--wait&amp;lt;/code&amp;gt; as the first argument it runs in the foreground instead of as a daemon. &amp;lt;code&amp;gt;sbin/stop-connect-server.sh&amp;lt;/code&amp;gt; stops it.&amp;lt;ref name=&amp;quot;startsh&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sbin/start-connect-server.sh |title=start-connect-server.sh (tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;stopsh&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sbin/stop-connect-server.sh |title=stop-connect-server.sh (tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because the server is a Spark driver, it runs on any cluster manager that the driver supports, and its queries run on ordinary [[executor]]s. Inside the driver, the server is started by the driver plugin &amp;lt;code&amp;gt;org.apache.spark.sql.connect.SparkConnectPlugin&amp;lt;/code&amp;gt;. Spark&amp;#039;s source describes this design as a way to decouple the build of Spark Connect from Spark core: the server is enabled by putting its JAR on the classpath and loading the plugin through &amp;lt;code&amp;gt;spark.plugins&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;plugin&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/connect/server/src/main/scala/org/apache/spark/sql/connect/SparkConnectPlugin.scala |title=SparkConnectPlugin.scala (tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; PySpark uses the same plugin when &amp;lt;code&amp;gt;SparkSession.builder.remote(&amp;quot;local[*]&amp;quot;)&amp;lt;/code&amp;gt; starts a local server for the current process.&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/connect/session.py |title=pyspark/sql/connect/session.py (tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Spark 4.3.0 release is published both as the usual &amp;lt;code&amp;gt;spark-4.3.0-bin-hadoop3.tgz&amp;lt;/code&amp;gt; and as &amp;lt;code&amp;gt;spark-4.3.0-bin-hadoop3-connect.tgz&amp;lt;/code&amp;gt;, the variant with Spark Connect enabled by default that Spark 4.0.0 introduced.&amp;lt;ref name=&amp;quot;dl&amp;quot;&amp;gt;{{Cite web |url=https://downloads.apache.org/spark/spark-4.3.0/ |title=Index of /spark/spark-4.3.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;r400&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4-0-0.html |title=Spark Release 4.0.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Which configuration keys does the server use? ==&lt;br /&gt;
The main Spark Connect server settings are static configurations, set when the driver starts:&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;&amp;lt;ref name=&amp;quot;connectconf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Key !! Default !! Meaning !! Since&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.connect.grpc.binding.address&amp;lt;/code&amp;gt; || (none) || Address to bind || 4.0.0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.connect.grpc.binding.port&amp;lt;/code&amp;gt; || 15002 || Port to bind || 3.4.0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.connect.grpc.port.maxRetries&amp;lt;/code&amp;gt; || 0 || Port retry attempts; 0 fails fast on a port conflict || 4.0.0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.connect.grpc.interceptor.classes&amp;lt;/code&amp;gt; || (none) || Comma-separated &amp;lt;code&amp;gt;io.grpc.ServerInterceptor&amp;lt;/code&amp;gt; classes || 3.4.0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.connect.grpc.maxInboundMessageSize&amp;lt;/code&amp;gt; || 134217728 || Largest accepted gRPC request, in bytes || 3.4.0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.connect.grpc.keepAlive.enabled&amp;lt;/code&amp;gt; || true || Server keepalive pings to detect dead client connections || 4.3.0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.connect.grpc.keepAlive.time&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;.timeout&amp;lt;/code&amp;gt; || 60s / 20s || Idle time before a ping, and wait for its acknowledgement || 4.3.0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.connect.extensions.relation.classes&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;.expression.classes&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;.command.classes&amp;lt;/code&amp;gt; || (none) || [[Spark Connect plugin]] classes || 3.4.0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.sql.connect.ui.retainedSessions&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;retainedStatements&amp;lt;/code&amp;gt; || 200 / 200 || Sessions and statements kept in the Spark Connect UI || 3.5.0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== How are client sessions isolated? ==&lt;br /&gt;
The Spark Connect server keeps one server-side Spark session for each pair of user ID and session ID sent by the client. A new pair gets a new session created with &amp;lt;code&amp;gt;SparkSession.newSession()&amp;lt;/code&amp;gt; on the server&amp;#039;s base session; the session ID must be a UUID, and an ID that was already closed cannot be reused.&amp;lt;ref name=&amp;quot;sessmgr&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/connect/server/src/main/scala/org/apache/spark/sql/connect/service/SparkConnectSessionManager.scala |title=SparkConnectSessionManager.scala (tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Clients set these values with the &amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;session_id&amp;lt;/code&amp;gt; parameters of the connection string; by default the session ID is a random UUID, and reusing one lets several clients, even in different languages, share a session.&amp;lt;ref name=&amp;quot;connstr&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/connect/docs/client-connection-string.md |title=Connecting to Spark Connect using Clients (tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Session isolation in the Spark Connect server covers session state, not the whole application. The Spark documentation states that temporary views, runtime SQL configurations and session artifacts are per session, while state backed by the shared &amp;lt;code&amp;gt;SparkContext&amp;lt;/code&amp;gt;, such as the persistent catalog, global temporary views and cached datasets, is shared by all sessions.&amp;lt;ref name=&amp;quot;overview&amp;quot; /&amp;gt; The server starts its base session with artifact session isolation enabled, so JARs and files uploaded by one client are kept apart from other sessions.&amp;lt;ref name=&amp;quot;server&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/connect/server/src/main/scala/org/apache/spark/sql/connect/service/SparkConnectServer.scala |title=SparkConnectServer.scala (tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; All sessions run on the same driver and executors.&lt;br /&gt;
&lt;br /&gt;
== What timeouts apply to sessions and operations? ==&lt;br /&gt;
The Spark Connect server removes idle sessions and abandoned operations with internal settings:&amp;lt;ref name=&amp;quot;connectconf&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;spark.connect.session.manager.defaultSessionTimeout&amp;lt;/code&amp;gt; (default 60 minutes, since 4.0.0) removes a session that has received no RPC for that long; &amp;lt;code&amp;gt;-1&amp;lt;/code&amp;gt; keeps sessions forever.&amp;lt;ref name=&amp;quot;connectconf&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;spark.connect.execute.manager.detachedTimeout&amp;lt;/code&amp;gt; (default 5 minutes, since 3.5.0) removes an execution that no RPC is attached to.&amp;lt;ref name=&amp;quot;connectconf&amp;quot; /&amp;gt;&lt;br /&gt;
* Reattachable execution (&amp;lt;code&amp;gt;spark.connect.execute.reattachable.enabled&amp;lt;/code&amp;gt;, default true, since 3.5.0) lets a client reconnect to a running query; the server ends one response stream after &amp;lt;code&amp;gt;spark.connect.execute.reattachable.senderMaxStreamDuration&amp;lt;/code&amp;gt; (default 2 minutes) or &amp;lt;code&amp;gt;spark.connect.execute.reattachable.senderMaxStreamSize&amp;lt;/code&amp;gt; (default 1g), and the client reattaches.&amp;lt;ref name=&amp;quot;connectconf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These keys are marked internal in the source, so they do not appear in the configuration page and may change without notice.&amp;lt;ref name=&amp;quot;connectconf&amp;quot; /&amp;gt; Spark 4.3.0 added REST endpoints under &amp;lt;code&amp;gt;/applications/[app-id]/connect/&amp;lt;/code&amp;gt; that list and describe sessions and operations.&amp;lt;ref name=&amp;quot;monitoring&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/monitoring.html |title=Monitoring and Instrumentation (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;r430&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4-3-0.html |title=Spark Release 4.3.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How are Spark Connect clients authenticated? ==&lt;br /&gt;
The Spark Connect overview states that Spark Connect has no built-in authentication and is designed to work with authenticating proxies in front of its gRPC HTTP/2 interface.&amp;lt;ref name=&amp;quot;overview&amp;quot; /&amp;gt; In the 4.3.0 source, the server has three layers to consider:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Mechanism !! Shipped with Spark? !! What it does&lt;br /&gt;
|-&lt;br /&gt;
| Pre-shared token (&amp;lt;code&amp;gt;spark.connect.authenticate.token&amp;lt;/code&amp;gt; or the &amp;lt;code&amp;gt;SPARK_CONNECT_AUTHENTICATE_TOKEN&amp;lt;/code&amp;gt; environment variable)&lt;br /&gt;
| Yes; internal setting added in 4.0.0&lt;br /&gt;
| Rejects any call whose &amp;lt;code&amp;gt;Authorization&amp;lt;/code&amp;gt; header is not &amp;lt;code&amp;gt;Bearer&amp;lt;/code&amp;gt; plus the token, with gRPC status &amp;lt;code&amp;gt;UNAUTHENTICATED&amp;lt;/code&amp;gt;. One shared secret; no users or roles.&amp;lt;ref name=&amp;quot;connectconf&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;psk&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/connect/server/src/main/scala/org/apache/spark/sql/connect/service/PreSharedKeyAuthenticationInterceptor.scala |title=PreSharedKeyAuthenticationInterceptor.scala (tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Custom interceptors (&amp;lt;code&amp;gt;spark.connect.grpc.interceptor.classes&amp;lt;/code&amp;gt;)&lt;br /&gt;
| Hook only; the user supplies the classes&lt;br /&gt;
| Runs &amp;lt;code&amp;gt;io.grpc.ServerInterceptor&amp;lt;/code&amp;gt; code on every call, for example to validate a JWT or map a caller to a user. When the token check is on, it runs first, so interceptors see only authenticated calls.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;service&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| TLS and identity-aware proxy&lt;br /&gt;
| No; external&lt;br /&gt;
| The server&amp;#039;s gRPC builder sets no TLS context, so encryption and single sign-on are added by a proxy or gateway in front of it.&amp;lt;ref name=&amp;quot;service&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;overview&amp;quot; /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
On the client side, the &amp;lt;code&amp;gt;token&amp;lt;/code&amp;gt; parameter of the connection string sends a standard gRPC bearer token, and the connection string reference states that setting it enables TLS.&amp;lt;ref name=&amp;quot;connstr&amp;quot; /&amp;gt; The PySpark client makes one exception: for &amp;lt;code&amp;gt;localhost&amp;lt;/code&amp;gt; without &amp;lt;code&amp;gt;use_ssl=true&amp;lt;/code&amp;gt;, it sends the token over gRPC local channel credentials instead of TLS.&amp;lt;ref name=&amp;quot;core&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/sql/connect/client/core.py |title=pyspark/sql/connect/client/core.py (tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; When PySpark starts a local server itself, it generates a random token unless one is set.&amp;lt;ref name=&amp;quot;pysession&amp;quot; /&amp;gt; For a remote server, a token therefore needs a TLS-terminating proxy in front of the plaintext gRPC port.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
The following commands start a server on a local master that requires a token and binds only to the loopback interface, then connect with PySpark:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export SPARK_CONNECT_AUTHENTICATE_TOKEN=&amp;quot;$(openssl rand -hex 32)&amp;quot;&lt;br /&gt;
$SPARK_HOME/sbin/start-connect-server.sh --master &amp;quot;local[*]&amp;quot; \&lt;br /&gt;
  --conf spark.connect.grpc.binding.address=127.0.0.1 \&lt;br /&gt;
  --conf spark.connect.grpc.binding.port=15002&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import os&lt;br /&gt;
from pyspark.sql import SparkSession&lt;br /&gt;
&lt;br /&gt;
token = os.environ[&amp;quot;SPARK_CONNECT_AUTHENTICATE_TOKEN&amp;quot;]&lt;br /&gt;
spark = SparkSession.builder.remote(f&amp;quot;sc://localhost:15002/;token={token}&amp;quot;).getOrCreate()&lt;br /&gt;
spark.range(5).show()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Spark Connect]]&lt;br /&gt;
* [[Spark Connect client]]&lt;br /&gt;
* [[Spark Connect plugin]]&lt;br /&gt;
* [[Executor]]&lt;br /&gt;
* [[Apache 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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:52 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Spark_Connect_server</comments>
		</item>
		<item>
			<title>SparkContext</title>
			<link>https://openlakehouse.io/w/index.php?title=SparkContext&amp;diff=184&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=SparkContext&amp;diff=184&amp;oldid=0</guid>
			<description>&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            = SparkContext&lt;br /&gt;
| also_known_as   = &amp;lt;code&amp;gt;sc&amp;lt;/code&amp;gt; (the variable name in shells)&lt;br /&gt;
| field           = Distributed data processing&lt;br /&gt;
| key_parts       = Connection to the cluster manager, executors, DAG and task schedulers, RDD API, broadcast variables, accumulators, job groups and tags&lt;br /&gt;
| implementations = [[Apache Spark]] (Spark Classic only)&lt;br /&gt;
| related         = [[SparkSession]], [[Driver (Apache Spark)]], [[RDD]], [[Spark Connect]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (core SparkContext.scala, the Spark 2.0.0 release notes, docs/cluster-overview.md, docs/spark-connect-overview.md, docs/app-dev-spark-connect.md, python/pyspark/sql/connect/session.py, python/pyspark/sql/session.py, sql/api SparkSession.scala)}}&lt;br /&gt;
&lt;br /&gt;
In [[Apache Spark]], a &amp;#039;&amp;#039;&amp;#039;SparkContext&amp;#039;&amp;#039;&amp;#039; is the object in the [[Driver (Apache Spark)|driver]] that represents the connection to a Spark cluster; it acquires [[executor]]s, schedules work on them and is used to create [[RDD]]s, accumulators and broadcast variables.&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; The source code still calls it the &amp;quot;main entry point for Spark functionality&amp;quot;, but since Spark 2.0.0 DataFrame and SQL code starts from a [[SparkSession]], which creates or reuses a SparkContext underneath.&amp;lt;ref name=&amp;quot;sc&amp;quot; /&amp;gt;&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 SparkContext still runs every classic application, but [[Spark Connect]] clients cannot use it.&lt;br /&gt;
&lt;br /&gt;
== What does SparkContext still do in Spark 4? ==&lt;br /&gt;
SparkContext remains the core of a Spark Classic application in Spark 4.3.0. The cluster overview describes Spark applications as independent sets of processes coordinated by the SparkContext in the driver program: it connects to the cluster manager (standalone, YARN or Kubernetes), acquires executors, sends them the application code and then sends them tasks.&amp;lt;ref name=&amp;quot;cluster&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/cluster-overview.html |title=Cluster Mode Overview (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; DataFrame and SQL queries are planned by the [[SparkSession]] and then run as jobs submitted through this SparkContext.&lt;br /&gt;
&lt;br /&gt;
Only one SparkContext may be active per JVM. Creating a second one while the first is running fails with &amp;quot;Only one SparkContext should be running in this JVM (see SPARK-2243)&amp;quot;; the first must be stopped with &amp;lt;code&amp;gt;stop()&amp;lt;/code&amp;gt; before a new one is made.&amp;lt;ref name=&amp;quot;sc&amp;quot; /&amp;gt; A side effect of this design is isolation: each application has its own executors, so two applications cannot share in-memory data except through external storage.&amp;lt;ref name=&amp;quot;cluster&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The public API of SparkContext in Spark 4.3.0 still covers these areas:&amp;lt;ref name=&amp;quot;sc&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Area !! Examples of SparkContext methods&lt;br /&gt;
|-&lt;br /&gt;
| Creating RDDs || &amp;lt;code&amp;gt;parallelize&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;textFile&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;runJob&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Shared variables || &amp;lt;code&amp;gt;broadcast&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;longAccumulator&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Shipping dependencies || &amp;lt;code&amp;gt;addFile&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;addJar&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Grouping and cancelling jobs || &amp;lt;code&amp;gt;setJobGroup&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;cancelJobGroup&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;setLocalProperty&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Inspecting the application || &amp;lt;code&amp;gt;applicationId&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;uiWebUrl&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;statusTracker&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;defaultParallelism&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;setLogLevel&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Fault tolerance for long lineages || &amp;lt;code&amp;gt;setCheckpointDir&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In PySpark Classic, &amp;lt;code&amp;gt;spark.sparkContext&amp;lt;/code&amp;gt; returns the SparkContext behind a session. Code that uses only DataFrames and SQL seldom needs it; code that uses the RDD API, accumulators or &amp;lt;code&amp;gt;sc.setJobGroup&amp;lt;/code&amp;gt; does.&lt;br /&gt;
&lt;br /&gt;
== Why do Spark Connect clients not have a SparkContext? ==&lt;br /&gt;
A Spark Connect client does not run in the same process as the Spark driver. It builds logical plans and sends them to a Spark Connect server, which runs the driver and its SparkContext. The Spark Connect overview lists two consequences: the protocol, which is built on logical plans, does not support all of Spark&amp;#039;s execution APIs, &amp;quot;most importantly RDDs&amp;quot;; and the client, which gets a session rather than the whole application, has no access to the static Spark configuration or the SparkContext.&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;
The reason is that one server&amp;#039;s SparkContext serves many client sessions. The overview explains that a Connect client gets a session-based interface and has no access to properties that change the environment for all connected clients, the SparkContext above all.&amp;lt;ref name=&amp;quot;connect&amp;quot; /&amp;gt; In PySpark 4.3.0, reading &amp;lt;code&amp;gt;spark.sparkContext&amp;lt;/code&amp;gt; on a Connect session raises &amp;lt;code&amp;gt;JVM_ATTRIBUTE_NOT_SUPPORTED&amp;lt;/code&amp;gt;, and the Scala API marks &amp;lt;code&amp;gt;SparkSession.sparkContext&amp;lt;/code&amp;gt; as &amp;lt;code&amp;gt;@ClassicOnly&amp;lt;/code&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;&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;
== What replaces SparkContext calls in Spark Connect? ==&lt;br /&gt;
The Spark Connect application guide says that RDDs can no longer be used directly from Spark Connect clients, and that alternatives for missing RDD functionality are provided in the higher-level APIs.&amp;lt;ref name=&amp;quot;appdev&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/app-dev-spark-connect.html |title=Application Development with Spark Connect (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; For common SparkContext calls, the [[SparkSession]] has methods that work over Spark Connect:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! SparkContext usage !! Session-level alternative&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;sc.parallelize(data)&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;spark.createDataFrame(data)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;spark.range(n)&amp;lt;/code&amp;gt;, which build a DataFrame instead of an RDD&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;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;sc.addFile&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;sc.addPyFile&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;spark.addArtifacts(...)&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;pysession&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;sc.setJobGroup&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;sc.cancelJobGroup&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;spark.addTag(tag)&amp;lt;/code&amp;gt;, then &amp;lt;code&amp;gt;spark.interruptTag(tag)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;spark.interruptAll()&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;pysession&amp;quot; /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The session-level methods in this table work in both Connect and Classic sessions since Spark 4.0.0, so code that uses them runs in either mode.&amp;lt;ref name=&amp;quot;pysession&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[SparkSession]]&lt;br /&gt;
* [[Spark Connect]]&lt;br /&gt;
* [[Driver (Apache Spark)]]&lt;br /&gt;
* [[RDD]]&lt;br /&gt;
* [[Job, stage and task]]&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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:52 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:SparkContext</comments>
		</item>
		<item>
			<title>Sort-merge join</title>
			<link>https://openlakehouse.io/w/index.php?title=Sort-merge_join&amp;diff=179&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Sort-merge_join&amp;diff=179&amp;oldid=0</guid>
			<description>&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            = Sort-merge join&lt;br /&gt;
| also_known_as   = Shuffle sort-merge join, SMJ, &amp;lt;code&amp;gt;SortMergeJoin&amp;lt;/code&amp;gt;&lt;br /&gt;
| field           = Distributed query processing&lt;br /&gt;
| key_parts       = Shuffle exchange, hash partitioning, per-partition sort, merge scan&lt;br /&gt;
| implementations = [[Apache Spark]]&lt;br /&gt;
| related         = [[Broadcast join]], [[Shuffle hash join]], [[Shuffle]], [[Adaptive Query Execution]], [[Logical plan and physical plan]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (SparkStrategies.scala, SortMergeJoinExec.scala, joins.scala, SQLConf.scala, sql-performance-tuning.md and sql-ref-syntax-qry-select-hints.md)}}&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;&amp;#039;sort-merge join&amp;#039;&amp;#039;&amp;#039; is a distributed equality-join strategy that repartitions both inputs by the join keys, sorts each resulting partition by those keys, and merges the two ordered streams.&amp;lt;ref name=&amp;quot;smjexec&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/joins/SortMergeJoinExec.scala |title=SortMergeJoinExec.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; In [[Apache Spark]], &amp;lt;code&amp;gt;SortMergeJoin&amp;lt;/code&amp;gt; is the usual physical operator for an equality join between two large inputs when neither side can be broadcast: Spark prefers it over a [[shuffle hash join]] by default, and its memory use does not depend on building an entire input partition as a hash table.&amp;lt;ref name=&amp;quot;strategies&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/SparkStrategies.scala |title=SparkStrategies.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;sqlconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala |title=SQLConf.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does a sort-merge join work? ==&lt;br /&gt;
A Spark sort-merge join has three distributed steps:&amp;lt;ref name=&amp;quot;smjexec&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;Shuffle both sides.&amp;#039;&amp;#039;&amp;#039; Spark applies compatible hash partitioning to the two inputs so rows with equal join keys arrive in partitions with the same partition number.&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;Sort each partition.&amp;#039;&amp;#039;&amp;#039; Each side is ordered by its join keys. The &amp;lt;code&amp;gt;SortMergeJoinExec&amp;lt;/code&amp;gt; operator declares ascending key order as a requirement for both children.&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;Merge matching keys.&amp;#039;&amp;#039;&amp;#039; A task reads one partition from each side, advances through the two ordered streams, and emits rows when the keys compare equal. Spark may buffer rows that share a key and can spill that buffer when necessary.&lt;br /&gt;
&lt;br /&gt;
The two exchanges are stage boundaries. The exchange writers create shuffle files, and later tasks fetch, sort and join the matching partitions. This makes sort-merge join suitable for inputs that are too large to copy to every executor, but it also means network I/O, disk I/O and sorting work on both sides.&lt;br /&gt;
&lt;br /&gt;
== What does SortMergeJoin mean in EXPLAIN? ==&lt;br /&gt;
A representative physical plan has this shape:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
*(5) SortMergeJoin [customer_id#1L], [customer_id#8L], Inner&lt;br /&gt;
:- *(2) Sort [customer_id#1L ASC NULLS FIRST], false, 0&lt;br /&gt;
:  +- Exchange hashpartitioning(customer_id#1L, 200), ENSURE_REQUIREMENTS&lt;br /&gt;
:     +- Scan parquet sales&lt;br /&gt;
+- *(4) Sort [customer_id#8L ASC NULLS FIRST], false, 0&lt;br /&gt;
   +- Exchange hashpartitioning(customer_id#8L, 200), ENSURE_REQUIREMENTS&lt;br /&gt;
      +- Scan parquet customers&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;SortMergeJoin&amp;lt;/code&amp;gt; names the algorithm and lists the left and right join keys. The two &amp;lt;code&amp;gt;Exchange hashpartitioning&amp;lt;/code&amp;gt; nodes show that both inputs shuffle. The &amp;lt;code&amp;gt;Sort&amp;lt;/code&amp;gt; nodes satisfy the ordering required by the join. The partition count shown by a real plan comes from the chosen exchange partitioning and can be changed by [[Adaptive Query Execution]] after runtime statistics become available.&amp;lt;ref name=&amp;quot;perf&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-performance-tuning.html |title=Performance Tuning (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an input already has compatible partitioning or ordering, Spark can reuse those properties rather than inserting every operator shown above. &amp;lt;code&amp;gt;EXPLAIN FORMATTED&amp;lt;/code&amp;gt; is useful for tracing each &amp;lt;code&amp;gt;Exchange&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Sort&amp;lt;/code&amp;gt; to its input.&amp;lt;ref&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-ref-syntax-qry-explain.html |title=EXPLAIN statement (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== When does Spark choose sort-merge join? ==&lt;br /&gt;
For an equality join without hints, Spark 4.3.0 tries a broadcast hash join first. It next considers a shuffled hash join only when one side meets the size tests and &amp;lt;code&amp;gt;spark.sql.join.preferSortMergeJoin&amp;lt;/code&amp;gt; is false. Spark then chooses sort-merge join when the join keys have a sortable data type.&amp;lt;ref name=&amp;quot;strategies&amp;quot; /&amp;gt; The internal setting &amp;lt;code&amp;gt;spark.sql.join.preferSortMergeJoin&amp;lt;/code&amp;gt; defaults to &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;MERGE&amp;lt;/code&amp;gt; hint asks Spark to use sort-merge join. Its aliases are &amp;lt;code&amp;gt;SHUFFLE_MERGE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;MERGEJOIN&amp;lt;/code&amp;gt;:&amp;lt;ref name=&amp;quot;hints&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-ref-syntax-qry-select-hints.html |title=Hints (Spark 4.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;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT /*+ MERGE(large_orders, large_customers) */&lt;br /&gt;
       large_orders.order_id, large_customers.region&lt;br /&gt;
FROM large_orders&lt;br /&gt;
JOIN large_customers&lt;br /&gt;
  ON large_orders.customer_id = large_customers.customer_id;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A hint is a request rather than a guarantee. Spark ignores an inapplicable merge hint, including when there are no equality keys or the key type cannot supply the binary ordering required by the strategy.&amp;lt;ref name=&amp;quot;hints&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;strategies&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does sort-merge join compare with other joins? ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! !! Sort-merge join !! Shuffle hash join !! Broadcast hash join&lt;br /&gt;
|-&lt;br /&gt;
! Data movement&lt;br /&gt;
| Shuffles both inputs by the join keys&lt;br /&gt;
| Shuffles both inputs by the join keys&lt;br /&gt;
| Broadcasts the build side; normally does not shuffle the streamed side&lt;br /&gt;
|-&lt;br /&gt;
! Local work&lt;br /&gt;
| Sorts both partitions, then merges ordered streams&lt;br /&gt;
| Builds a hash table from one shuffled partition and probes it with the other&lt;br /&gt;
| Builds one relation at the driver, broadcasts it, and probes it in each task&lt;br /&gt;
|-&lt;br /&gt;
! Main memory risk&lt;br /&gt;
| Groups of equal keys may need buffering; the implementation can spill its match buffer&amp;lt;ref name=&amp;quot;smjexec&amp;quot; /&amp;gt;&lt;br /&gt;
| The build partition must fit well enough to construct a local hash table&lt;br /&gt;
| The complete build side must be collected and broadcast&lt;br /&gt;
|-&lt;br /&gt;
! Typical use in Spark&lt;br /&gt;
| Two large inputs with sortable equality keys&lt;br /&gt;
| One side is much smaller per partition, or the strategy is selected by hint or AQE&lt;br /&gt;
| One complete input is small enough to broadcast&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Sort-merge join can be slower when the shuffle and sort dominate the query, especially if the inputs were not already partitioned compatibly. Skew can leave one reducer with far more rows than the others. AQE can split skewed sort-merge partitions, coalesce small shuffle partitions, or convert an eligible sort-merge join to a broadcast or shuffled hash join after it observes actual shuffle sizes.&amp;lt;ref name=&amp;quot;perf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What cannot sort-merge join do? ==&lt;br /&gt;
Spark&amp;#039;s sort-merge implementation requires equality keys with sortable data types.&amp;lt;ref name=&amp;quot;strategies&amp;quot; /&amp;gt; A condition such as &amp;lt;code&amp;gt;left.ts &amp;amp;gt; right.ts&amp;lt;/code&amp;gt; by itself is not a sort-merge equality join; Spark must use another physical strategy. A sort-merge join also cannot remove the cost of a required shuffle merely because the SQL uses a &amp;lt;code&amp;gt;MERGE&amp;lt;/code&amp;gt; hint.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Apache Spark]]&lt;br /&gt;
* [[Broadcast join]]&lt;br /&gt;
* [[Shuffle hash join]]&lt;br /&gt;
* [[Adaptive Query Execution]]&lt;br /&gt;
* [[Narrow and wide transformations]]&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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:51 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Sort-merge_join</comments>
		</item>
		<item>
			<title>Spark configuration precedence</title>
			<link>https://openlakehouse.io/w/index.php?title=Spark_configuration_precedence&amp;diff=180&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Spark_configuration_precedence&amp;diff=180&amp;oldid=0</guid>
			<description>&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            = Spark configuration precedence&lt;br /&gt;
| also_known_as   = Spark property precedence&lt;br /&gt;
| field           = Distributed data processing&lt;br /&gt;
| key_parts       = &amp;lt;code&amp;gt;spark-defaults.conf&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;--properties-file&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;--conf&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;SparkConf&amp;lt;/code&amp;gt;, session configuration, SQL &amp;lt;code&amp;gt;SET&amp;lt;/code&amp;gt;&lt;br /&gt;
| implementations = [[Apache Spark]]&lt;br /&gt;
| related         = [[Spark-submit|spark-submit]], [[Spark Connect]], [[Executor]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (docs/configuration.md, docs/submitting-applications.md, docs/sql-migration-guide.md, docs/spark-connect-overview.md, SQLConf.scala, StaticSQLConf.scala, classic/RuntimeConfig.scala, python/pyspark/sql/session.py and conf.py) and SPARK-48392}}&lt;br /&gt;
&lt;br /&gt;
In [[Apache Spark]], &amp;#039;&amp;#039;&amp;#039;configuration precedence&amp;#039;&amp;#039;&amp;#039; is the order in which Spark merges property values from the defaults file, the &amp;lt;code&amp;gt;spark-submit&amp;lt;/code&amp;gt; command line and application code, and the rule that decides which of those values can still change after the application has started.&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; Values set on a &amp;lt;code&amp;gt;SparkConf&amp;lt;/code&amp;gt; in code win over &amp;lt;code&amp;gt;--conf&amp;lt;/code&amp;gt; flags, which win over &amp;lt;code&amp;gt;spark-defaults.conf&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt; Once the application runs, only runtime SQL configurations can be changed per session, with &amp;lt;code&amp;gt;spark.conf.set&amp;lt;/code&amp;gt; or the SQL &amp;lt;code&amp;gt;SET&amp;lt;/code&amp;gt; command.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What is the order of precedence for Spark properties? ==&lt;br /&gt;
Spark reads properties from several places when an application starts and merges them. The Spark 4.3.0 configuration guide gives this order, highest first:&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Rank !! Source !! Example&lt;br /&gt;
|-&lt;br /&gt;
| 1 (highest) || Properties set directly on a &amp;lt;code&amp;gt;SparkConf&amp;lt;/code&amp;gt; or the &amp;lt;code&amp;gt;SparkSession&amp;lt;/code&amp;gt; builder in application code || &amp;lt;code&amp;gt;SparkSession.builder.config(&amp;quot;spark.sql.shuffle.partitions&amp;quot;, &amp;quot;64&amp;quot;)&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Flags passed to &amp;lt;code&amp;gt;spark-submit&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spark-shell&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;pyspark&amp;lt;/code&amp;gt;: &amp;lt;code&amp;gt;--conf&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;-c&amp;lt;/code&amp;gt;, dedicated flags such as &amp;lt;code&amp;gt;--master&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;--executor-memory&amp;lt;/code&amp;gt;, and a file given with &amp;lt;code&amp;gt;--properties-file&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;--conf spark.eventLog.enabled=true&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 3 (lowest) || &amp;lt;code&amp;gt;conf/spark-defaults.conf&amp;lt;/code&amp;gt; under &amp;lt;code&amp;gt;SPARK_HOME&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;SPARK_CONF_DIR&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;spark.executor.memory 4g&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Any property that none of these sources sets keeps its built-in default. The Environment tab of the Spark UI lists only values that were set explicitly through &amp;lt;code&amp;gt;spark-defaults.conf&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;SparkConf&amp;lt;/code&amp;gt; or the command line.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When a configuration key has been renamed in a newer Spark version, Spark still accepts the old name, but any value under the new name takes precedence over the old one.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How do spark-defaults.conf and --properties-file interact? ==&lt;br /&gt;
By default &amp;lt;code&amp;gt;spark-submit&amp;lt;/code&amp;gt; reads &amp;lt;code&amp;gt;conf/spark-defaults.conf&amp;lt;/code&amp;gt;, a file with one whitespace-separated key and value per line.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt; Setting &amp;lt;code&amp;gt;SPARK_CONF_DIR&amp;lt;/code&amp;gt; makes Spark read &amp;lt;code&amp;gt;spark-defaults.conf&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spark-env.sh&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;log4j2.properties&amp;lt;/code&amp;gt; from another directory instead of &amp;lt;code&amp;gt;SPARK_HOME/conf&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When a file is passed with &amp;lt;code&amp;gt;--properties-file&amp;lt;/code&amp;gt;, Spark no longer loads &amp;lt;code&amp;gt;spark-defaults.conf&amp;lt;/code&amp;gt; unless the &amp;lt;code&amp;gt;--load-spark-defaults&amp;lt;/code&amp;gt; flag is also given. With both, values in the &amp;lt;code&amp;gt;--properties-file&amp;lt;/code&amp;gt; file take precedence over those in &amp;lt;code&amp;gt;spark-defaults.conf&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;submit&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/submitting-applications.html |title=Submitting Applications (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;ssargs&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/deploy/SparkSubmitArguments.scala |title=SparkSubmitArguments.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The &amp;lt;code&amp;gt;--load-spark-defaults&amp;lt;/code&amp;gt; flag was added in Spark 4.0.0 by SPARK-48392.&amp;lt;ref&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-48392 |title=SPARK-48392: Load spark-defaults.conf when passing configurations to spark-submit through --properties-file |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Within rank 2, &amp;lt;code&amp;gt;SparkSubmitArguments&amp;lt;/code&amp;gt; at the v4.3.0 tag gives &amp;lt;code&amp;gt;--conf&amp;lt;/code&amp;gt; values priority over the &amp;lt;code&amp;gt;--properties-file&amp;lt;/code&amp;gt; file, and that file priority over &amp;lt;code&amp;gt;spark-defaults.conf&amp;lt;/code&amp;gt;; a dedicated flag such as &amp;lt;code&amp;gt;--master&amp;lt;/code&amp;gt; wins over the same property passed as &amp;lt;code&amp;gt;--conf spark.master&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;ssargs&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see which source supplied a value, the Spark documentation recommends running &amp;lt;code&amp;gt;spark-submit&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;--verbose&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;submit&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Which properties must be set before the application starts? ==&lt;br /&gt;
Spark&amp;#039;s configuration guide divides properties into two kinds. Deploy-related properties, such as &amp;lt;code&amp;gt;spark.driver.memory&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spark.executor.instances&amp;lt;/code&amp;gt;, may have no effect when set in code at runtime, so the guide recommends setting them in a configuration file or on the &amp;lt;code&amp;gt;spark-submit&amp;lt;/code&amp;gt; command line. Runtime-control properties, such as &amp;lt;code&amp;gt;spark.task.maxFailures&amp;lt;/code&amp;gt;, can be set either way.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The driver&amp;#039;s JVM settings are the most common case. In client deploy mode, &amp;lt;code&amp;gt;spark.driver.memory&amp;lt;/code&amp;gt; (default &amp;lt;code&amp;gt;1g&amp;lt;/code&amp;gt;) and &amp;lt;code&amp;gt;spark.driver.extraJavaOptions&amp;lt;/code&amp;gt; must not be set through &amp;lt;code&amp;gt;SparkConf&amp;lt;/code&amp;gt; in the application, because the driver JVM has already started when that code runs. They must be given with &amp;lt;code&amp;gt;--driver-memory&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;--driver-java-options&amp;lt;/code&amp;gt; or the defaults file instead.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What can change at runtime? ==&lt;br /&gt;
Spark SQL configurations come in two kinds:&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Runtime SQL configurations&amp;#039;&amp;#039;&amp;#039; are per session and mutable. They take initial values from the defaults file, &amp;lt;code&amp;gt;--conf&amp;lt;/code&amp;gt; or the &amp;lt;code&amp;gt;SparkConf&amp;lt;/code&amp;gt; used to build the session, and can then be read and changed with &amp;lt;code&amp;gt;spark.conf.get&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;spark.conf.set&amp;lt;/code&amp;gt;, the SQL &amp;lt;code&amp;gt;SET&amp;lt;/code&amp;gt; command, and reset with &amp;lt;code&amp;gt;RESET&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt;spark.sql.shuffle.partitions&amp;lt;/code&amp;gt; (default 200) is an example.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;sqlconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala |title=SQLConf.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Static SQL configurations&amp;#039;&amp;#039;&amp;#039; are shared by all sessions and fixed once the first session starts. They can be read with &amp;lt;code&amp;gt;spark.conf.get&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;SET key&amp;lt;/code&amp;gt;, but not set or unset. &amp;lt;code&amp;gt;spark.sql.extensions&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spark.sql.warehouse.dir&amp;lt;/code&amp;gt; are static.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/StaticSQLConf.scala |title=StaticSQLConf.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Spark 4.3.0, &amp;lt;code&amp;gt;spark.conf.set&amp;lt;/code&amp;gt; on a static SQL key fails with the error condition &amp;lt;code&amp;gt;CANNOT_MODIFY_STATIC_CONFIG&amp;lt;/code&amp;gt;, and on a Spark core key (one registered as a &amp;lt;code&amp;gt;SparkConf&amp;lt;/code&amp;gt; entry, such as &amp;lt;code&amp;gt;spark.executor.memory&amp;lt;/code&amp;gt;) it fails with &amp;lt;code&amp;gt;CANNOT_MODIFY_CONFIG&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;rtconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/classic/RuntimeConfig.scala |title=classic/RuntimeConfig.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The SQL &amp;lt;code&amp;gt;SET&amp;lt;/code&amp;gt; command has rejected Spark core keys since Spark 3.0; before 3.0 it accepted them silently with no effect. The internal flag &amp;lt;code&amp;gt;spark.sql.legacy.setCommandRejectsSparkCoreConfs&amp;lt;/code&amp;gt; controls this check: it defaults to &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;, and setting it to &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt; restores the old behavior.&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;&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PySpark has a method that answers the question directly: &amp;lt;code&amp;gt;spark.conf.isModifiable(key)&amp;lt;/code&amp;gt;, added in PySpark 2.4.0, returns whether a key can be changed in the current session.&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/sql/conf.py |title=python/pyspark/sql/conf.py (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;
The following PySpark code runs against Spark 4.3.0 in classic mode. It reads one runtime and one static SQL configuration, changes the runtime one in two equivalent ways, and checks which keys can be changed.&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 = (SparkSession.builder&lt;br /&gt;
         .appName(&amp;quot;conf-demo&amp;quot;)&lt;br /&gt;
         .config(&amp;quot;spark.sql.shuffle.partitions&amp;quot;, &amp;quot;64&amp;quot;)   # rank 1: code&lt;br /&gt;
         .getOrCreate())&lt;br /&gt;
&lt;br /&gt;
print(spark.conf.get(&amp;quot;spark.sql.shuffle.partitions&amp;quot;))   # &amp;#039;64&amp;#039;&lt;br /&gt;
&lt;br /&gt;
spark.conf.set(&amp;quot;spark.sql.shuffle.partitions&amp;quot;, &amp;quot;32&amp;quot;)    # runtime SQL conf: allowed&lt;br /&gt;
spark.sql(&amp;quot;SET spark.sql.shuffle.partitions=16&amp;quot;)        # same effect in SQL&lt;br /&gt;
&lt;br /&gt;
print(spark.conf.isModifiable(&amp;quot;spark.sql.shuffle.partitions&amp;quot;))  # True&lt;br /&gt;
print(spark.conf.isModifiable(&amp;quot;spark.sql.extensions&amp;quot;))          # False (static)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same changes in Spark SQL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SET spark.sql.shuffle.partitions=16;   -- change for this session&lt;br /&gt;
SET spark.sql.shuffle.partitions;      -- show the current value&lt;br /&gt;
RESET spark.sql.shuffle.partitions;    -- back to the value the session started with&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;SET&amp;lt;/code&amp;gt; command sets, shows or lists SQL configuration properties; &amp;lt;code&amp;gt;SET -v&amp;lt;/code&amp;gt; also prints each property&amp;#039;s meaning.&amp;lt;ref&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-ref-syntax-aux-conf-mgmt-set.html |title=SET (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 do sessions share configuration? ==&lt;br /&gt;
In PySpark, &amp;lt;code&amp;gt;SparkSession.builder.getOrCreate()&amp;lt;/code&amp;gt; returns the existing global default session if there is one, and applies the options given to the builder to that existing session.&amp;lt;ref name=&amp;quot;session&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/sql/session.py |title=python/pyspark/sql/session.py (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; &amp;lt;code&amp;gt;spark.newSession()&amp;lt;/code&amp;gt; returns a session with its own SQL configuration, temporary views and UDFs, sharing the &amp;lt;code&amp;gt;SparkContext&amp;lt;/code&amp;gt; and the table cache.&amp;lt;ref name=&amp;quot;session&amp;quot; /&amp;gt; Runtime SQL configurations are therefore per session, while Spark core properties belong to the whole application.&lt;br /&gt;
&lt;br /&gt;
== How does Spark Connect change this? ==&lt;br /&gt;
A [[Spark Connect]] client gets a session on a remote Spark server and has no access to the static Spark configuration or the &amp;lt;code&amp;gt;SparkContext&amp;lt;/code&amp;gt;; it cannot change settings that affect every client of that server.&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; In practice a Spark Connect client can set runtime SQL configurations for its own session, and cluster-level properties are set where the server is started.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Spark-submit|spark-submit]]&lt;br /&gt;
* [[Spark Connect]]&lt;br /&gt;
* [[Executor]]&lt;br /&gt;
* [[Driver (Apache Spark)]]&lt;br /&gt;
* [[Spark on YARN]]&lt;br /&gt;
* [[Spark on Kubernetes]]&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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:51 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Spark_configuration_precedence</comments>
		</item>
		<item>
			<title>Spark Connect client</title>
			<link>https://openlakehouse.io/w/index.php?title=Spark_Connect_client&amp;diff=181&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Spark_Connect_client&amp;diff=181&amp;oldid=0</guid>
			<description>&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            = Spark Connect client&lt;br /&gt;
| also_known_as   = Thin client, Spark Connect client library&lt;br /&gt;
| field           = Distributed data processing, client-server protocols&lt;br /&gt;
| introduced      = Apache Spark 3.4.0 (Python client)&lt;br /&gt;
| key_parts       = Protocol Buffers plan builder, gRPC channel, Apache Arrow result decoder, &amp;lt;code&amp;gt;sc://&amp;lt;/code&amp;gt; connection string&lt;br /&gt;
| implementations = PySpark (&amp;lt;code&amp;gt;pyspark-client&amp;lt;/code&amp;gt;), Scala (&amp;lt;code&amp;gt;spark-connect-client-jvm&amp;lt;/code&amp;gt;), JDBC driver, Go, Swift, Rust&lt;br /&gt;
| related         = [[Spark Connect]], [[Spark Connect server]], [[Spark Connect plugin]], [[Apache Spark]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the Spark 4.3.0 Spark Connect overview and sql/connect/docs/client-connection-string.md at tag v4.3.0; the GitHub repositories, READMEs, tags and releases of apache/spark-connect-go, apache/spark-connect-swift, apache/spark-connect-rust, GoEddie/spark-connect-dotnet and yaooqinn/spark.js; PyPI, crates.io, Maven Central and the Apache Spark download directory}}&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;&amp;#039;Spark Connect client&amp;#039;&amp;#039;&amp;#039; is a library that lets an application use [[Apache Spark]] remotely through the [[Spark Connect]] protocol: it builds unresolved logical plans as Protocol Buffers messages, sends them to a Spark Connect server over gRPC, and decodes the results, which come back as Apache Arrow record batches.&amp;lt;ref name=&amp;quot;overview&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; A Spark Connect client runs in its own process, separate from the Spark driver, and does not reach into the driver JVM; the PySpark client does not use Py4J.&amp;lt;ref name=&amp;quot;overview&amp;quot; /&amp;gt; The &amp;lt;code&amp;gt;pyspark-client&amp;lt;/code&amp;gt; package leaves Py4J out and depends only on Python libraries such as &amp;lt;code&amp;gt;pyarrow&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;grpcio&amp;lt;/code&amp;gt;, so it needs no local Spark JVM.&amp;lt;ref name=&amp;quot;clientsetup&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/packaging/client/setup.py |title=python/packaging/client/setup.py (tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Because the protocol is language-agnostic, a client can be written in any language with gRPC and Arrow support, and the Scala client (&amp;lt;code&amp;gt;spark-connect-client-jvm&amp;lt;/code&amp;gt;) and the JDBC driver are themselves JVM libraries.&amp;lt;ref name=&amp;quot;overview&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;mvnjdbc&amp;quot; /&amp;gt; The Apache Spark project ships Python and Scala clients and a JDBC driver, and maintains separate Go, Swift and Rust clients; other clients are community projects.&lt;br /&gt;
&lt;br /&gt;
== What does a Spark Connect client do? ==&lt;br /&gt;
A Spark Connect client has three jobs. It turns DataFrame or SQL calls into a protobuf plan, manages a gRPC channel and session with the server, and turns Arrow batches into native values. The Spark documentation describes the protocol as language-agnostic, and the server runs every plan through the normal Spark optimizer and execution engine, so a query from a Go client and the same query from PySpark run the same way on the server.&amp;lt;ref name=&amp;quot;overview&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All official clients address the server with the same connection string format, &amp;lt;code&amp;gt;sc://host:port/;param=value&amp;lt;/code&amp;gt;. The Spark Connect developer guidelines ask new clients to follow this format so that the user experience is the same in every language. The parameters include &amp;lt;code&amp;gt;token&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;use_ssl&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;user_agent&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;session_id&amp;lt;/code&amp;gt; and gRPC keepalive settings, and the default port is 15002.&amp;lt;ref name=&amp;quot;connstr&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/connect/docs/client-connection-string.md |title=Connecting to Spark Connect using Clients (sql/connect/docs/client-connection-string.md, tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;readme&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/connect/README.md |title=sql/connect/README.md (tag v4.3.0) |publisher=Apache Spark on GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Which Spark Connect clients exist? ==&lt;br /&gt;
The following table lists the clients maintained under the Apache Spark project, followed by two community clients. &amp;quot;Latest release&amp;quot; is the newest version found on 23 November 2026, and &amp;quot;stated status&amp;quot; quotes or paraphrases each project&amp;#039;s own description.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Client !! Repository and package !! Language !! Latest release !! Stated status !! Notable gaps&lt;br /&gt;
|-&lt;br /&gt;
| PySpark client&lt;br /&gt;
| [https://github.com/apache/spark apache/spark]; PyPI &amp;lt;code&amp;gt;pyspark-client&amp;lt;/code&amp;gt;&lt;br /&gt;
| Python&lt;br /&gt;
| 4.3.0 (30 October 2026)&amp;lt;ref name=&amp;quot;pypi&amp;quot;&amp;gt;{{Cite web |url=https://pypi.org/project/pyspark-client/ |title=pyspark-client |publisher=Python Package Index |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| Part of each Spark release; supports most PySpark APIs since Spark 3.4&amp;lt;ref name=&amp;quot;overview&amp;quot; /&amp;gt;&lt;br /&gt;
| No &amp;lt;code&amp;gt;SparkContext&amp;lt;/code&amp;gt; or RDD API&amp;lt;ref name=&amp;quot;overview&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Scala client&lt;br /&gt;
| apache/spark; Maven &amp;lt;code&amp;gt;spark-connect-client-jvm_2.13&amp;lt;/code&amp;gt;&lt;br /&gt;
| Scala&lt;br /&gt;
| 4.3.0&amp;lt;ref name=&amp;quot;mvnjvm&amp;quot;&amp;gt;{{Cite web |url=https://repo1.maven.org/maven2/org/apache/spark/spark-connect-client-jvm_2.13/maven-metadata.xml |title=spark-connect-client-jvm_2.13 maven-metadata.xml |publisher=Maven Central |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| Part of each Spark release; supports most Scala APIs since Spark 3.5&amp;lt;ref name=&amp;quot;overview&amp;quot; /&amp;gt;&lt;br /&gt;
| No &amp;lt;code&amp;gt;SparkContext&amp;lt;/code&amp;gt; or RDD API; UDF classes and JARs must be uploaded as artifacts&amp;lt;ref name=&amp;quot;overview&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| JDBC driver&lt;br /&gt;
| apache/spark; Maven &amp;lt;code&amp;gt;spark-connect-client-jdbc_2.13&amp;lt;/code&amp;gt;&lt;br /&gt;
| Java (JDBC)&lt;br /&gt;
| 4.3.0&amp;lt;ref name=&amp;quot;mvnjdbc&amp;quot;&amp;gt;{{Cite web |url=https://repo1.maven.org/maven2/org/apache/spark/spark-connect-client-jdbc_2.13/maven-metadata.xml |title=spark-connect-client-jdbc_2.13 maven-metadata.xml |publisher=Maven Central |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| Added in Spark 4.1.0 (SPARK-53484); Spark 4.3.0 describes it as &amp;quot;more complete&amp;quot;&amp;lt;ref name=&amp;quot;r410&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4.1.0.html |title=Spark Release 4.1.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;r430&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4-3-0.html |title=Spark Release 4.3.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| SQL only; ARRAY, MAP and STRUCT support arrived in 4.3.0 (SPARK-57380)&amp;lt;ref name=&amp;quot;r430&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Go client&lt;br /&gt;
| [https://github.com/apache/spark-connect-go apache/spark-connect-go]&lt;br /&gt;
| Go&lt;br /&gt;
| v0.1.0 (GitHub release, 17 June 2025)&amp;lt;ref name=&amp;quot;gorel&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark-connect-go/releases |title=Releases: apache/spark-connect-go |publisher=GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| &amp;quot;Highly experimental and should not be used in any production setting&amp;quot;; the Spark PMC reserves the right to withdraw it&amp;lt;ref name=&amp;quot;goreadme&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark-connect-go/blob/master/README.md |title=apache/spark-connect-go README |publisher=GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| The &amp;lt;code&amp;gt;spark/sql&amp;lt;/code&amp;gt; package has session, DataFrame, reader, writer, grouping, NA and statistics APIs, but no streaming or UDF API; last commit on &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; in August 2025&amp;lt;ref name=&amp;quot;gocommits&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark-connect-go/commits/master |title=Commits: apache/spark-connect-go (master) |publisher=GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;gotree&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark-connect-go/tree/master/spark/sql |title=apache/spark-connect-go: spark/sql |publisher=GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Swift client&lt;br /&gt;
| [https://github.com/apache/spark-connect-swift apache/spark-connect-swift]&lt;br /&gt;
| Swift&lt;br /&gt;
| 0.8.0 (13 November 2026)&amp;lt;ref name=&amp;quot;swiftrel&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark-connect-swift/releases/tag/0.8.0 |title=Release 0.8.0: apache/spark-connect-swift |publisher=GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| &amp;quot;Still experimental&amp;quot; (0.8.0 release notes); source releases published in the Apache Spark download directory&amp;lt;ref name=&amp;quot;swiftrel&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;dist&amp;quot;&amp;gt;{{Cite web |url=https://downloads.apache.org/spark/ |title=Index of /spark |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| UDFs only by registering existing Java UDF classes on the server, not in Swift; README lists Spark 4.3.0 as the requirement&amp;lt;ref name=&amp;quot;swiftudf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark-connect-swift/blob/0.8.0/Sources/SparkConnect/UDFRegistration.swift |title=UDFRegistration.swift (tag 0.8.0) |publisher=GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;swiftreadme&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark-connect-swift/blob/main/README.md |title=apache/spark-connect-swift README |publisher=GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Rust client&lt;br /&gt;
| [https://github.com/apache/spark-connect-rust apache/spark-connect-rust]; crate &amp;lt;code&amp;gt;apache-spark-connect&amp;lt;/code&amp;gt;, PyPI &amp;lt;code&amp;gt;pyspark-client-rust&amp;lt;/code&amp;gt;&lt;br /&gt;
| Rust, with a Python wrapper&lt;br /&gt;
| 4.3.0 (git tag and packages, 16 November 2026)&amp;lt;ref name=&amp;quot;crate&amp;quot;&amp;gt;{{Cite web |url=https://crates.io/crates/apache-spark-connect |title=apache-spark-connect |publisher=crates.io |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;rustpypi&amp;quot;&amp;gt;{{Cite web |url=https://pypi.org/project/pyspark-client-rust/ |title=pyspark-client-rust |publisher=Python Package Index |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| README claims full public-API parity with PySpark 4.3.0 for the Python wrapper; targets Spark 4.3.0 and later&amp;lt;ref name=&amp;quot;rustreadme&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark-connect-rust/blob/main/README.md |title=apache/spark-connect-rust README |publisher=GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;rustcompat&amp;quot;&amp;gt;{{Cite web |url=https://apache.github.io/spark-connect-rust/compatibility/ |title=Compatibility (Spark Connect Rust Client documentation) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| Native Rust API excludes APIs that need Python itself, such as pandas; UDFs are Rust functions compiled to WebAssembly&amp;lt;ref name=&amp;quot;rustdocs&amp;quot;&amp;gt;{{Cite web |url=https://apache.github.io/spark-connect-rust/ |title=Spark Connect Rust Client documentation |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| .NET client (community)&lt;br /&gt;
| [https://github.com/GoEddie/spark-connect-dotnet GoEddie/spark-connect-dotnet]&lt;br /&gt;
| C# and other .NET languages&lt;br /&gt;
| v4.0.0-build.41 (3 October 2026)&amp;lt;ref name=&amp;quot;dotnet&amp;quot;&amp;gt;{{Cite web |url=https://github.com/GoEddie/spark-connect-dotnet |title=GoEddie/spark-connect-dotnet |publisher=GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| Not an Apache project (MIT license)&amp;lt;ref name=&amp;quot;dotnet&amp;quot; /&amp;gt;&lt;br /&gt;
| README says keeping up with new Spark versions is hard and advises users to be prepared to make their own gRPC calls for functions the library lacks&amp;lt;ref name=&amp;quot;dotnet&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| JavaScript client (community)&lt;br /&gt;
| [https://github.com/yaooqinn/spark.js yaooqinn/spark.js]; npm &amp;lt;code&amp;gt;@yaooqinn/spark.js&amp;lt;/code&amp;gt;&lt;br /&gt;
| TypeScript&lt;br /&gt;
| v0.1.0 (git tag, January 2026)&amp;lt;ref name=&amp;quot;sparkjs&amp;quot;&amp;gt;{{Cite web |url=https://github.com/yaooqinn/spark.js |title=yaooqinn/spark.js |publisher=GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| &amp;quot;Experimental&amp;quot;; APIs may change without notice&amp;lt;ref name=&amp;quot;sparkjs&amp;quot; /&amp;gt;&lt;br /&gt;
| Requires Spark 4.0 or later&amp;lt;ref name=&amp;quot;sparkjs&amp;quot; /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The Apache Spark download directory lists source releases of the Swift client but none of the Go or Rust clients.&amp;lt;ref name=&amp;quot;dist&amp;quot; /&amp;gt; The Rust client replaced an earlier community project, sjrusso8/spark-connect-rs, whose repository is now read-only and points to apache/spark-connect-rust.&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/sjrusso8/spark-connect-rs |title=sjrusso8/spark-connect-rs |publisher=GitHub |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The Rust repository also contains an unpublished, experimental Rust server frontend intended for local, trusted experiments.&amp;lt;ref name=&amp;quot;rustreadme&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How is a client connected to a server? ==&lt;br /&gt;
In PySpark, the &amp;lt;code&amp;gt;pyspark-client&amp;lt;/code&amp;gt; package contains only the Spark Connect client, and &amp;lt;code&amp;gt;SparkSession.builder.remote()&amp;lt;/code&amp;gt; takes the connection string.&amp;lt;ref name=&amp;quot;overview&amp;quot; /&amp;gt; The following example connects over TLS with a bearer token; according to the connection string reference, setting &amp;lt;code&amp;gt;token&amp;lt;/code&amp;gt; also enables TLS.&amp;lt;ref name=&amp;quot;connstr&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# pip install pyspark-client==4.3.0&lt;br /&gt;
from pyspark.sql import SparkSession&lt;br /&gt;
&lt;br /&gt;
spark = (&lt;br /&gt;
    SparkSession.builder&lt;br /&gt;
    .remote(&amp;quot;sc://spark.example.com:443/;use_ssl=true;token=MY_TOKEN;user_agent=etl_app&amp;quot;)&lt;br /&gt;
    .getOrCreate()&lt;br /&gt;
)&lt;br /&gt;
print(spark.version)&lt;br /&gt;
spark.sql(&amp;quot;SELECT 1 AS ok&amp;quot;).show()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same string can be set in the &amp;lt;code&amp;gt;SPARK_REMOTE&amp;lt;/code&amp;gt; environment variable. The Swift README states that its client also reads &amp;lt;code&amp;gt;SPARK_REMOTE&amp;lt;/code&amp;gt;, and the Rust and JavaScript clients take an &amp;lt;code&amp;gt;sc://&amp;lt;/code&amp;gt; address in their builders.&amp;lt;ref name=&amp;quot;overview&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;swiftreadme&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;rustreadme&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;sparkjs&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Spark Connect client vs classic Spark application ==&lt;br /&gt;
A Spark Connect client differs from a classic PySpark or Scala application because it runs outside the driver:&amp;lt;ref name=&amp;quot;overview&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! !! Spark Connect client !! Classic Spark application&lt;br /&gt;
|-&lt;br /&gt;
! Process&lt;br /&gt;
| Separate from the driver; talks to it over gRPC&lt;br /&gt;
| Runs inside the driver process (Py4J bridge for PySpark)&lt;br /&gt;
|-&lt;br /&gt;
! &amp;lt;code&amp;gt;SparkContext&amp;lt;/code&amp;gt; and RDDs&lt;br /&gt;
| Not available&lt;br /&gt;
| Available&lt;br /&gt;
|-&lt;br /&gt;
! Cluster-wide and static configuration&lt;br /&gt;
| Not accessible; session settings only&lt;br /&gt;
| Accessible&lt;br /&gt;
|-&lt;br /&gt;
! Dependencies&lt;br /&gt;
| Client library only; server upgraded independently&lt;br /&gt;
| Shares the driver&amp;#039;s process and dependencies&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Spark Connect]]&lt;br /&gt;
* [[Spark Connect server]]&lt;br /&gt;
* [[Spark Connect plugin]]&lt;br /&gt;
* [[Apache Spark]]&lt;br /&gt;
* [[Spark Declarative Pipelines]]&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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:51 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Spark_Connect_client</comments>
		</item>
		<item>
			<title>Salting</title>
			<link>https://openlakehouse.io/w/index.php?title=Salting&amp;diff=176&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Salting&amp;diff=176&amp;oldid=0</guid>
			<description>&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            = Salting&lt;br /&gt;
| also_known_as   = Key salting, salted join&lt;br /&gt;
| field           = Distributed data processing&lt;br /&gt;
| key_parts       = Random salt column on the skewed side, replicated (exploded) other side, join on key plus salt&lt;br /&gt;
| implementations = Applies to any shuffle-based engine; usually written by hand in [[Apache Spark]]&lt;br /&gt;
| related         = [[Data skew]], [[Shuffle]], [[Adaptive Query Execution]], [[Join strategy hints]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (docs/sql-performance-tuning.md, adaptive/OptimizeSkewedJoin.scala, python/pyspark/sql/functions, docs/rdd-programming-guide.md), SPARK-29544 and the Databricks skew and spill guide}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Salting&amp;#039;&amp;#039;&amp;#039; is a manual technique for [[data skew]] in which a random number, the salt, is added to a hot join or grouping key so that the rows for that key are spread over several tasks instead of one. In [[Apache Spark]] before 3.0 the engine had no automatic skew join handling, so salting was done by hand; since Spark 3.0, [[Adaptive Query Execution]] (AQE) splits most skewed joins automatically, and salting is kept for the cases AQE does not cover.&amp;lt;ref name=&amp;quot;perf&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-performance-tuning.html |title=Performance Tuning (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;spark29544&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-29544 |title=SPARK-29544: Optimize skewed join at runtime with new Adaptive Execution |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How salting works ==&lt;br /&gt;
A [[shuffle]] sends all rows with the same key to the same partition. If one key holds most of the rows, one task does most of the work.&amp;lt;ref name=&amp;quot;shuffle&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/rdd-programming-guide.html#shuffle-operations |title=RDD Programming Guide: Shuffle operations (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The Databricks guide to skew describes the remedy as appending a random bucket suffix to the skewed keys, and, for an aggregation, grouping and aggregating in two stages.&amp;lt;ref name=&amp;quot;dbxskew&amp;quot;&amp;gt;{{Cite web |url=https://docs.databricks.com/aws/en/optimizations/spark-ui-guide/long-spark-stage-page |title=Skew and spill |publisher=Databricks |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; For a join, salting changes the shuffle key from &amp;lt;code&amp;gt;key&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;(key, salt)&amp;lt;/code&amp;gt;, where &amp;lt;code&amp;gt;salt&amp;lt;/code&amp;gt; is an integer from 0 to N - 1:&lt;br /&gt;
&lt;br /&gt;
# On the large, skewed side, add a column with a random salt for each row.&lt;br /&gt;
# On the other side, replicate each row N times, once per salt value (for example with &amp;lt;code&amp;gt;explode&amp;lt;/code&amp;gt; over a sequence, which returns one row per array element).&amp;lt;ref name=&amp;quot;pyfuncs&amp;quot; /&amp;gt;&lt;br /&gt;
# Join on both the original key and the salt.&lt;br /&gt;
&lt;br /&gt;
Each hot key is now split across N shuffle partitions. Because each salted row carries exactly one salt value and the other side has a copy for every value, each salted row still meets every matching row from the other side exactly once. The cost is that the other side grows N times, so N is kept as small as the skew allows.&lt;br /&gt;
&lt;br /&gt;
The result is unchanged only when no row of the replicated side has to appear on its own. That holds for an inner join, a left outer join that preserves the salted side, and a left semi or left anti join with the salted side on the left. It does not hold when the join must keep unmatched rows of the replicated side, as a right outer join that preserves the replicated side or a full outer join does: an unmatched replicated row then appears once per salt value, N times instead of once.&lt;br /&gt;
&lt;br /&gt;
== Example in PySpark ==&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;
N = 8  # number of salt values&lt;br /&gt;
&lt;br /&gt;
orders_salted = orders.withColumn(&amp;quot;salt&amp;quot;, (F.rand() * N).cast(&amp;quot;int&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
customers_salted = customers.withColumn(&lt;br /&gt;
    &amp;quot;salt&amp;quot;, F.explode(F.sequence(F.lit(0), F.lit(N - 1)))&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
joined = orders_salted.join(customers_salted, [&amp;quot;customer_id&amp;quot;, &amp;quot;salt&amp;quot;]).drop(&amp;quot;salt&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;rand()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;sequence()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;explode()&amp;lt;/code&amp;gt; are built-in functions of &amp;lt;code&amp;gt;pyspark.sql.functions&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;pyfuncs&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/api/python/reference/pyspark.sql/functions.html |title=Functions (PySpark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; A variant salts only the known hot keys and leaves other keys unsalted, which keeps the replicated side small.&lt;br /&gt;
&lt;br /&gt;
=== Salting a full outer join ===&lt;br /&gt;
A full outer join can be rebuilt from parts that salt correctly: a salted left outer join that keeps every row of the skewed side, plus the rows of the other side that have no match, found with an unsalted left anti join against the distinct keys of the skewed side.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
matched_or_left = orders_salted.join(customers_salted, [&amp;quot;customer_id&amp;quot;, &amp;quot;salt&amp;quot;], &amp;quot;left&amp;quot;).drop(&amp;quot;salt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
order_keys = orders.select(&amp;quot;customer_id&amp;quot;).distinct()&lt;br /&gt;
right_only = customers.join(order_keys, &amp;quot;customer_id&amp;quot;, &amp;quot;left_anti&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
full = matched_or_left.unionByName(right_only, allowMissingColumns=True)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Salting an aggregation ===&lt;br /&gt;
For a skewed &amp;lt;code&amp;gt;GROUP BY&amp;lt;/code&amp;gt;, salting runs the aggregation in two steps: first group by &amp;lt;code&amp;gt;(key, salt)&amp;lt;/code&amp;gt;, then group the partial results by &amp;lt;code&amp;gt;key&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;dbxskew&amp;quot; /&amp;gt; This works for aggregates that can be combined, such as &amp;lt;code&amp;gt;sum&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;count&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;min&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;max&amp;lt;/code&amp;gt;; an average is computed from a salted sum and a salted count.&lt;br /&gt;
&lt;br /&gt;
== When does AQE make salting unnecessary? ==&lt;br /&gt;
AQE skew join handling, added in Spark 3.0.0 and on by default whenever AQE is on (the default since Spark 3.2.0), detects a skewed shuffle partition at runtime and splits it into smaller tasks, replicating the matching partition of the other side. That is the same idea as salting, done by the engine and only for the partitions that need it.&amp;lt;ref name=&amp;quot;perf&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;spark29544&amp;quot; /&amp;gt; A partition counts as skewed when it is over 5 times the median size and over 256 MB, by default.&amp;lt;ref name=&amp;quot;perf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For an inner join, a left or right outer join on the side that can be split, or a semi or anti join, AQE usually makes salting unnecessary.&amp;lt;ref name=&amp;quot;rule&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/OptimizeSkewedJoin.scala |title=OptimizeSkewedJoin.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Salting is still used when:&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;The join type cannot be split.&amp;#039;&amp;#039;&amp;#039; In Spark 4.3.0, AQE splits the left side only for inner, cross, left semi, left anti and left outer joins, and the right side only for inner, cross and right outer joins. A full outer join, or a left outer join whose right side is skewed, is not split.&amp;lt;ref name=&amp;quot;rule&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;The skew is in an aggregation or window.&amp;#039;&amp;#039;&amp;#039; The AQE skew rule targets sort-merge and shuffled hash joins, not aggregations.&amp;lt;ref name=&amp;quot;rule&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;AQE is off&amp;#039;&amp;#039;&amp;#039; (&amp;lt;code&amp;gt;spark.sql.adaptive.enabled=false&amp;lt;/code&amp;gt;) or skew join handling is off (&amp;lt;code&amp;gt;spark.sql.adaptive.skewJoin.enabled=false&amp;lt;/code&amp;gt;).&amp;lt;ref name=&amp;quot;perf&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;The skew is below the thresholds&amp;#039;&amp;#039;&amp;#039; but still slows the stage. Lowering &amp;lt;code&amp;gt;spark.sql.adaptive.skewJoin.skewedPartitionThresholdInBytes&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;skewedPartitionFactor&amp;lt;/code&amp;gt; is often simpler than salting in that case.&amp;lt;ref name=&amp;quot;perf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Salting compared with other skew remedies ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Remedy !! Who does it !! Cost !! Join types&lt;br /&gt;
|-&lt;br /&gt;
| AQE skew join (Spark)&lt;br /&gt;
| The engine, at runtime&lt;br /&gt;
| Replicates only the matching partition of the other side&lt;br /&gt;
| Splittable sides only (see above)&amp;lt;ref name=&amp;quot;rule&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| [[Broadcast join]]&lt;br /&gt;
| The planner, or a &amp;lt;code&amp;gt;BROADCAST&amp;lt;/code&amp;gt; hint&lt;br /&gt;
| The small side is copied to every executor&amp;lt;ref name=&amp;quot;perf&amp;quot; /&amp;gt;&lt;br /&gt;
| Most join types; which side can be broadcast depends on the join type&lt;br /&gt;
|-&lt;br /&gt;
| Salting&lt;br /&gt;
| The user, in the query&lt;br /&gt;
| Replicates the whole other side N times&lt;br /&gt;
| Inner joins; left outer, left semi and left anti joins with the salted side on the left; full outer joins only when rebuilt as above; also aggregations&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Data skew]]&lt;br /&gt;
* [[Shuffle]]&lt;br /&gt;
* [[Adaptive Query Execution]]&lt;br /&gt;
* [[Join strategy hints]]&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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:50 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Salting</comments>
		</item>
		<item>
			<title>Session window</title>
			<link>https://openlakehouse.io/w/index.php?title=Session_window&amp;diff=177&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Session_window&amp;diff=177&amp;oldid=0</guid>
			<description>&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            = Session window&lt;br /&gt;
| also_known_as   = Gap-based window, sessionization&lt;br /&gt;
| field           = [[Stream processing]]&lt;br /&gt;
| introduced      = Spark 3.2.0 (&amp;lt;code&amp;gt;session_window&amp;lt;/code&amp;gt;)&lt;br /&gt;
| key_parts       = Grouping key, event-time column, gap duration (static or per record), [[watermark]]&lt;br /&gt;
| implementations = [[Structured Streaming]] (&amp;lt;code&amp;gt;session_window&amp;lt;/code&amp;gt;), [[Apache Flink]] (session window assigners, &amp;lt;code&amp;gt;SESSION&amp;lt;/code&amp;gt; TVF), Kafka Streams (&amp;lt;code&amp;gt;SessionWindows&amp;lt;/code&amp;gt;)&lt;br /&gt;
| related         = [[Windowing (stream processing)]], [[Stateful stream processing]], [[transformWithState]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the Spark 4.3.0 Structured Streaming programming guide and Real-time Mode guide, &amp;lt;code&amp;gt;python/pyspark/sql/functions/builtin.py&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;SQLConf.scala&amp;lt;/code&amp;gt; at tag v4.3.0 of apache/spark, SPARK-10816, the Apache Flink 2.3 DataStream &amp;quot;Windows&amp;quot; and SQL &amp;quot;Windowing TVF&amp;quot; pages, and the Kafka Streams 4.4 DSL developer guide}}&lt;br /&gt;
&lt;br /&gt;
In [[stream processing]], a &amp;#039;&amp;#039;&amp;#039;session window&amp;#039;&amp;#039;&amp;#039; is a window whose length is set by the data: it opens with a record for a key, extends each time another record for that key arrives within a &amp;#039;&amp;#039;&amp;#039;gap duration&amp;#039;&amp;#039;&amp;#039;, and closes when no record arrives for the length of the gap. Session windows group bursts of activity, such as one user&amp;#039;s clicks during a visit, without fixing the window size in advance. In [[Apache Spark]] [[Structured Streaming]], session windows are built with the &amp;lt;code&amp;gt;session_window&amp;lt;/code&amp;gt; function, added in Spark 3.2.0.&amp;lt;ref name=&amp;quot;builtin&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/sql/functions/builtin.py |title=python/pyspark/sql/functions/builtin.py (Apache Spark v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;jira&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-10816 |title=SPARK-10816: EventTime based sessionization (session window) |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How is a session window different from a tumbling or sliding window? ==&lt;br /&gt;
Tumbling and sliding windows have a fixed size and fixed boundaries, so the engine can compute a record&amp;#039;s window from its timestamp alone. A session window has neither: its start is the first record of the session and its end moves later with every new record. Spark&amp;#039;s guide describes it as having a dynamic size that depends on the inputs.&amp;lt;ref name=&amp;quot;ss-types&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#types-of-time-windows |title=Structured Streaming: Types of time windows (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; See [[Windowing (stream processing)]] for the other window types.&lt;br /&gt;
&lt;br /&gt;
Because a later record can join two earlier sessions into one, engines implement session windows by merging. [[Apache Flink]]&amp;#039;s documentation states that its session window operator creates a new window for every record and merges windows that are closer to each other than the gap.&amp;lt;ref name=&amp;quot;flink-win&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-release-2.3/docs/dev/datastream/operators/windows/#session-windows |title=Windows: Session Windows (Apache Flink 2.3) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does session_window work in Spark? ==&lt;br /&gt;
&amp;lt;code&amp;gt;session_window(timeColumn, gapDuration)&amp;lt;/code&amp;gt; returns a struct column named &amp;lt;code&amp;gt;session_window&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;start&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;end&amp;lt;/code&amp;gt; fields. The end of a session is the timestamp of its latest record plus the gap, so it grows as records join the session.&amp;lt;ref name=&amp;quot;builtin&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The gap can be a static string such as &amp;lt;code&amp;gt;&amp;quot;5 minutes&amp;quot;&amp;lt;/code&amp;gt; or a column expression evaluated per row, for example a different gap per user type. With a dynamic gap, a session&amp;#039;s range is the union of the ranges of its events (each event&amp;#039;s time plus its own gap), and rows whose gap evaluates to zero or a negative value are filtered out of the aggregation.&amp;lt;ref name=&amp;quot;ss-types&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;builtin&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A streaming session window query has these restrictions in Spark 4.3.0:&amp;lt;ref name=&amp;quot;ss-types&amp;quot; /&amp;gt;&lt;br /&gt;
* Update [[output mode]] is not supported; use append (sessions are emitted when the [[watermark]] passes their end) or complete.&lt;br /&gt;
* The grouping key must contain at least one column besides &amp;lt;code&amp;gt;session_window&amp;lt;/code&amp;gt;. A global session window, with &amp;lt;code&amp;gt;session_window&amp;lt;/code&amp;gt; as the only key, is allowed only in batch queries.&lt;br /&gt;
&lt;br /&gt;
By default Spark does not pre-aggregate sessions before the shuffle, because doing so needs an extra local sort. Setting &amp;lt;code&amp;gt;spark.sql.streaming.sessionWindow.merge.sessions.in.local.partition&amp;lt;/code&amp;gt; (default &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt;, since 3.2.0) to &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; sorts and merges sessions within each partition first, which helps when many rows of a batch belong to the same session.&amp;lt;ref name=&amp;quot;ss-types&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;sqlconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala |title=SQLConf.scala (Apache Spark v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Session-window aggregation is not supported in Real-time Mode as of Spark 4.3.0.&amp;lt;ref name=&amp;quot;rtm&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/real-time-mode.html |title=Real-time Mode (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Sessions with custom rules, such as closing a session on a logout event, need arbitrary stateful processing with [[transformWithState]].&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
This PySpark query counts page views per user session, where a session ends after 30 minutes without activity, and uses a shorter gap for one class of users:&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;
views = spark.readStream.table(&amp;quot;main.web.page_views&amp;quot;)   # columns: ts, user_id, user_type&lt;br /&gt;
&lt;br /&gt;
gap = F.when(F.col(&amp;quot;user_type&amp;quot;) == &amp;quot;bot&amp;quot;, &amp;quot;1 minute&amp;quot;).otherwise(&amp;quot;30 minutes&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
sessions = (views&lt;br /&gt;
    .withWatermark(&amp;quot;ts&amp;quot;, &amp;quot;1 hour&amp;quot;)&lt;br /&gt;
    .groupBy(F.session_window(&amp;quot;ts&amp;quot;, gap), &amp;quot;user_id&amp;quot;)&lt;br /&gt;
    .agg(F.count(&amp;quot;*&amp;quot;).alias(&amp;quot;views&amp;quot;)))&lt;br /&gt;
&lt;br /&gt;
(sessions.writeStream&lt;br /&gt;
    .outputMode(&amp;quot;append&amp;quot;)&lt;br /&gt;
    .option(&amp;quot;checkpointLocation&amp;quot;, &amp;quot;/checkpoints/sessions&amp;quot;)&lt;br /&gt;
    .toTable(&amp;quot;main.web.user_sessions&amp;quot;))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Spark SQL the same grouping is &amp;lt;code&amp;gt;GROUP BY session_window(ts, &amp;#039;30 minutes&amp;#039;), user_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Spark session_window compared with Flink ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! !! Spark &amp;lt;code&amp;gt;session_window&amp;lt;/code&amp;gt; !! Flink DataStream session assigners !! Flink SQL &amp;lt;code&amp;gt;SESSION&amp;lt;/code&amp;gt; TVF&lt;br /&gt;
|-&lt;br /&gt;
! Gap&lt;br /&gt;
| Static string or per-row column expression&amp;lt;ref name=&amp;quot;builtin&amp;quot; /&amp;gt;&lt;br /&gt;
| Static gap, or a &amp;lt;code&amp;gt;SessionWindowTimeGapExtractor&amp;lt;/code&amp;gt; for dynamic gaps&amp;lt;ref name=&amp;quot;flink-win&amp;quot; /&amp;gt;&lt;br /&gt;
| Static gap only&amp;lt;ref name=&amp;quot;flink-tvf&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-release-2.3/docs/sql/reference/queries/window-tvf/ |title=Windowing table-valued functions (Apache Flink 2.3) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Key&lt;br /&gt;
| At least one grouping column besides the window in streaming&amp;lt;ref name=&amp;quot;ss-types&amp;quot; /&amp;gt;&lt;br /&gt;
| Keyed (&amp;lt;code&amp;gt;keyBy&amp;lt;/code&amp;gt;) or non-keyed streams&amp;lt;ref name=&amp;quot;flink-win&amp;quot; /&amp;gt;&lt;br /&gt;
| Optional &amp;lt;code&amp;gt;PARTITION BY&amp;lt;/code&amp;gt; key columns&amp;lt;ref name=&amp;quot;flink-tvf&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Time&lt;br /&gt;
| Event time; processing time by windowing on &amp;lt;code&amp;gt;current_timestamp&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;builtin&amp;quot; /&amp;gt;&lt;br /&gt;
| Event-time and processing-time variants&amp;lt;ref name=&amp;quot;flink-win&amp;quot; /&amp;gt;&lt;br /&gt;
| Event or processing time attribute&amp;lt;ref name=&amp;quot;flink-tvf&amp;quot; /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The two engines differ in batch support and in late data. Spark runs &amp;lt;code&amp;gt;session_window&amp;lt;/code&amp;gt; in batch queries too, including a global session window, while Flink&amp;#039;s &amp;lt;code&amp;gt;SESSION&amp;lt;/code&amp;gt; TVF is not supported in batch mode.&amp;lt;ref name=&amp;quot;ss-types&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;flink-tvf&amp;quot; /&amp;gt; In Spark, a record that arrives after the watermark has passed its session&amp;#039;s end is not added to the session; Flink&amp;#039;s DataStream session windows drop such records by default, and &amp;lt;code&amp;gt;allowedLateness&amp;lt;/code&amp;gt; keeps windows open longer.&amp;lt;ref name=&amp;quot;ss-types&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;flink-win&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Kafka Streams also has session windows: sessions are periods of activity separated by an inactivity gap, and the process is called sessionization.&amp;lt;ref name=&amp;quot;kstreams&amp;quot;&amp;gt;{{Cite web |url=https://kafka.apache.org/44/streams/developer-guide/dsl-api/ |title=Kafka Streams DSL (Apache Kafka 4.4) |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;
* [[Windowing (stream processing)]]&lt;br /&gt;
* [[Watermark]]&lt;br /&gt;
* [[Output mode]]&lt;br /&gt;
* [[transformWithState]]&lt;br /&gt;
* [[Structured Streaming]]&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:Pipelines and orchestration]]&lt;br /&gt;
[[Category:Apache Spark]]&lt;/div&gt;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:50 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Session_window</comments>
		</item>
		<item>
			<title>Shuffle hash join</title>
			<link>https://openlakehouse.io/w/index.php?title=Shuffle_hash_join&amp;diff=178&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Shuffle_hash_join&amp;diff=178&amp;oldid=0</guid>
			<description>&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            = Shuffle hash join&lt;br /&gt;
| also_known_as   = Shuffled hash join, SHJ, &amp;lt;code&amp;gt;ShuffledHashJoin&amp;lt;/code&amp;gt;&lt;br /&gt;
| field           = Distributed query processing&lt;br /&gt;
| key_parts       = Shuffle exchange, build side, stream side, per-partition hash table&lt;br /&gt;
| implementations = [[Apache Spark]]&lt;br /&gt;
| related         = [[Sort-merge join]], [[Broadcast join]], [[Shuffle]], [[Adaptive Query Execution]], [[Cost-based optimizer (Spark)]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (SparkStrategies.scala, joins.scala, ShuffledHashJoinExec.scala, SQLConf.scala, sql-performance-tuning.md and sql-ref-syntax-qry-select-hints.md)}}&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;&amp;#039;shuffle hash join&amp;#039;&amp;#039;&amp;#039; is a distributed equality-join strategy that repartitions both inputs by the join keys, then builds a hash table from one input partition inside each join task.&amp;lt;ref name=&amp;quot;shjexec&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/joins/ShuffledHashJoinExec.scala |title=ShuffledHashJoinExec.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; In [[Apache Spark]], the physical operator is named &amp;lt;code&amp;gt;ShuffledHashJoin&amp;lt;/code&amp;gt;. Shuffle hash join avoids sorting both inputs, but it uses more task memory than a [[sort-merge join]] because every task constructs a hash table from its build-side partition.&amp;lt;ref name=&amp;quot;strategies&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/SparkStrategies.scala |title=SparkStrategies.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does a shuffle hash join work? ==&lt;br /&gt;
A Spark shuffle hash join has three steps:&amp;lt;ref name=&amp;quot;shjexec&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;Shuffle both inputs.&amp;#039;&amp;#039;&amp;#039; Spark uses compatible hash partitioning so equal join keys from both sides reach the same partition number.&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;Build a local hash table.&amp;#039;&amp;#039;&amp;#039; In every join task, Spark reads the selected &amp;#039;&amp;#039;&amp;#039;build-side&amp;#039;&amp;#039;&amp;#039; partition and creates a &amp;lt;code&amp;gt;HashedRelation&amp;lt;/code&amp;gt; keyed by the join columns.&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;Probe the table.&amp;#039;&amp;#039;&amp;#039; The task streams rows from the other partition, called the &amp;#039;&amp;#039;&amp;#039;stream side&amp;#039;&amp;#039;&amp;#039;, and looks each key up in the local hash table.&lt;br /&gt;
&lt;br /&gt;
Unlike a [[broadcast join]], shuffle hash join does not collect the complete build side at the [[Driver (Apache Spark)|driver]] or send a full copy to every executor. Each task receives only its build partition. Unlike sort-merge join, shuffle hash join does not require the two shuffled partitions to be sorted before they are joined.&lt;br /&gt;
&lt;br /&gt;
== What does ShuffledHashJoin mean in EXPLAIN? ==&lt;br /&gt;
A representative plan forced with a &amp;lt;code&amp;gt;SHUFFLE_HASH&amp;lt;/code&amp;gt; hint has this shape:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
*(3) ShuffledHashJoin [customer_id#1L], [customer_id#8L], Inner, BuildRight&lt;br /&gt;
:- Exchange hashpartitioning(customer_id#1L, 200), ENSURE_REQUIREMENTS&lt;br /&gt;
:  +- Scan parquet orders&lt;br /&gt;
+- Exchange hashpartitioning(customer_id#8L, 200), ENSURE_REQUIREMENTS&lt;br /&gt;
   +- Scan parquet customers&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The two &amp;lt;code&amp;gt;Exchange hashpartitioning&amp;lt;/code&amp;gt; nodes show that both sides shuffle. &amp;lt;code&amp;gt;BuildRight&amp;lt;/code&amp;gt; means each task builds its hash table from the right input partition and streams the left input partition through it. The absence of &amp;lt;code&amp;gt;Sort&amp;lt;/code&amp;gt; operators is the main visual difference from a &amp;lt;code&amp;gt;SortMergeJoin&amp;lt;/code&amp;gt; plan.&lt;br /&gt;
&lt;br /&gt;
== When does Spark pick shuffle hash join automatically? ==&lt;br /&gt;
Without a hint, Spark 4.3.0 considers shuffle hash join after broadcast hash join. The non-adaptive planner chooses it only when all of these conditions hold:&amp;lt;ref name=&amp;quot;joins&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/joins.scala |title=joins.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;strategies&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;spark.sql.join.preferSortMergeJoin&amp;lt;/code&amp;gt; is &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt;; it defaults to &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala |title=SQLConf.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* One input is estimated small enough to build a local hash map. Spark tests its total estimated bytes against the automatic broadcast threshold multiplied by the number of shuffle partitions.&lt;br /&gt;
* That input is estimated to be much smaller than the other. Spark multiplies the candidate build-side size by &amp;lt;code&amp;gt;spark.sql.shuffledHashJoinFactor&amp;lt;/code&amp;gt; and requires the result to be no larger than the other side.&lt;br /&gt;
* The equality-key data types support Spark&amp;#039;s binary hash equality, and the join type permits the selected build side.&lt;br /&gt;
&lt;br /&gt;
Because the default prefers sort-merge join, a static plan commonly uses &amp;lt;code&amp;gt;SortMergeJoin&amp;lt;/code&amp;gt; for two non-broadcast inputs even when one is smaller. This preference reflects the planner&amp;#039;s source comment that sort-merge join consumes less memory, while shuffled hash join can improve performance when one input is much smaller.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does AQE choose shuffle hash join? ==&lt;br /&gt;
[[Adaptive Query Execution]] can replace a planned sort-merge join after shuffle statistics reveal that every build-side partition is small enough for a local hash table. The threshold is &amp;lt;code&amp;gt;spark.sql.adaptive.maxShuffledHashJoinLocalMapThreshold&amp;lt;/code&amp;gt;, which defaults to 0 bytes. For this preference to apply, the threshold must be at least &amp;lt;code&amp;gt;spark.sql.adaptive.advisoryPartitionSizeInBytes&amp;lt;/code&amp;gt;, and every relevant partition must be no larger than the threshold.&amp;lt;ref name=&amp;quot;perf&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-performance-tuning.html |title=Performance Tuning (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spark 4.3.0 also has &amp;lt;code&amp;gt;spark.sql.adaptive.convertSortMergeJoinToShuffledHashJoin.enabled&amp;lt;/code&amp;gt;, on by default, as the master switch for this conversion.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt; The zero-byte local-map threshold means that setting a useful positive threshold is still necessary before ordinary nonempty partitions qualify through this AQE rule.&lt;br /&gt;
&lt;br /&gt;
== How can a query request shuffle hash join? ==&lt;br /&gt;
The &amp;lt;code&amp;gt;SHUFFLE_HASH&amp;lt;/code&amp;gt; hint requests the strategy and identifies the preferred build relation:&amp;lt;ref name=&amp;quot;hints&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-ref-syntax-qry-select-hints.html |title=Hints (Spark 4.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;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT /*+ SHUFFLE_HASH(customers) */&lt;br /&gt;
       orders.order_id, customers.region&lt;br /&gt;
FROM orders&lt;br /&gt;
JOIN customers&lt;br /&gt;
  ON orders.customer_id = customers.customer_id;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If both relations carry &amp;lt;code&amp;gt;SHUFFLE_HASH&amp;lt;/code&amp;gt; hints, Spark chooses the build side from the join type and relation statistics. A hint is not a guarantee: Spark cannot use the strategy when the join has no equality keys or the requested build side is invalid for that join type.&amp;lt;ref name=&amp;quot;hints&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;strategies&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What are the tradeoffs? ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! !! Shuffle hash join !! Sort-merge join !! Broadcast hash join&lt;br /&gt;
|-&lt;br /&gt;
! Network work&lt;br /&gt;
| Shuffles both inputs&lt;br /&gt;
| Shuffles both inputs&lt;br /&gt;
| Broadcasts one complete input; normally leaves the streamed input in place&lt;br /&gt;
|-&lt;br /&gt;
! CPU work after shuffle&lt;br /&gt;
| Builds and probes a hash table; no key sort&lt;br /&gt;
| Sorts both inputs and merges ordered streams&lt;br /&gt;
| Probes a hash table already distributed to each executor&lt;br /&gt;
|-&lt;br /&gt;
! Memory scope&lt;br /&gt;
| One build partition per concurrent task&lt;br /&gt;
| Primarily sort and match buffers, which can spill&lt;br /&gt;
| The complete built relation on the driver and a copy available to executors&lt;br /&gt;
|-&lt;br /&gt;
! Best fit&lt;br /&gt;
| Build partitions are reliably much smaller than stream partitions and fit in task memory&lt;br /&gt;
| Both sides are large or build-side memory is uncertain&lt;br /&gt;
| One complete side is small enough to broadcast&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Shuffle hash join can outperform sort-merge join by avoiding sorts, especially when the build side is much smaller. It can also fail or slow sharply when a build partition is larger than estimated: constructing &amp;lt;code&amp;gt;HashedRelation&amp;lt;/code&amp;gt; is memory-intensive, and skew can concentrate many build rows in one task.&amp;lt;ref name=&amp;quot;strategies&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;shjexec&amp;quot; /&amp;gt; Increasing task concurrency can multiply this pressure because several tasks may build hash tables in the same executor at once.&lt;br /&gt;
&lt;br /&gt;
AQE can reduce the risk when runtime partition sizes are available, but AQE cannot make a single oversized or highly skewed build partition cheap merely by changing the operator. Splitting skewed partitions, filtering earlier, improving statistics, or using sort-merge join may be safer when build-side memory is uncertain.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Apache Spark]]&lt;br /&gt;
* [[Sort-merge join]]&lt;br /&gt;
* [[Broadcast join]]&lt;br /&gt;
* [[Adaptive Query Execution]]&lt;br /&gt;
* [[Shuffle]]&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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:50 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Shuffle_hash_join</comments>
		</item>
		<item>
			<title>Remote shuffle service</title>
			<link>https://openlakehouse.io/w/index.php?title=Remote_shuffle_service&amp;diff=172&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Remote_shuffle_service&amp;diff=172&amp;oldid=0</guid>
			<description>&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            = Remote shuffle service&lt;br /&gt;
| also_known_as   = RSS, disaggregated shuffle&lt;br /&gt;
| field           = Distributed data processing&lt;br /&gt;
| key_parts       = Shuffle manager plug-in in the engine, a coordinator or master, shuffle servers or workers, local disk or remote storage&lt;br /&gt;
| implementations = [[Apache Celeborn]], [[Apache Uniffle]]&lt;br /&gt;
| related         = [[Shuffle]], [[Executor]], [[External shuffle service]], [[Push-based shuffle]], [[Apache Spark]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (docs/job-scheduling.md, core config package.scala, shuffle/api), Apache Celeborn 0.7.0 (README.md, docs/deploy.md, docs/deploy_on_k8s.md), Apache Uniffle 0.10.0 (README.md, pom.xml), the Celeborn and Uniffle download pages and the Apache Incubator status pages}}&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;&amp;#039;remote shuffle service&amp;#039;&amp;#039;&amp;#039; (RSS) is a cluster of long-running servers that receives, stores and serves the intermediate [[shuffle]] data of distributed jobs, so that the data no longer lives on the local disks of the compute processes that wrote it.&amp;lt;ref name=&amp;quot;celebornreadme&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;uniffereadme&amp;quot; /&amp;gt; In [[Apache Spark]], a remote shuffle service plugs in as a custom shuffle manager: map tasks push their output to shuffle servers over the network, and reduce tasks read it back from those servers.&amp;lt;ref name=&amp;quot;coreconf&amp;quot; /&amp;gt; Two open source implementations at the Apache Software Foundation are [[Apache Celeborn]] and [[Apache Uniffle]].&amp;lt;ref name=&amp;quot;celebornincubator&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;uniffleincubator&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What problem does a remote shuffle service solve? ==&lt;br /&gt;
By default, a Spark executor writes shuffle files to its own local disk and serves them to the next stage; the [[external shuffle service]] moves the serving to a long-running process on the same node, but the files still sit on that node.&amp;lt;ref name=&amp;quot;jobsched&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/job-scheduling.html |title=Job Scheduling (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; When executors are removed, as happens with dynamic allocation or on [[Kubernetes]], the shuffle files must be kept somewhere else or the stages that produced them must run again.&lt;br /&gt;
&lt;br /&gt;
Spark&amp;#039;s documentation lists four ways to let dynamic allocation remove executors without losing shuffle files: the external shuffle service, shuffle tracking, shuffle block migration during decommissioning, or a custom &amp;lt;code&amp;gt;ShuffleDataIO&amp;lt;/code&amp;gt; (set with &amp;lt;code&amp;gt;spark.shuffle.sort.io.plugin.class&amp;lt;/code&amp;gt;) whose driver components support reliable storage.&amp;lt;ref name=&amp;quot;jobsched&amp;quot; /&amp;gt; A remote shuffle service is the fourth kind: shuffle data lives on separate servers, so compute nodes can be added and removed freely. Spark on Kubernetes does not support the built-in external shuffle service.&amp;lt;ref name=&amp;quot;jobsched&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Separating shuffle storage from compute is what both Apache projects name as their goal. Celeborn describes its features as disaggregated computing and storage, push-based shuffle write with merged shuffle read, and high availability.&amp;lt;ref name=&amp;quot;celebornreadme&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/celeborn/blob/v0.7.0/README.md |title=Apache Celeborn README (v0.7.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Uniffle describes itself as changing shuffle from a &amp;quot;local file pull-like style&amp;quot; to a &amp;quot;remote block push-like style&amp;quot;, with disaggregated storage and high elasticity.&amp;lt;ref name=&amp;quot;uniffereadme&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/uniffle/blob/v0.10.0/README.md |title=Apache Uniffle README (v0.10.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does a remote shuffle service plug into Apache Spark? ==&lt;br /&gt;
Spark loads its shuffle implementation from &amp;lt;code&amp;gt;spark.shuffle.manager&amp;lt;/code&amp;gt; (default &amp;lt;code&amp;gt;sort&amp;lt;/code&amp;gt;, since Spark 1.1.0), so a remote shuffle service ships a jar with its own &amp;lt;code&amp;gt;ShuffleManager&amp;lt;/code&amp;gt; class and asks users to point this setting at it.&amp;lt;ref name=&amp;quot;coreconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/internal/config/package.scala |title=config/package.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Since Spark 3.0.0 there is also a narrower shuffle storage API, &amp;lt;code&amp;gt;org.apache.spark.shuffle.api.ShuffleDataIO&amp;lt;/code&amp;gt;, selected by &amp;lt;code&amp;gt;spark.shuffle.sort.io.plugin.class&amp;lt;/code&amp;gt; (default &amp;lt;code&amp;gt;LocalDiskShuffleDataIO&amp;lt;/code&amp;gt;).&amp;lt;ref name=&amp;quot;coreconf&amp;quot; /&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/java/org/apache/spark/shuffle/api/ShuffleDataIO.java |title=ShuffleDataIO.java (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both Celeborn and Uniffle use the two hooks together. The shuffle manager does the data transfer, and the &amp;lt;code&amp;gt;ShuffleDataIO&amp;lt;/code&amp;gt; class tells Spark (3.5 and later) that shuffle data is stored reliably, so dynamic allocation can release executors without the external shuffle service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;properties&amp;quot;&amp;gt;&lt;br /&gt;
# Apache Celeborn 0.7.0 client settings for Spark&lt;br /&gt;
spark.shuffle.manager                 org.apache.spark.shuffle.celeborn.SparkShuffleManager&lt;br /&gt;
spark.serializer                      org.apache.spark.serializer.KryoSerializer&lt;br /&gt;
spark.celeborn.master.endpoints       clb-1:9097,clb-2:9097,clb-3:9097&lt;br /&gt;
spark.shuffle.service.enabled         false&lt;br /&gt;
spark.shuffle.sort.io.plugin.class    org.apache.spark.shuffle.celeborn.CelebornShuffleDataIO&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The settings above come from the Celeborn deployment guide.&amp;lt;ref name=&amp;quot;celebornreadme&amp;quot; /&amp;gt; Uniffle&amp;#039;s equivalents are &amp;lt;code&amp;gt;spark.shuffle.manager=org.apache.spark.shuffle.RssShuffleManager&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spark.rss.coordinator.quorum&amp;lt;/code&amp;gt; for the coordinator addresses, and &amp;lt;code&amp;gt;spark.shuffle.sort.io.plugin.class=org.apache.spark.shuffle.RssShuffleDataIo&amp;lt;/code&amp;gt; on Spark 3.5 or later; for older Spark versions Uniffle ships patches to Spark in its &amp;lt;code&amp;gt;patch/spark&amp;lt;/code&amp;gt; folder.&amp;lt;ref name=&amp;quot;uniffereadme&amp;quot; /&amp;gt; Both projects require a serializer that supports relocation of serialized objects, such as Kryo.&amp;lt;ref name=&amp;quot;celebornreadme&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;uniffereadme&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Remote shuffle service implementations compared ==&lt;br /&gt;
The first column is Spark&amp;#039;s built-in shuffle, shown for reference.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! !! Apache Spark built-in shuffle (with external shuffle service) !! Apache Celeborn !! Apache Uniffle&lt;br /&gt;
|-&lt;br /&gt;
! Where shuffle data lives&lt;br /&gt;
| Local disks of the nodes that ran the map tasks&amp;lt;ref name=&amp;quot;jobsched&amp;quot; /&amp;gt;&lt;br /&gt;
| Celeborn workers, which merge data per reducer and flush to disk; HDFS is a supported storage type&amp;lt;ref name=&amp;quot;celebornreadme&amp;quot; /&amp;gt;&lt;br /&gt;
| Shuffle servers, which buffer data in memory and write to local disk, remote storage such as HDFS, or both&amp;lt;ref name=&amp;quot;uniffereadme&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Components&lt;br /&gt;
| Executors, plus one external shuffle service per node&amp;lt;ref name=&amp;quot;jobsched&amp;quot; /&amp;gt;&lt;br /&gt;
| Master (resource management, state replicated with Raft), Worker, and a LifecycleManager that runs in the Spark driver&amp;lt;ref name=&amp;quot;celebornreadme&amp;quot; /&amp;gt;&lt;br /&gt;
| Coordinator cluster, shuffle server cluster, optional remote storage&amp;lt;ref name=&amp;quot;uniffereadme&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Write and read model&lt;br /&gt;
| Map tasks write sorted files locally; reducers fetch blocks from many nodes&amp;lt;ref name=&amp;quot;jobsched&amp;quot; /&amp;gt;&lt;br /&gt;
| Mappers push data to workers; reducers read merged partition files&amp;lt;ref name=&amp;quot;celebornreadme&amp;quot; /&amp;gt;&lt;br /&gt;
| Tasks push blocks to shuffle servers; readers read from shuffle servers, remote storage or both&amp;lt;ref name=&amp;quot;uniffereadme&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Engines (latest release)&lt;br /&gt;
| Spark only&lt;br /&gt;
| Spark 3.0 to 4.2, Flink 1.18 to 2.3, Hadoop MapReduce 3; Tez client marked experimental&amp;lt;ref name=&amp;quot;celebornreadme&amp;quot; /&amp;gt;&lt;br /&gt;
| Spark 2.3 to 3.5, Hadoop MapReduce, Apache Tez&amp;lt;ref name=&amp;quot;uniffereadme&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Kubernetes&lt;br /&gt;
| External shuffle service not supported on Kubernetes&amp;lt;ref name=&amp;quot;jobsched&amp;quot; /&amp;gt;&lt;br /&gt;
| Helm chart for deployment on Kubernetes&amp;lt;ref name=&amp;quot;celeborndeployk8s&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/celeborn/blob/v0.7.0/docs/deploy_on_k8s.md |title=Deploy Celeborn on Kubernetes (v0.7.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| Kubernetes operator in &amp;lt;code&amp;gt;deploy/kubernetes&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;unifflek8s&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/uniffle/tree/v0.10.0/deploy/kubernetes |title=deploy/kubernetes (Uniffle v0.10.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Origin&lt;br /&gt;
| Part of Apache Spark&lt;br /&gt;
| Started at Alibaba in 2020 as &amp;quot;RemoteShuffleService&amp;quot;, open sourced in 2021&amp;lt;ref name=&amp;quot;celebornproposal&amp;quot;&amp;gt;{{Cite web |url=https://cwiki.apache.org/confluence/display/INCUBATOR/CelebornProposal |title=Celeborn Proposal |publisher=Apache Incubator |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| Started at Tencent in 2020 as &amp;quot;Firestorm&amp;quot;, open sourced in 2021&amp;lt;ref name=&amp;quot;uniffleproposal&amp;quot;&amp;gt;{{Cite web |url=https://cwiki.apache.org/confluence/display/INCUBATOR/UniffleProposal |title=Uniffle Proposal |publisher=Apache Incubator |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! ASF top-level project since&lt;br /&gt;
| (Spark is a top-level project)&lt;br /&gt;
| 2024-03-21&amp;lt;ref name=&amp;quot;celebornincubator&amp;quot;&amp;gt;{{Cite web |url=https://incubator.apache.org/projects/celeborn.html |title=Celeborn Project Incubation Status |publisher=Apache Incubator |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| 2025-02-19&amp;lt;ref name=&amp;quot;uniffleincubator&amp;quot;&amp;gt;{{Cite web |url=https://incubator.apache.org/projects/uniffle.html |title=Uniffle Project Incubation Status |publisher=Apache Incubator |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Latest release (checked 2026-11-23)&lt;br /&gt;
| Spark 4.3.0&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/releases/tag/v4.3.0 |title=Release v4.3.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| 0.7.0, 2026-08-16&amp;lt;ref name=&amp;quot;celeborndl&amp;quot;&amp;gt;{{Cite web |url=https://celeborn.apache.org/download/ |title=Download |publisher=Apache Celeborn |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| 0.10.0, 2025-09-25&amp;lt;ref name=&amp;quot;uniffledl&amp;quot;&amp;gt;{{Cite web |url=https://uniffle.apache.org/download |title=Download |publisher=Apache Uniffle |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Remote shuffle service vs external shuffle service vs push-based shuffle ==&lt;br /&gt;
The three terms are often confused. The &amp;#039;&amp;#039;&amp;#039;[[external shuffle service]]&amp;#039;&amp;#039;&amp;#039; is part of Spark; it serves shuffle files that executors wrote to the node&amp;#039;s local disk, and is off by default (&amp;lt;code&amp;gt;spark.shuffle.service.enabled&amp;lt;/code&amp;gt;).&amp;lt;ref name=&amp;quot;jobsched&amp;quot; /&amp;gt; &amp;#039;&amp;#039;&amp;#039;[[Push-based shuffle]]&amp;#039;&amp;#039;&amp;#039;, added in Spark 3.2.0, has map tasks push blocks to external shuffle services that merge them per partition; it works only on YARN.&amp;lt;ref name=&amp;quot;sparkconfdoc&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; A &amp;#039;&amp;#039;&amp;#039;remote shuffle service&amp;#039;&amp;#039;&amp;#039; is a separate cluster, outside Spark, that stores the shuffle data on its own servers.&lt;br /&gt;
&lt;br /&gt;
== When is a remote shuffle service worth running? ==&lt;br /&gt;
A remote shuffle service is one more distributed system to deploy, size and monitor. Its configuration guidance shows the tradeoffs: Celeborn recommends server-side replication (&amp;lt;code&amp;gt;spark.celeborn.client.push.replicate.enabled=true&amp;lt;/code&amp;gt;) unless there is only one worker or HDFS storage is used, and recommends turning off Spark&amp;#039;s AQE local shuffle reader (&amp;lt;code&amp;gt;spark.sql.adaptive.localShuffleReader.enabled=false&amp;lt;/code&amp;gt;).&amp;lt;ref name=&amp;quot;celebornreadme&amp;quot; /&amp;gt; Teams usually consider one when dynamic allocation on Kubernetes keeps losing shuffle data, or when shuffles are large enough to strain the local disks of compute nodes.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Shuffle]]&lt;br /&gt;
* [[Apache Celeborn]]&lt;br /&gt;
* [[Apache Uniffle]]&lt;br /&gt;
* [[Executor]]&lt;br /&gt;
* [[External shuffle service]]&lt;br /&gt;
* [[Push-based shuffle]]&lt;br /&gt;
* [[Dynamic allocation]]&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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:49 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Remote_shuffle_service</comments>
		</item>
		<item>
			<title>RocksDB state store</title>
			<link>https://openlakehouse.io/w/index.php?title=RocksDB_state_store&amp;diff=173&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=RocksDB_state_store&amp;diff=173&amp;oldid=0</guid>
			<description>&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            = RocksDB state store&lt;br /&gt;
| also_known_as   = &amp;lt;code&amp;gt;RocksDBStateStoreProvider&amp;lt;/code&amp;gt;&lt;br /&gt;
| field           = [[Stream processing]]&lt;br /&gt;
| introduced      = Apache Spark 3.2&lt;br /&gt;
| key_parts       = One RocksDB instance per operator partition, local disk, uploaded SST files and &amp;lt;code&amp;gt;.zip&amp;lt;/code&amp;gt; version files, optional changelog checkpointing, optional bounded memory&lt;br /&gt;
| implementations = [[Structured Streaming]] in [[Apache Spark]]; a separate provider on Databricks&lt;br /&gt;
| related         = [[State store]], [[Streaming checkpoint]], [[transformWithState]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the Spark 4.3.0 Structured Streaming programming guide (RocksDB state store implementation, memory management, changelog checkpointing), &amp;lt;code&amp;gt;SQLConf.scala&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;RocksDB.scala&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;RocksDBFileManager.scala&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pom.xml&amp;lt;/code&amp;gt; at tag v4.3.0 of apache/spark, SPARK-43421, and the Databricks RocksDB state store page}}&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;RocksDB state store&amp;#039;&amp;#039;&amp;#039; is a [[state store]] implementation for [[Apache Spark]] [[Structured Streaming]] that keeps the state of stateful operators in RocksDB, an embedded key-value database, in native memory and on the executor&amp;#039;s local disk, and uploads its files to the [[streaming checkpoint]] for fault tolerance. It was added in Spark 3.2 for queries with large state, such as millions of keys, where the default HDFS-backed state store causes long JVM garbage collection pauses.&amp;lt;ref name=&amp;quot;ss-rocks&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#rocksdb-state-store-implementation |title=Structured Streaming: RocksDB state store implementation (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; It is the only built-in provider that supports [[transformWithState]].&lt;br /&gt;
&lt;br /&gt;
== How is the RocksDB state store enabled? ==&lt;br /&gt;
The provider is chosen with &amp;lt;code&amp;gt;spark.sql.streaming.stateStore.providerClass&amp;lt;/code&amp;gt;. In Apache Spark, set it to &amp;lt;code&amp;gt;org.apache.spark.sql.execution.streaming.state.RocksDBStateStoreProvider&amp;lt;/code&amp;gt; before a query first starts; the provider cannot be changed between restarts from the same checkpoint.&amp;lt;ref name=&amp;quot;ss-rocks&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;sqlconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala |title=SQLConf.scala (Apache Spark 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;
spark.conf.set(&lt;br /&gt;
    &amp;quot;spark.sql.streaming.stateStore.providerClass&amp;quot;,&lt;br /&gt;
    &amp;quot;org.apache.spark.sql.execution.streaming.state.RocksDBStateStoreProvider&amp;quot;,&lt;br /&gt;
)&lt;br /&gt;
spark.conf.set(&lt;br /&gt;
    &amp;quot;spark.sql.streaming.stateStore.rocksdb.changelogCheckpointing.enabled&amp;quot;, &amp;quot;true&amp;quot;&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On Databricks, RocksDB is the default state store provider in Databricks Runtime 17.3 LTS and above. Older runtimes enable it with the provider class &amp;lt;code&amp;gt;com.databricks.sql.streaming.state.RocksDBStateStoreProvider&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;db&amp;quot;&amp;gt;{{Cite web |url=https://docs.databricks.com/aws/en/structured-streaming/rocksdb-state-store |title=Configure RocksDB state store on Databricks |publisher=Databricks |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spark 4.3.0 is built against version 9.8.4 of the &amp;lt;code&amp;gt;rocksdbjni&amp;lt;/code&amp;gt; library.&amp;lt;ref name=&amp;quot;pom&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/pom.xml |title=pom.xml (Apache Spark v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; &amp;lt;code&amp;gt;spark.sql.streaming.stateStore.rocksdb.formatVersion&amp;lt;/code&amp;gt; (default 5) is stored in the checkpoint when a query starts and used for its whole lifetime.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does it checkpoint state? ==&lt;br /&gt;
By default the RocksDB state store uses &amp;#039;&amp;#039;&amp;#039;incremental snapshot checkpointing&amp;#039;&amp;#039;&amp;#039;. At each commit it uploads the RocksDB manifest files and the SST data files that are new since the previous version.&amp;lt;ref name=&amp;quot;ss-cl&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#rocksdb-state-store-changelog-checkpointing |title=Structured Streaming: RocksDB State Store Changelog Checkpointing (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; In the checkpoint, SST and log files get unique names in shared directories, and each version is described by a &amp;lt;code&amp;gt;&amp;#039;&amp;#039;version&amp;#039;&amp;#039;.zip&amp;lt;/code&amp;gt; file with the metadata that maps local file names to the uploaded files. Unlike the HDFS-backed store, which has to replay earlier &amp;lt;code&amp;gt;.delta&amp;lt;/code&amp;gt; files, each &amp;lt;code&amp;gt;.zip&amp;lt;/code&amp;gt; is a complete description of one version.&amp;lt;ref name=&amp;quot;rocksfm&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDBFileManager.scala |title=RocksDBFileManager.scala (Apache Spark v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== What is changelog checkpointing? ===&lt;br /&gt;
With &amp;#039;&amp;#039;&amp;#039;changelog checkpointing&amp;#039;&amp;#039;&amp;#039;, each commit uploads only the changes made to the state since the last checkpoint, in a &amp;lt;code&amp;gt;.changelog&amp;lt;/code&amp;gt; file, instead of a snapshot. Snapshots are still written periodically in the background, to bound recovery time and allow old changelogs to be removed. The Spark guide states that this avoids the cost of capturing and uploading snapshots and reduces streaming query latency.&amp;lt;ref name=&amp;quot;ss-cl&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;rocksfm&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Changelog checkpointing was added in Spark 3.5.0 (SPARK-43421).&amp;lt;ref name=&amp;quot;jira&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-43421 |title=SPARK-43421: Implement changelog checkpointing for RocksDB state store |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; In Apache Spark it is off by default and is turned on with &amp;lt;code&amp;gt;spark.sql.streaming.stateStore.rocksdb.changelogCheckpointing.enabled=true&amp;lt;/code&amp;gt;. It is compatible in both directions with snapshot checkpointing: an existing query can switch to changelog checkpointing, or back, on restart without discarding its state.&amp;lt;ref name=&amp;quot;ss-cl&amp;quot; /&amp;gt; Snapshots are created after &amp;lt;code&amp;gt;spark.sql.streaming.stateStore.minDeltasForSnapshot&amp;lt;/code&amp;gt; (default 10) changelog versions.&amp;lt;ref name=&amp;quot;rocksdbsrc&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDB.scala |title=RocksDB.scala (Apache Spark v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On Databricks, changelog checkpointing is available in Databricks Runtime 13.3 LTS and above and enabled by default in 17.3 LTS and above; Databricks recommends it for all stateful Structured Streaming queries.&amp;lt;ref name=&amp;quot;db&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How is RocksDB memory controlled? ==&lt;br /&gt;
RocksDB allocates memory for memtables (write buffers), the block cache and filter and index blocks. Left unbounded, the instances on one executor can together use enough memory to cause out-of-memory errors.&amp;lt;ref name=&amp;quot;ss-mem&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#rocksdb-state-store-memory-management |title=Structured Streaming: RocksDB State Store Memory Management (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting &amp;lt;code&amp;gt;spark.sql.streaming.stateStore.rocksdb.boundedMemoryUsage=true&amp;lt;/code&amp;gt; caps the total memory of all RocksDB instances on a node at &amp;lt;code&amp;gt;maxMemoryUsageMB&amp;lt;/code&amp;gt; (default 500), through RocksDB&amp;#039;s write buffer manager. The cap is a soft limit: usage can briefly exceed it. Per-instance limits are set with &amp;lt;code&amp;gt;writeBufferSizeMB&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;maxWriteBufferNumber&amp;lt;/code&amp;gt;, which by default use RocksDB&amp;#039;s own defaults.&amp;lt;ref name=&amp;quot;ss-mem&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
All keys start with &amp;lt;code&amp;gt;spark.sql.streaming.stateStore.rocksdb.&amp;lt;/code&amp;gt;. Defaults are those of Spark 4.3.0.&amp;lt;ref name=&amp;quot;ss-rocks&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Key suffix !! Default !! Meaning&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;changelogCheckpointing.enabled&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt; || Upload changelogs instead of snapshots at commit&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;compactOnCommit&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt; || Run a range compaction at each commit&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;blockSizeKB&amp;lt;/code&amp;gt; || 4 || Approximate user data per block in a block-based SST table&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;blockCacheSizeMB&amp;lt;/code&amp;gt; || 8 || Block cache capacity&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;lockAcquireTimeoutMs&amp;lt;/code&amp;gt; || 60000 || Wait for the instance lock when loading&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;maxOpenFiles&amp;lt;/code&amp;gt; || -1 || Open file limit; -1 keeps all files open&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;resetStatsOnLoad&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; || Reset RocksDB statistics on load&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;trackTotalNumberOfRows&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; || Track total rows in state; costs an extra lookup per write&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeBufferSizeMB&amp;lt;/code&amp;gt; || -1 || Maximum memtable size; -1 uses the RocksDB default&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;maxWriteBufferNumber&amp;lt;/code&amp;gt; || -1 || Maximum number of memtables; -1 uses the RocksDB default&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;boundedMemoryUsage&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt; || Bound total RocksDB memory per node&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;maxMemoryUsageMB&amp;lt;/code&amp;gt; || 500 || Total memory limit per node when bounded&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeBufferCacheRatio&amp;lt;/code&amp;gt; || 0.5 || Share of the bound used for write buffers&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;highPriorityPoolRatio&amp;lt;/code&amp;gt; || 0.1 || Share of the bound used for high-priority blocks&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;allowFAllocate&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; || Let RocksDB pre-allocate disk space with fallocate&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;compression&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;lz4&amp;lt;/code&amp;gt; || RocksDB compression type&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Turning off &amp;lt;code&amp;gt;trackTotalNumberOfRows&amp;lt;/code&amp;gt; can improve write performance; the reported number of rows in state is then 0. It can be changed when the query restarts.&amp;lt;ref name=&amp;quot;ss-rocks&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison with Flink&amp;#039;s RocksDB backend ==&lt;br /&gt;
[[Apache Flink]] also has an embedded RocksDB state backend, &amp;lt;code&amp;gt;EmbeddedRocksDBStateBackend&amp;lt;/code&amp;gt;. It stores state as serialized bytes, always takes asynchronous snapshots, and is the only Flink backend that offers incremental checkpoints.&amp;lt;ref name=&amp;quot;flink-sb&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-release-2.3/docs/ops/state/state_backends/ |title=State Backends (Apache Flink 2.3) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Flink&amp;#039;s default is the heap-based &amp;lt;code&amp;gt;HashMapStateBackend&amp;lt;/code&amp;gt;, as Spark&amp;#039;s default is the heap-based HDFS-backed state store.&amp;lt;ref name=&amp;quot;flink-sb&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[State store]]&lt;br /&gt;
* [[Streaming checkpoint]]&lt;br /&gt;
* [[Stateful stream processing]]&lt;br /&gt;
* [[transformWithState]]&lt;br /&gt;
* [[Structured Streaming]]&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;br /&gt;
[[Category:Pipelines and orchestration]]&lt;/div&gt;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:49 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:RocksDB_state_store</comments>
		</item>
		<item>
			<title>Runtime filter</title>
			<link>https://openlakehouse.io/w/index.php?title=Runtime_filter&amp;diff=174&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Runtime_filter&amp;diff=174&amp;oldid=0</guid>
			<description>&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            = Runtime filter&lt;br /&gt;
| also_known_as   = Bloom filter join, dynamic filtering (Trino), runtime filtering (Impala), semi-join reduction&lt;br /&gt;
| field           = Query optimization&lt;br /&gt;
| key_parts       = Creation side (small, filtered join input), application side (large join input), filter structure (bloom filter, value set or min/max range)&lt;br /&gt;
| implementations = [[Apache Spark]] (since 3.3.0), [[Trino]], [[Apache Flink]], Apache Impala&lt;br /&gt;
| related         = [[Dynamic partition pruning]], [[Bloom filter (data files)]], [[Shuffle]], [[Sort-merge join]], [[Predicate pushdown]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (InjectRuntimeFilter.scala, BloomFilterMightContain.scala, FileSourceStrategy.scala, SQLConf.scala), Spark JIRA SPARK-32268 and SPARK-38841, the Trino 484 dynamic filtering page, the Apache Flink 2.3 table configuration page and the Apache Impala runtime filtering page}}&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;&amp;#039;runtime filter&amp;#039;&amp;#039;&amp;#039; is a filter that a query engine builds while a join is running from the join keys of the smaller, filtered input and applies to the larger input before the join, so that rows which cannot find a match are dropped early.&amp;lt;ref name=&amp;quot;rule&amp;quot; /&amp;gt; In [[Apache Spark]], a runtime filter is a bloom filter built from one side of a shuffle join and applied to the other side to reduce the data that goes into the [[shuffle]]; Spark added it in 3.3.0 and has enabled it by default since 3.4.0. Other engines have the same idea under other names, such as dynamic filtering in [[Trino]].&amp;lt;ref name=&amp;quot;trino&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does a runtime filter work? ==&lt;br /&gt;
A runtime filter has two sides. The &amp;#039;&amp;#039;&amp;#039;creation side&amp;#039;&amp;#039;&amp;#039; is the join input with a selective predicate, for example a dimension table filtered to a few rows; the engine reads its join keys and builds a compact filter from them. The &amp;#039;&amp;#039;&amp;#039;application side&amp;#039;&amp;#039;&amp;#039; is the large input; the engine applies the filter to it, ideally at the scan, so that rows whose keys are not in the filter never reach the join.&lt;br /&gt;
&lt;br /&gt;
The filter structure varies. A bloom filter answers &amp;quot;might this key be present?&amp;quot; in a fixed amount of memory; it can return false positives but never false negatives, so it never drops a row that would match.&amp;lt;ref name=&amp;quot;parquetbloom&amp;quot;&amp;gt;{{Cite web |url=https://parquet.apache.org/docs/file-format/bloomfilter/ |title=Bloom Filter |publisher=Apache Parquet |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Other engines also use exact value sets or minimum and maximum ranges.&lt;br /&gt;
&lt;br /&gt;
== How does the runtime filter work in Apache Spark? ==&lt;br /&gt;
Spark&amp;#039;s optimizer rule &amp;lt;code&amp;gt;InjectRuntimeFilter&amp;lt;/code&amp;gt; inserts a runtime filter on one side of a join if it can build one from the other side. The source describes the filter as logically an &amp;lt;code&amp;gt;IN&amp;lt;/code&amp;gt; subquery on the join keys, currently always implemented as a bloom filter.&amp;lt;ref name=&amp;quot;rule&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/InjectRuntimeFilter.scala |title=InjectRuntimeFilter.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The feature came from SPARK-32268, &amp;quot;Bloom Filter Join&amp;quot;, fixed in 3.3.0, and SPARK-38841 enabled it by default in 3.4.0.&amp;lt;ref&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-32268 |title=SPARK-32268: Bloom Filter Join |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-38841 |title=SPARK-38841: Enable Bloom filter join by default |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At Spark 4.3.0, the rule adds a bloom filter on a join key only when:&amp;lt;ref name=&amp;quot;rule&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;sqlconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala |title=SQLConf.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* the join is a shuffle join, or a broadcast join with a shuffle below the side to be filtered;&lt;br /&gt;
* the join keys are simple, cheap expressions;&lt;br /&gt;
* there is no [[dynamic partition pruning]] filter on the same key already;&lt;br /&gt;
* the creation side has a selective predicate, or is a fully materialized, repeatable cached input with evidence that pruning helps;&lt;br /&gt;
* the creation side is small enough: its estimated size must be under &amp;lt;code&amp;gt;spark.sql.optimizer.runtime.bloomFilter.creationSideThreshold&amp;lt;/code&amp;gt; (default 10MB), or, for a fully materialized, repeatable input with accurate statistics, under &amp;lt;code&amp;gt;spark.sql.optimizer.runtime.bloomFilter.materializedCreationSideThreshold&amp;lt;/code&amp;gt; (default 100MB, since 4.3.0), which replaces the general threshold for such inputs;&lt;br /&gt;
* the application side&amp;#039;s scan size is over &amp;lt;code&amp;gt;spark.sql.optimizer.runtime.bloomFilter.applicationSideScanSizeThreshold&amp;lt;/code&amp;gt; (default 10GB);&lt;br /&gt;
* the query has fewer than &amp;lt;code&amp;gt;spark.sql.optimizer.runtimeFilter.number.threshold&amp;lt;/code&amp;gt; (default 10) runtime filters already, a limit that protects the driver from running out of memory.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Setting !! Default !! Since&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.sql.optimizer.runtime.bloomFilter.enabled&amp;lt;/code&amp;gt; || true || 3.3.0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.sql.optimizer.runtime.bloomFilter.creationSideThreshold&amp;lt;/code&amp;gt; || 10MB || 3.3.0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.sql.optimizer.runtime.bloomFilter.materializedCreationSideThreshold&amp;lt;/code&amp;gt; || 100MB || 4.3.0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.sql.optimizer.runtime.bloomFilter.applicationSideScanSizeThreshold&amp;lt;/code&amp;gt; || 10GB || 3.3.0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.sql.optimizer.runtime.bloomFilter.expectedNumItems&amp;lt;/code&amp;gt; || 1000000 || 3.3.0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.sql.optimizer.runtime.bloomFilter.numBits&amp;lt;/code&amp;gt; || 8388608 || 3.3.0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark.sql.optimizer.runtimeFilter.number.threshold&amp;lt;/code&amp;gt; || 10 || 3.3.0&lt;br /&gt;
|}&lt;br /&gt;
All values are from &amp;lt;code&amp;gt;SQLConf.scala&amp;lt;/code&amp;gt; at Spark 4.3.0.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In a Spark plan, an injected runtime filter appears as a &amp;lt;code&amp;gt;might_contain(...)&amp;lt;/code&amp;gt; predicate in a &amp;lt;code&amp;gt;Filter&amp;lt;/code&amp;gt; on the application side, which refers to a scalar subquery that builds the bloom filter.&amp;lt;ref name=&amp;quot;rule&amp;quot; /&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/BloomFilterMightContain.scala |title=BloomFilterMightContain.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Spark does not push the bloom filter into file scans as a data filter; it is evaluated on the rows after the scan.&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/FileSourceStrategy.scala |title=FileSourceStrategy.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Runtime filters in other engines ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! !! Apache Spark !! Trino !! Apache Flink !! Apache Impala&lt;br /&gt;
|-&lt;br /&gt;
! Name&lt;br /&gt;
| Runtime filter (bloom filter join)&amp;lt;ref name=&amp;quot;rule&amp;quot; /&amp;gt;&lt;br /&gt;
| Dynamic filtering&amp;lt;ref name=&amp;quot;trino&amp;quot;&amp;gt;{{Cite web |url=https://trino.io/docs/current/admin/dynamic-filtering.html |title=Dynamic filtering (Trino 484) |publisher=Trino Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| Runtime filter&amp;lt;ref name=&amp;quot;flink&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-stable/docs/dev/table/config/ |title=Configuration (Apache Flink 2.3) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| Runtime filtering&amp;lt;ref name=&amp;quot;impala&amp;quot;&amp;gt;{{Cite web |url=https://impala.apache.org/docs/build/html/topics/impala_runtime_filtering.html |title=Runtime Filtering for Impala Queries |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! On by default?&lt;br /&gt;
| Yes, since 3.4.0&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
| Yes&amp;lt;ref name=&amp;quot;trino&amp;quot; /&amp;gt;&lt;br /&gt;
| No (&amp;lt;code&amp;gt;table.optimizer.runtime-filter.enabled&amp;lt;/code&amp;gt; is false)&amp;lt;ref name=&amp;quot;flink&amp;quot; /&amp;gt;&lt;br /&gt;
| Yes; &amp;lt;code&amp;gt;RUNTIME_FILTER_MODE&amp;lt;/code&amp;gt; defaults to &amp;lt;code&amp;gt;GLOBAL&amp;lt;/code&amp;gt; in Impala 2.6 and higher&amp;lt;ref name=&amp;quot;impala&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Filter structure&lt;br /&gt;
| Bloom filter&lt;br /&gt;
| Distinct value sets; falls back to per-column minimum and maximum when the build side exceeds size thresholds&amp;lt;ref name=&amp;quot;trino&amp;quot; /&amp;gt;&lt;br /&gt;
| Not described on the configuration page&lt;br /&gt;
| Bloom filter for HDFS-based tables; minimum and maximum filter for Kudu tables&amp;lt;ref name=&amp;quot;impala&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Applies to&lt;br /&gt;
| Shuffle joins (and broadcast joins with a shuffle below them)&amp;lt;ref name=&amp;quot;rule&amp;quot; /&amp;gt;&lt;br /&gt;
| Inner and right joins with &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;&amp;amp;lt;&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;&amp;amp;lt;=&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;&amp;amp;gt;&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;&amp;amp;gt;=&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;IS NOT DISTINCT FROM&amp;lt;/code&amp;gt;, and semi-joins with &amp;lt;code&amp;gt;IN&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;trino&amp;quot; /&amp;gt;&lt;br /&gt;
| Batch jobs only&amp;lt;ref name=&amp;quot;flink&amp;quot; /&amp;gt;&lt;br /&gt;
| Joins; available since Impala 2.5&amp;lt;ref name=&amp;quot;impala&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Size limits&lt;br /&gt;
| Creation side under 10MB (100MB for fully materialized inputs with accurate statistics), application side over 10GB by default&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
| Build-side thresholds before falling back to min and max&amp;lt;ref name=&amp;quot;trino&amp;quot; /&amp;gt;&lt;br /&gt;
| Build side under 150 mb, probe side over 10 gb, filter ratio over 0.5 by default&amp;lt;ref name=&amp;quot;flink&amp;quot; /&amp;gt;&lt;br /&gt;
| Controlled by query options&amp;lt;ref name=&amp;quot;impala&amp;quot; /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Runtime filter vs dynamic partition pruning ==&lt;br /&gt;
{{Main|Dynamic partition pruning}}&lt;br /&gt;
Both techniques move information across a join at run time. [[Dynamic partition pruning]] needs a partition column as the join key, and it skips whole partitions before they are read. A runtime filter works on any equi-join key, and it removes rows after the scan and before the shuffle. Spark checks for an existing DPP filter on a key before it injects a bloom filter on the same key.&amp;lt;ref name=&amp;quot;rule&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Runtime filters vs bloom filters in data files ==&lt;br /&gt;
{{Main|Bloom filter (data files)}}&lt;br /&gt;
A runtime filter is built for one query and thrown away. A bloom filter in a data file, such as an [[Apache Parquet]] column bloom filter, is written once with the file and lets readers skip row groups for equality filters with a literal value.&amp;lt;ref name=&amp;quot;parquetbloom&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Dynamic partition pruning]]&lt;br /&gt;
* [[Bloom filter (data files)]]&lt;br /&gt;
* [[Shuffle]]&lt;br /&gt;
* [[Predicate pushdown]]&lt;br /&gt;
* [[Trino]]&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;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:49 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Runtime_filter</comments>
		</item>
		<item>
			<title>Ryan Blue</title>
			<link>https://openlakehouse.io/w/index.php?title=Ryan_Blue&amp;diff=175&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Ryan_Blue&amp;diff=175&amp;oldid=0</guid>
			<description>&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 person&lt;br /&gt;
| name         = Ryan Blue&lt;br /&gt;
| known_for    = [[Apache Iceberg]]&lt;br /&gt;
| role         = Software engineer&lt;br /&gt;
| affiliations = [[Databricks]], [[Apache Software Foundation]]&lt;br /&gt;
| projects     = [[Apache Iceberg]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the Databricks and PR Newswire acquisition announcements, the Databricks Data + AI Summit speaker page and the ASF project leadership list}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ryan Blue&amp;#039;&amp;#039;&amp;#039; is a software engineer known as one of the original creators of [[Apache Iceberg]], an [[open table format]] for large analytic datasets. He developed Iceberg at [[Netflix]] with Daniel Weeks, co-founded the data management company [[Tabular]] around the format, and joined [[Databricks]] when it acquired Tabular in 2024.&amp;lt;ref name=&amp;quot;prnewswire&amp;quot;&amp;gt;{{Cite web |url=https://www.prnewswire.com/news-releases/databricks-agrees-to-acquire-tabular-the-company-founded-by-the-original-creators-of-apache-iceberg-302163561.html |title=Databricks Agrees to Acquire Tabular, the Company Founded by the Original Creators of Apache Iceberg |publisher=PR Newswire |date=2024-06-04 |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;dbxblog&amp;quot;&amp;gt;{{Cite web |url=https://www.databricks.com/blog/databricks-tabular |title=Databricks + Tabular |publisher=Databricks |date=2024-06-04 |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Career and work ==&lt;br /&gt;
Blue worked at Cloudera before joining Netflix, where he was part of the big data platform team.&amp;lt;ref name=&amp;quot;dais&amp;quot;&amp;gt;{{Cite web |url=https://www.databricks.com/dataaisummit/speaker/ryan-blue |title=Ryan Blue |publisher=Databricks |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; At Netflix, Blue and Daniel Weeks developed Apache Iceberg and later donated the project to the [[Apache Software Foundation]].&amp;lt;ref name=&amp;quot;dbxblog&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In 2021, Blue co-founded Tabular with Daniel Weeks and Jason Reid.&amp;lt;ref name=&amp;quot;techcrunch&amp;quot;&amp;gt;{{Cite web |url=https://techcrunch.com/2024/06/04/databricks-acquires-tabular-to-build-a-common-data-lakehouse-standard/ |title=Databricks acquires Tabular to build a common data lakehouse standard |publisher=TechCrunch |date=2024-06-04 |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Tabular built a data management platform around Iceberg, and Blue served as its chief executive officer.&amp;lt;ref name=&amp;quot;prnewswire&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On 4 June 2024, Databricks announced that it had agreed to acquire Tabular.&amp;lt;ref name=&amp;quot;prnewswire&amp;quot; /&amp;gt; Databricks stated that the acquisition completed on 7 June 2024.&amp;lt;ref name=&amp;quot;dbxblog&amp;quot; /&amp;gt; After the acquisition, Blue is listed as a Member of Technical Staff at Databricks.&amp;lt;ref name=&amp;quot;dais&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Contributions to the open lakehouse ==&lt;br /&gt;
Apache Iceberg is the contribution for which Blue is most widely recognized. Iceberg was created at Netflix to address correctness, performance and scalability problems with the earlier [[Apache Hive]] table layout, and was donated to the Apache Software Foundation as an open-source project.&amp;lt;ref name=&amp;quot;prnewswire&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;dbxblog&amp;quot; /&amp;gt; Iceberg lets multiple query engines read and write the same tables on object storage with transactional guarantees, a pattern central to the [[open lakehouse]].&lt;br /&gt;
&lt;br /&gt;
Blue chairs the Apache Iceberg Project Management Committee (PMC).&amp;lt;ref name=&amp;quot;prnewswire&amp;quot; /&amp;gt; The Apache Software Foundation lists him as Vice President, Apache Iceberg, the officer role that corresponds to the PMC chair of a top-level project.&amp;lt;ref name=&amp;quot;asf&amp;quot;&amp;gt;{{Cite web |url=https://apache.org/foundation/leadership |title=ASF Project Leadership |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The 2024 Databricks acquisition was described as bringing together the original creators of Apache Iceberg and the creators of [[Delta Lake]], with a stated goal of improving interoperability between the two open table formats.&amp;lt;ref name=&amp;quot;prnewswire&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;dbxblog&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Selected works ==&lt;br /&gt;
* Apache Iceberg, the open table format Blue co-created at Netflix and contributed to the Apache Software Foundation.&amp;lt;ref name=&amp;quot;prnewswire&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;dbxblog&amp;quot; /&amp;gt;&lt;br /&gt;
* Conference presentations on Apache Iceberg and open table formats, including sessions at the Databricks Data + AI Summit.&amp;lt;ref name=&amp;quot;dais&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Apache Iceberg]]&lt;br /&gt;
* [[Tabular]]&lt;br /&gt;
* [[Delta Lake]]&lt;br /&gt;
* [[Open table format]]&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:People]]&lt;/div&gt;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:49 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Ryan_Blue</comments>
		</item>
		<item>
			<title>Pyspark-client</title>
			<link>https://openlakehouse.io/w/index.php?title=Pyspark-client&amp;diff=168&amp;oldid=0</link>
			<guid isPermaLink="false">https://openlakehouse.io/w/index.php?title=Pyspark-client&amp;diff=168&amp;oldid=0</guid>
			<description>&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;{{DISPLAYTITLE:pyspark-client}}&lt;br /&gt;
{{Infobox software&lt;br /&gt;
| name                = pyspark-client&lt;br /&gt;
| developer           = [[Apache Software Foundation]] ([[Apache Spark]] project)&lt;br /&gt;
| initial_release     = 4.0.0 (2025-05-23)&lt;br /&gt;
| latest_release      = 4.3.0&lt;br /&gt;
| latest_release_date = 2026-10-30&lt;br /&gt;
| written_in          = Python&lt;br /&gt;
| type                = Pure-Python [[Spark Connect]] client library&lt;br /&gt;
| license             = Apache License 2.0&lt;br /&gt;
| website             = [https://pypi.org/project/pyspark-client/ pypi.org/project/pyspark-client]&lt;br /&gt;
| repo                = [https://github.com/apache/spark/tree/v4.3.0/python/packaging/client github.com/apache/spark (python/packaging/client)]&lt;br /&gt;
| related             = [[Spark Connect]], [[Apache Spark]], [[Pandas API on Spark]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the pyspark-client, pyspark and pyspark-connect release histories and metadata on PyPI (latest 4.3.0, uploaded 2026-10-30), python/packaging/client/setup.py and python/packaging/classic/setup.py at tags v4.0.0 and v4.3.0, python/docs/source/getting_started/install.rst at v4.0.0 and v4.3.0, docs/spark-connect-overview.md at v4.3.0, the Spark 4.0.0 release notes and SPARK-47540}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;pyspark-client&amp;#039;&amp;#039;&amp;#039; is the pure-Python [[Spark Connect]] client for [[Apache Spark]], published on PyPI, which lets a Python program use the PySpark DataFrame, SQL and streaming APIs against a remote Spark Connect server without a Java runtime or Spark JAR files on the client machine.&amp;lt;ref name=&amp;quot;install430&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/docs/source/getting_started/install.rst |title=Installation (python/docs/source/getting_started/install.rst at v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The package was first released with Spark 4.0.0, and its version numbers follow Spark releases.&amp;lt;ref name=&amp;quot;pypi&amp;quot;&amp;gt;{{Cite web |url=https://pypi.org/project/pyspark-client/#history |title=pyspark-client release history |publisher=Python Package Index |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; It is installed with &amp;lt;code&amp;gt;pip install pyspark-client&amp;lt;/code&amp;gt; and supports only remote connections through &amp;lt;code&amp;gt;spark.remote&amp;lt;/code&amp;gt; with an &amp;lt;code&amp;gt;sc://&amp;lt;/code&amp;gt; connection URI.&amp;lt;ref name=&amp;quot;install430&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What is pyspark-client? ==&lt;br /&gt;
pyspark-client is a separate distribution of the PySpark source tree that contains only Python code. The Spark installation guide describes it as a pure Python library that does not depend on non-Python components such as JARs or a Java Runtime Environment (JRE).&amp;lt;ref name=&amp;quot;install430&amp;quot; /&amp;gt; The PyPI package name is &amp;lt;code&amp;gt;pyspark-client&amp;lt;/code&amp;gt;; the import name stays &amp;lt;code&amp;gt;pyspark&amp;lt;/code&amp;gt;, so code written for Spark Connect runs unchanged.&amp;lt;ref name=&amp;quot;setup430&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/packaging/client/setup.py |title=python/packaging/client/setup.py (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Spark 4.0.0 release notes list &amp;quot;a new lightweight Python client (pyspark-client) at just 1.5 MB&amp;quot; among the Spark Connect changes of that release.&amp;lt;ref name=&amp;quot;r400&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4-0-0.html |title=Spark Release 4.0.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; On PyPI, the 4.3.0 source distribution of pyspark-client is 1,745,601 bytes, while the 4.3.0 source distribution of the full &amp;lt;code&amp;gt;pyspark&amp;lt;/code&amp;gt; package, which bundles the Spark JARs, is 455,910,862 bytes.&amp;lt;ref name=&amp;quot;pypi&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;pypi-pyspark&amp;quot;&amp;gt;{{Cite web |url=https://pypi.org/project/pyspark/4.3.0/#files |title=pyspark 4.3.0 (files) |publisher=Python Package Index |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How is pyspark-client installed and used? ==&lt;br /&gt;
pyspark-client 4.3.0 requires Python 3.11 or later and installs pandas (2.2.0 or later), PyArrow (18.0.0 or later), grpcio and grpcio-status (1.76.0 or later), googleapis-common-protos, zstandard, NumPy and PyYAML as dependencies.&amp;lt;ref name=&amp;quot;setup430&amp;quot; /&amp;gt; The 4.0.0 release required Python 3.9 or later.&amp;lt;ref name=&amp;quot;setup400&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.0.0/python/packaging/client/setup.py |title=python/packaging/client/setup.py (v4.0.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Spark Connect documentation recommends pinning the client to the Spark release in use, for example &amp;lt;code&amp;gt;pip install pyspark-client==4.3&amp;lt;/code&amp;gt;, and then creating a session with &amp;lt;code&amp;gt;SparkSession.builder.remote()&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;overview&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/docs/spark-connect-overview.md |title=Spark Connect Overview (docs/spark-connect-overview.md at v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The server side is a Spark Connect server, which by default listens on port 15002; see [[Spark Connect]].&amp;lt;ref name=&amp;quot;overview&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# pip install pyspark-client==4.3.0&lt;br /&gt;
from pyspark.sql import SparkSession&lt;br /&gt;
from pyspark.sql import functions as F&lt;br /&gt;
&lt;br /&gt;
spark = SparkSession.builder.remote(&amp;quot;sc://localhost:15002&amp;quot;).getOrCreate()&lt;br /&gt;
&lt;br /&gt;
df = spark.range(10).withColumn(&amp;quot;even&amp;quot;, F.col(&amp;quot;id&amp;quot;) % 2 == 0)&lt;br /&gt;
df.groupBy(&amp;quot;even&amp;quot;).count().show()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What is missing compared with PySpark? ==&lt;br /&gt;
pyspark-client leaves out the parts of PySpark that need a local JVM. Compared with the classic &amp;lt;code&amp;gt;pyspark&amp;lt;/code&amp;gt; package at v4.3.0, its package list omits &amp;lt;code&amp;gt;pyspark.core&amp;lt;/code&amp;gt; (the module that holds &amp;lt;code&amp;gt;SparkContext&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;RDD&amp;lt;/code&amp;gt; and broadcast variables), &amp;lt;code&amp;gt;pyspark.sql.classic&amp;lt;/code&amp;gt; (the Py4J-based DataFrame implementation), and the bundled &amp;lt;code&amp;gt;jars&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;bin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sbin&amp;lt;/code&amp;gt; directories.&amp;lt;ref name=&amp;quot;setup430&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;classic430&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/packaging/classic/setup.py |title=python/packaging/classic/setup.py (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; It also does not depend on Py4J, which the full package requires.&amp;lt;ref name=&amp;quot;setup430&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;pypi-pyspark&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because pyspark-client speaks only the Spark Connect protocol, the general Spark Connect limits apply to it. The Spark documentation lists them: the client cannot reach the driver JVM, so private fields such as &amp;lt;code&amp;gt;df._jdf&amp;lt;/code&amp;gt; do not exist; RDDs are not supported; and the client has no access to &amp;lt;code&amp;gt;SparkContext&amp;lt;/code&amp;gt; or to the static Spark configuration.&amp;lt;ref name=&amp;quot;overview&amp;quot; /&amp;gt; The [[RDD]] API is therefore unavailable, and code that calls &amp;lt;code&amp;gt;spark.sparkContext&amp;lt;/code&amp;gt; must be rewritten with DataFrame APIs.&lt;br /&gt;
&lt;br /&gt;
pyspark-client cannot start Spark by itself. The installation guide says it supports only &amp;lt;code&amp;gt;spark.remote&amp;lt;/code&amp;gt; with connection URIs; it has no local mode, and the user must run a Spark Connect server separately.&amp;lt;ref name=&amp;quot;install430&amp;quot; /&amp;gt; The SPIP that proposed the pure-Python package also excluded full compatibility with classic PySpark (such as the RDD API), launching the server and local mode from its scope.&amp;lt;ref name=&amp;quot;spip&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-47540 |title=SPARK-47540: SPIP: Pure Python Package (Spark Connect) |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Most of the PySpark API is still present. The package includes &amp;lt;code&amp;gt;pyspark.sql&amp;lt;/code&amp;gt; with its Spark Connect implementation, Structured Streaming, &amp;lt;code&amp;gt;pyspark.ml&amp;lt;/code&amp;gt;, the [[Pandas API on Spark]] (&amp;lt;code&amp;gt;pyspark.pandas&amp;lt;/code&amp;gt;) and the &amp;lt;code&amp;gt;pyspark.pipelines&amp;lt;/code&amp;gt; module of [[Spark Declarative Pipelines]].&amp;lt;ref name=&amp;quot;setup430&amp;quot; /&amp;gt; The Spark API reference labels each API that &amp;quot;Supports Spark Connect&amp;quot;.&amp;lt;ref name=&amp;quot;overview&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does pyspark-client differ from pyspark and pyspark-connect? ==&lt;br /&gt;
Spark publishes three Python packages from the same source tree:&amp;lt;ref name=&amp;quot;install430&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;setup430&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;classic430&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! PyPI package !! Contents !! Bundles Spark JARs !! Connection modes&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;pyspark-client&amp;lt;/code&amp;gt; || Python code only; no JARs, no Py4J || No || &amp;lt;code&amp;gt;spark.remote&amp;lt;/code&amp;gt; with an &amp;lt;code&amp;gt;sc://&amp;lt;/code&amp;gt; URI only&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;pyspark&amp;lt;/code&amp;gt; || Full PySpark with the Spark JARs and Py4J; Spark Connect available through the &amp;lt;code&amp;gt;connect&amp;lt;/code&amp;gt; extra || Yes || Classic (Py4J) and Spark Connect&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;pyspark-connect&amp;lt;/code&amp;gt; || A small package that depends on the same version of &amp;lt;code&amp;gt;pyspark&amp;lt;/code&amp;gt; and makes Spark Connect the default || Yes, through its &amp;lt;code&amp;gt;pyspark&amp;lt;/code&amp;gt; dependency || &amp;lt;code&amp;gt;spark.master&amp;lt;/code&amp;gt; with a local Connect server, or &amp;lt;code&amp;gt;spark.remote&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;pyspark-connect&amp;lt;/code&amp;gt; 4.3.0 package on PyPI depends on &amp;lt;code&amp;gt;pyspark==4.3.0&amp;lt;/code&amp;gt;, so it brings in the full JVM-backed distribution; pyspark-client does not.&amp;lt;ref name=&amp;quot;pypi-connect&amp;quot;&amp;gt;{{Cite web |url=https://pypi.org/project/pyspark-connect/4.3.0/ |title=pyspark-connect 4.3.0 |publisher=Python Package Index |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
The pure-Python package was proposed in SPARK-47540, &amp;quot;SPIP: Pure Python Package (Spark Connect)&amp;quot;, filed on 25 March 2024 with fix version 4.0.0.&amp;lt;ref name=&amp;quot;spip&amp;quot; /&amp;gt; The SPIP text used the name &amp;lt;code&amp;gt;pyspark-connect&amp;lt;/code&amp;gt;; in the released code the pure-Python package is named &amp;lt;code&amp;gt;pyspark-client&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;pyspark-connect&amp;lt;/code&amp;gt; became the package that makes Connect the default for full PySpark.&amp;lt;ref name=&amp;quot;spip&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;setup400&amp;quot; /&amp;gt; The Spark 4.0.0 release notes list SPARK-47540 and the 1.5 MB client.&amp;lt;ref name=&amp;quot;r400&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
pyspark-client 4.0.0 was uploaded to PyPI on 23 May 2025, the release date of Spark 4.0.0. Later releases track Spark: 4.1.0 (16 December 2025), 4.2.0 (14 July 2026) and 4.3.0 (30 October 2026), with maintenance releases for older lines, such as 4.2.1, 4.1.4 and 4.0.5 on 27 October 2026.&amp;lt;ref name=&amp;quot;pypi&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Spark Connect]]&lt;br /&gt;
* [[Apache Spark]]&lt;br /&gt;
* [[RDD]]&lt;br /&gt;
* [[Pandas API on Spark]]&lt;br /&gt;
* [[Spark 3 to Spark 4 migration]]&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:Query engines]]&lt;br /&gt;
[[Category:Apache Spark]]&lt;/div&gt;</description>
			<pubDate>Wed, 25 Nov 2026 00:52:48 GMT</pubDate>
			<dc:creator>Open Lakehouse Wiki sync</dc:creator>
			<comments>https://openlakehouse.io/wiki/Talk:Pyspark-client</comments>
		</item>
</channel></rss>