apache/spark — pull request #2967 by zhzhan (2014-10-27 22:38:49+00:00)
Title: Spark 4103

Currently the sessionState in HiveContext is lazy evaluated, and to start the session, SessionState.start() has to be invoked to initialize it. Using ThreadLocal variable natively in hive to track the availability of SessionState and initialize it if required. It avoid multiple thread sharing the same SessionState or single thread invoke SessionState.start with the same SessionState multiple times, which seems to cause unexpected behavior, and break the contract defined in hive. Refer below comments form SessionState in hive.

/**
* set current session to existing session object if a thread is running
* multiple sessions - it must call this method with the new session object
* when switching from one session to another.
* @throws HiveException
*/
public static SessionState start(SessionState startSs) {
...
}