Repository: spark Updated Branches: refs/heads/master e98f9647f -> 4286cba7d
[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 <r...@databricks.com> Closes #19905 from rxin/SPARK-22710. Project: http://git-wip-us.apache.org/repos/asf/spark/repo Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/4286cba7 Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/4286cba7 Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/4286cba7 Branch: refs/heads/master Commit: 4286cba7dacf4b457fff91da3743ac2518699945 Parents: e98f964 Author: Reynold Xin <r...@databricks.com> Authored: Wed Dec 6 10:11:25 2017 -0800 Committer: gatorsmile <gatorsm...@gmail.com> Committed: Wed Dec 6 10:11:25 2017 -0800 ---------------------------------------------------------------------- .../spark/internal/config/ConfigBuilder.scala | 4 +++- .../internal/config/ConfigEntrySuite.scala | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/spark/blob/4286cba7/core/src/main/scala/org/apache/spark/internal/config/ConfigBuilder.scala ---------------------------------------------------------------------- diff --git a/core/src/main/scala/org/apache/spark/internal/config/ConfigBuilder.scala b/core/src/main/scala/org/apache/spark/internal/config/ConfigBuilder.scala index 8f4c1b6..b0cd711 100644 --- a/core/src/main/scala/org/apache/spark/internal/config/ConfigBuilder.scala +++ b/core/src/main/scala/org/apache/spark/internal/config/ConfigBuilder.scala @@ -235,7 +235,9 @@ private[spark] case class ConfigBuilder(key: String) { } def fallbackConf[T](fallback: ConfigEntry[T]): ConfigEntry[T] = { - new FallbackConfigEntry(key, _alternatives, _doc, _public, fallback) + val entry = new FallbackConfigEntry(key, _alternatives, _doc, _public, fallback) + _onCreate.foreach(_(entry)) + entry } def regexConf: TypedConfigBuilder[Regex] = { http://git-wip-us.apache.org/repos/asf/spark/blob/4286cba7/core/src/test/scala/org/apache/spark/internal/config/ConfigEntrySuite.scala ---------------------------------------------------------------------- diff --git a/core/src/test/scala/org/apache/spark/internal/config/ConfigEntrySuite.scala b/core/src/test/scala/org/apache/spark/internal/config/ConfigEntrySuite.scala index bf08276..02514dc 100644 --- a/core/src/test/scala/org/apache/spark/internal/config/ConfigEntrySuite.scala +++ b/core/src/test/scala/org/apache/spark/internal/config/ConfigEntrySuite.scala @@ -288,4 +288,24 @@ class ConfigEntrySuite extends SparkFunSuite { conf.remove(testKey("b")) assert(conf.get(iConf) === 3) } + + test("onCreate") { + var onCreateCalled = false + ConfigBuilder(testKey("oc1")).onCreate(_ => onCreateCalled = true).intConf.createWithDefault(1) + assert(onCreateCalled) + + onCreateCalled = false + ConfigBuilder(testKey("oc2")).onCreate(_ => onCreateCalled = true).intConf.createOptional + assert(onCreateCalled) + + onCreateCalled = false + ConfigBuilder(testKey("oc3")).onCreate(_ => onCreateCalled = true).intConf + .createWithDefaultString("1.0") + assert(onCreateCalled) + + val fallback = ConfigBuilder(testKey("oc4")).intConf.createWithDefault(1) + onCreateCalled = false + ConfigBuilder(testKey("oc5")).onCreate(_ => onCreateCalled = true).fallbackConf(fallback) + assert(onCreateCalled) + } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org