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

		<summary type="html">&lt;p&gt;Sync from open-lakehouse/wiki@7c9abaa&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Infobox concept&lt;br /&gt;
| name            = 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;</summary>
		<author><name>Open Lakehouse Wiki sync</name></author>
	</entry>
</feed>