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

    https://github.com/apache/spark/pull/2887#discussion_r19513208
  
    --- Diff: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveContext.scala ---
    @@ -223,21 +223,23 @@ class HiveContext(sc: SparkContext) extends 
SQLContext(sc) {
       }
     
       /**
    -   * SQLConf and HiveConf contracts: when the hive session is first 
initialized, params in
    -   * HiveConf will get picked up by the SQLConf.  Additionally, any 
properties set by
    -   * set() or a SET command inside sql() will be set in the SQLConf *as 
well as*
    -   * in the HiveConf.
    +   * SQLConf and HiveConf contracts:
    +   *
    +   * 1. reuse existing started SessionState if any
    +   * 2. when the Hive session is first initialized, params in HiveConf 
will get picked up by the
    +   *    SQLConf.  Additionally, any properties set by set() or a SET 
command inside sql() will be
    +   *    set in the SQLConf *as well as* in the HiveConf.
        */
    -  @transient protected[hive] 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")
    -
    -    ss
    -  }
    +  @transient protected[hive] lazy val (hiveconf, sessionState) =
    +    Option(SessionState.get())
    +      .orElse(Some(new SessionState(new HiveConf(classOf[SessionState]))))
    +      .map { state =>
    +        setConf(state.getConf.getAllProperties)
    +        if (state.out == null) state.out = new PrintStream(outputBuffer, 
true, "UTF-8")
    +        if (state.err == null) state.err = new PrintStream(outputBuffer, 
true, "UTF-8")
    +        (state.getConf, state)
    +      }
    +      .get
    --- End diff --
    
    We should consider initializing the session state in the constructor, maybe 
by forcing the realization of the lazy val.  Matei just bumped into a problem 
where running "SHOW TABLES" as the first command null pointers.  Lets make sure 
that this PR fixes those sorts of problems too.


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