Github user vanzin commented on a diff in the pull request: https://github.com/apache/spark/pull/2379#discussion_r17808054 --- Diff: core/src/main/scala/org/apache/spark/util/Utils.scala --- @@ -1357,6 +1357,55 @@ private[spark] object Utils extends Logging { } } + /** + * Load the default spark properties from the file + * If file is null, then use the getDefaultConfigFile method's return. + */ + private[spark] def loadDefaultSparkProperties(conf: SparkConf, + file: String = null): String = { + val path = Option(file).getOrElse(getDefaultConfigFile) + Option(path).foreach { confFile => + getPropertiesFromFile(confFile).filter { case (k, v) => + k.startsWith("spark.") + }.foreach { case (k, v) => + conf.setIfMissing(k, v) + sys.props.getOrElseUpdate(k, v) + } + } + path + } + + /** Load properties present in the given file. */ + def getPropertiesFromFile(filename: String): Map[String, String] = { + val file = new File(filename) + require(file.exists(), s"Properties file $file does not exist") + require(file.isFile(), s"Properties file $file is not a normal file") + + val inReader = new InputStreamReader(new FileInputStream(file), "UTF-8") + try { + val properties = new Properties() + properties.load(inReader) + properties.stringPropertyNames().map(k => (k, properties(k).trim)).toMap + } catch { + case e: IOException => + throw new SparkException(s"Failed when loading Spark properties from $filename", e) + } finally { + inReader.close() + } + } + + /** Return the default spark configuration file */ + private[spark] def getDefaultConfigFile(): String = { + val s = File.separator + val configFile = sys.env.get("SPARK_CONF_DIR").map(t => + new File(s"$t${s}spark-defaults.conf")).filter(_.isFile). + map(_.getAbsolutePath) + + configFile.getOrElse(sys.env.get("SPARK_HOME").map(t => --- End diff -- Same here. Putting each call on a separate line makes it much easier to read.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org