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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to