Skip to content

Commit 3ab48f9

Browse files
MaxGekkgatorsmile
authored andcommitted
[SPARK-24761][SQL] Adding of isModifiable() to RuntimeConfig
## What changes were proposed in this pull request? In the PR, I propose to extend `RuntimeConfig` by new method `isModifiable()` which returns `true` if a config parameter can be modified at runtime (for current session state). For static SQL and core parameters, the method returns `false`. ## How was this patch tested? Added new test to `RuntimeConfigSuite` for checking Spark core and SQL parameters. Author: Maxim Gekk <[email protected]> Closes #21730 from MaxGekk/is-modifiable.
1 parent e008ad1 commit 3ab48f9

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

python/pyspark/sql/conf.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ def _checkType(self, obj, identifier):
6363
raise TypeError("expected %s '%s' to be a string (was '%s')" %
6464
(identifier, obj, type(obj).__name__))
6565

66+
@ignore_unicode_prefix
67+
@since(2.4)
68+
def isModifiable(self, key):
69+
"""Indicates whether the configuration property with the given key
70+
is modifiable in the current session.
71+
"""
72+
return self._jconf.isModifiable(key)
73+
6674

6775
def _test():
6876
import os

sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,4 +1907,8 @@ class SQLConf extends Serializable with Logging {
19071907
}
19081908
cloned
19091909
}
1910+
1911+
def isModifiable(key: String): Boolean = {
1912+
sqlConfEntries.containsKey(key) && !staticConfKeys.contains(key)
1913+
}
19101914
}

sql/core/src/main/scala/org/apache/spark/sql/RuntimeConfig.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,17 @@ class RuntimeConfig private[sql](sqlConf: SQLConf = new SQLConf) {
132132
sqlConf.unsetConf(key)
133133
}
134134

135+
/**
136+
* Indicates whether the configuration property with the given key
137+
* is modifiable in the current session.
138+
*
139+
* @return `true` if the configuration property is modifiable. For static SQL, Spark Core,
140+
* invalid (not existing) and other non-modifiable configuration properties,
141+
* the returned value is `false`.
142+
* @since 2.4.0
143+
*/
144+
def isModifiable(key: String): Boolean = sqlConf.isModifiable(key)
145+
135146
/**
136147
* Returns whether a particular key is set.
137148
*/

sql/core/src/test/scala/org/apache/spark/sql/RuntimeConfigSuite.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,18 @@ class RuntimeConfigSuite extends SparkFunSuite {
5454
conf.get("k1")
5555
}
5656
}
57+
58+
test("SPARK-24761: is a config parameter modifiable") {
59+
val conf = newConf()
60+
61+
// SQL configs
62+
assert(!conf.isModifiable("spark.sql.sources.schemaStringLengthThreshold"))
63+
assert(conf.isModifiable("spark.sql.streaming.checkpointLocation"))
64+
// Core configs
65+
assert(!conf.isModifiable("spark.task.cpus"))
66+
assert(!conf.isModifiable("spark.executor.cores"))
67+
// Invalid config parameters
68+
assert(!conf.isModifiable(""))
69+
assert(!conf.isModifiable("invalid config parameter"))
70+
}
5771
}

0 commit comments

Comments
 (0)