Github user andrewor14 commented on a diff in the pull request:

    https://github.com/apache/spark/pull/2379#discussion_r17614596
  
    --- Diff: core/src/main/scala/org/apache/spark/util/Utils.scala ---
    @@ -1352,6 +1352,33 @@ private[spark] object Utils extends Logging {
         }
       }
     
    +  /** Load properties present in the given file. */
    +  def getPropertiesFromFile(filename: String): Seq[(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().toSeq.map(k => (k, 
properties(k).trim))
    +    } catch {
    +      case e: IOException =>
    +        val message = s"Failed when loading Spark properties"
    +        throw new SparkException(message, e)
    +    } finally {
    +      inReader.close()
    +    }
    +  }
    +
    +  private[spark] def getDefaultConfigFile: String = {
    +    val s = File.separator
    +    Seq(
    +      sys.env.get("SPARK_CONF_DIR").map(t => new 
File(s"$t${s}spark-defaults.conf")),
    +      sys.env.get("SPARK_HOME").map(t => new 
File(s"${t}${s}conf${s}spark-defaults.conf"))).
    +      
filter(_.isDefined).map(_.get).find(_.exists).map(_.getAbsolutePath).orNull
    +  }
    --- End diff --
    
    This looks kinda funky. How about the following:
    ```
    sys.env.get("SPARK_CONF_DIR").map(...)
      .orElse(sys.env.get("SPARK_HOME").map(...))
      .map(_.getAbsolutePath)
      .orNull
    ```


---
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

Reply via email to