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
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ private[spark] abstract class ConfigEntry[T] (
def defaultValueString: String

protected def readString(reader: ConfigReader): Option[String] = {
val values = Seq(
prependedKey.flatMap(reader.get(_)),
alternatives.foldLeft(reader.get(key))((res, nextKey) => res.orElse(reader.get(nextKey)))
).flatten
if (values.nonEmpty) {
Some(values.mkString(prependSeparator))
} else {
None
// SPARK-48678: performance optimization: this code could be expressed more succinctly
// using flatten and mkString, but doing so adds lots of Scala collections perf. overhead.
val maybePrependedValue: Option[String] = prependedKey.flatMap(reader.get)
val maybeValue: Option[String] = alternatives
.foldLeft(reader.get(key))((res, nextKey) => res.orElse(reader.get(nextKey)))
(maybePrependedValue, maybeValue) match {
case (Some(prependedValue), Some(value)) => Some(s"$prependedValue$prependSeparator$value")
case _ => maybeValue.orElse(maybePrependedValue)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ private[spark] class ConfigReader(conf: ConfigProvider) {
def substitute(input: String): String = substitute(input, Set())

private def substitute(input: String, usedRefs: Set[String]): String = {
if (input != null) {
// SPARK-48678: performance optimization: skip the costly regex processing
// if the string cannot possibly contain a variable reference:
if (input != null && input.contains("${")) {
ConfigReader.REF_RE.replaceAllIn(input, { m =>
val prefix = m.group(1)
val name = m.group(2)
Expand Down