Github user andrewor14 commented on a diff in the pull request: https://github.com/apache/spark/pull/2379#discussion_r18001754 --- Diff: core/src/main/scala/org/apache/spark/util/Utils.scala --- @@ -1357,6 +1357,58 @@ private[spark] object Utils extends Logging { } } + /** + * Load the default spark properties from the file + * Use common defaults file, if not specified by user. + */ + 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 */ + def getDefaultConfigFile(): String = { --- End diff -- We should call this `getDefaultPropertiesFile` to be consistent
--- 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