Skip to content

Commit 4286cba

Browse files
rxingatorsmile
authored andcommitted
[SPARK-22710] ConfigBuilder.fallbackConf should trigger onCreate function
## What changes were proposed in this pull request? I was looking at the config code today and found that configs defined using ConfigBuilder.fallbackConf didn't trigger onCreate function. This patch fixes it. This doesn't require backporting since we currently have no configs that use it. ## How was this patch tested? Added a test case for all the config final creator functions in ConfigEntrySuite. Author: Reynold Xin <[email protected]> Closes #19905 from rxin/SPARK-22710.
1 parent e98f964 commit 4286cba

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

core/src/main/scala/org/apache/spark/internal/config/ConfigBuilder.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,9 @@ private[spark] case class ConfigBuilder(key: String) {
235235
}
236236

237237
def fallbackConf[T](fallback: ConfigEntry[T]): ConfigEntry[T] = {
238-
new FallbackConfigEntry(key, _alternatives, _doc, _public, fallback)
238+
val entry = new FallbackConfigEntry(key, _alternatives, _doc, _public, fallback)
239+
_onCreate.foreach(_(entry))
240+
entry
239241
}
240242

241243
def regexConf: TypedConfigBuilder[Regex] = {

core/src/test/scala/org/apache/spark/internal/config/ConfigEntrySuite.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,4 +288,24 @@ class ConfigEntrySuite extends SparkFunSuite {
288288
conf.remove(testKey("b"))
289289
assert(conf.get(iConf) === 3)
290290
}
291+
292+
test("onCreate") {
293+
var onCreateCalled = false
294+
ConfigBuilder(testKey("oc1")).onCreate(_ => onCreateCalled = true).intConf.createWithDefault(1)
295+
assert(onCreateCalled)
296+
297+
onCreateCalled = false
298+
ConfigBuilder(testKey("oc2")).onCreate(_ => onCreateCalled = true).intConf.createOptional
299+
assert(onCreateCalled)
300+
301+
onCreateCalled = false
302+
ConfigBuilder(testKey("oc3")).onCreate(_ => onCreateCalled = true).intConf
303+
.createWithDefaultString("1.0")
304+
assert(onCreateCalled)
305+
306+
val fallback = ConfigBuilder(testKey("oc4")).intConf.createWithDefault(1)
307+
onCreateCalled = false
308+
ConfigBuilder(testKey("oc5")).onCreate(_ => onCreateCalled = true).fallbackConf(fallback)
309+
assert(onCreateCalled)
310+
}
291311
}

0 commit comments

Comments
 (0)