Skip to content

Commit

Permalink
Remove singleton SQLConf and move back settings to the trait.
Browse files Browse the repository at this point in the history
  • Loading branch information
concretevitamin committed Jul 29, 2014
1 parent 2d99eb5 commit 573e644
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions sql/core/src/main/scala/org/apache/spark/sql/SQLConf.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ import java.util.Properties

import scala.collection.JavaConverters._

private object SQLConf {
@transient protected[spark] val confSettings = java.util.Collections.synchronizedMap(
new java.util.HashMap[String, String]())
}

/**
* A trait that enables the setting and getting of mutable config parameters/hints. The central
* location for storing them is uniquely located in the same-name private companion object.
Expand All @@ -40,8 +35,8 @@ private object SQLConf {
trait SQLConf {
import SQLConf._

import org.apache.spark.sql.SQLConf._
@transient protected[spark] val settings = confSettings
@transient protected[spark] val settings = java.util.Collections.synchronizedMap(
new java.util.HashMap[String, String]())

/** ************************ Spark SQL Params/Hints ******************* */
// TODO: refactor so that these hints accessors don't pollute the name space of SQLContext?
Expand Down Expand Up @@ -70,39 +65,39 @@ trait SQLConf {
/** ********************** SQLConf functionality methods ************ */

def set(props: Properties): Unit = {
confSettings.synchronized {
props.asScala.foreach { case (k, v) => confSettings.put(k, v) }
settings.synchronized {
props.asScala.foreach { case (k, v) => settings.put(k, v) }
}
}

def set(key: String, value: String): Unit = {
require(key != null, "key cannot be null")
require(value != null, s"value cannot be null for key: $key")
confSettings.put(key, value)
settings.put(key, value)
}

def get(key: String): String = {
Option(confSettings.get(key)).getOrElse(throw new NoSuchElementException(key))
Option(settings.get(key)).getOrElse(throw new NoSuchElementException(key))
}

def get(key: String, defaultValue: String): String = {
Option(confSettings.get(key)).getOrElse(defaultValue)
Option(settings.get(key)).getOrElse(defaultValue)
}

def getAll: Array[(String, String)] = confSettings.synchronized { confSettings.asScala.toArray }
def getAll: Array[(String, String)] = settings.synchronized { settings.asScala.toArray }

def getOption(key: String): Option[String] = Option(confSettings.get(key))
def getOption(key: String): Option[String] = Option(settings.get(key))

def contains(key: String): Boolean = confSettings.containsKey(key)
def contains(key: String): Boolean = settings.containsKey(key)

def toDebugString: String = {
confSettings.synchronized {
confSettings.asScala.toArray.sorted.map{ case (k, v) => s"$k=$v" }.mkString("\n")
settings.synchronized {
settings.asScala.toArray.sorted.map{ case (k, v) => s"$k=$v" }.mkString("\n")
}
}

private[spark] def clear() {
confSettings.clear()
settings.clear()
}

}
Expand Down

0 comments on commit 573e644

Please sign in to comment.