Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-47341][SQL] Fix inaccurate documentation of RuntimeConfig#get
### What changes were proposed in this pull request? The existing documentation of `RuntimeConfig.get()` is misleading: * `get(key: String)` method will not throw any exception if the key is not set as long as the config entry has a default value, instead, it will just return the `defaultValue` of the `ConfigEntry`. An `NoSuchElementException` will only be thrown if there is no default value for the config entry. * `get(key: String, default: String)` method will ignore the `defaultValue` of its `ConfigEntry`, and return the given param `default` if unset. * `getOption(key: String)` method will return the `defaultValue` of its `ConfigEntry` if the config is not set, instead of `None`. An example to demonstrate the behaviour: <img width="501" alt="image" src="https://github.com/user-attachments/assets/18650646-1920-4967-b2eb-fa4f21f2ca6c"> The first line makes sure the config is not set. ``` scala> spark.conf.unset("spark.sql.session.timeZone") ``` The following code returns `Etc/UTC`, which doesn't throw any exception. ``` scala> spark.conf.get("spark.sql.session.timeZone") res1: String = "Etc/UTC" ``` The following code returns `Some("Etc/UTC")`, instead of `None`. ``` scala> spark.conf.getOption("spark.sql.session.timeZone") res2: Option[String] = Some(value = "Etc/UTC") ``` The following code returns `Europe/Berlin`, ignoring the default value. However, the documentation only says it returns the value, without mentioning ignoring the default value of the entry when the config is not explicitly set. ``` scala> spark.conf.get("spark.sql.session.timeZone", "Europe/Berlin") res3: String = "Europe/Berlin" ``` In this PR, the documentation is fixed and a new test case is added. ### Why are the changes needed? The incorrect documentation is likely to mislead users to weird behaviours if they rely on the documentation. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? New test case in `RuntimeConfigSuite`. ### Was this patch authored or co-authored using generative AI tooling? No. Closes apache#48264 from xi-db/SPARK-49798-fix-runtimeconfig-doc. Lead-authored-by: Xi Lyu <[email protected]> Co-authored-by: Xi Lyu <[email protected]> Signed-off-by: Max Gekk <[email protected]>
- Loading branch information