Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions python/pyspark/sql/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ def _checkType(self, obj, identifier):
raise TypeError("expected %s '%s' to be a string (was '%s')" %
(identifier, obj, type(obj).__name__))

@ignore_unicode_prefix
@since(2.4)
def isModifiable(self, key):
"""Indicates whether the configuration property with the given key
is modifiable in the current session.
"""
return self._jconf.isModifiable(key)


def _test():
import os
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1892,4 +1892,8 @@ class SQLConf extends Serializable with Logging {
}
cloned
}

def isModifiable(key: String): Boolean = {
sqlConfEntries.containsKey(key) && !staticConfKeys.contains(key)
}
}
11 changes: 11 additions & 0 deletions sql/core/src/main/scala/org/apache/spark/sql/RuntimeConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@ class RuntimeConfig private[sql](sqlConf: SQLConf = new SQLConf) {
sqlConf.unsetConf(key)
}

/**
* Indicates whether the configuration property with the given key
* is modifiable in the current session.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: If a key is not a valid conf, this function will still return false. Should we specify this in the comments?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added @return tag with this info.

*
* @return `true` if the configuration property is modifiable. For static SQL, Spark Core,
* invalid (not existing) and other non-modifiable configuration properties,
* the returned value is `false`.
* @since 2.4.0
*/
def isModifiable(key: String): Boolean = sqlConf.isModifiable(key)

/**
* Returns whether a particular key is set.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,18 @@ class RuntimeConfigSuite extends SparkFunSuite {
conf.get("k1")
}
}

test("SPARK-24761: is a config parameter modifiable") {
val conf = newConf()

// SQL configs
assert(!conf.isModifiable("spark.sql.sources.schemaStringLengthThreshold"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add a case for nonexistent sql conf key?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a couple tests

assert(conf.isModifiable("spark.sql.streaming.checkpointLocation"))
// Core configs
assert(!conf.isModifiable("spark.task.cpus"))
assert(!conf.isModifiable("spark.executor.cores"))
// Invalid config parameters
assert(!conf.isModifiable(""))
assert(!conf.isModifiable("invalid config parameter"))
}
}