You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by zhzhan <gi...@git.apache.org> on 2014/10/28 00:30:40 UTC

[GitHub] spark pull request: [SPARK-4103][SQL] Clean up SessionState in Hiv...

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

    https://github.com/apache/spark/pull/2967#discussion_r19445035
  
    --- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveContext.scala ---
    @@ -230,13 +230,21 @@ class HiveContext(sc: SparkContext) extends SQLContext(sc) {
        * in the HiveConf.
        */
       @transient lazy val hiveconf = new HiveConf(classOf[SessionState])
    -  @transient protected[hive] lazy val sessionState = {
    -    val ss = new SessionState(hiveconf)
    -    setConf(hiveconf.getAllProperties)  // Have SQLConf pick up the initial set of HiveConf.
    -    SessionState.start(ss)
    -    ss.err = new PrintStream(outputBuffer, true, "UTF-8")
    -    ss.out = new PrintStream(outputBuffer, true, "UTF-8")
     
    +  /**
    +   * If the thread local sessionstate is not set, start a new SessionState
    +   * SessionState.start will put ss to thread local
    +   * @return
    +   */
    +  def getSessionState() = {
    +    var ss = SessionState.get
    +    if (ss == null) {
    +      ss = new SessionState(hiveconf)
    +      setConf(hiveconf.getAllProperties) // Have SQLConf pick up the initial set of HiveConf.
    +      SessionState.start(ss)
    +      ss.err = new PrintStream(outputBuffer, true, "UTF-8")
    +      ss.out = new PrintStream(outputBuffer, true, "UTF-8")
    +    }
    --- End diff --
    
    If we use lazy eval, we have to relies on SessionState.start(sessionState) to initialize it. It may be invoked multiple times in various locations. Here we relies on checking ThreadLocal variable and initialize it at the first call to avoid this.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org