Description
SparkSession.active is a thread local variable that points to the current thread's spark session. It is important to note that the SQLConf.get method depends on SparkSession.active. In the current implementation it is possible that SparkSession.active points to a different session which causes various problems. Most of these problems arise because part of the query processing is done using the configurations of a different session. For example, when creating a data frame using a new session, i.e., session.sql("..."), part of the data frame is constructed using the currently active spark session, which can be a different session from the one used later for processing the query.
This PR scopes SparkSession.active to prevent the above-mentioned problems. A new method, withActive is introduced on SparkSession that restores the previous spark session after the block of code is executed.
Attachments
Issue Links
- is duplicated by
-
SPARK-30223 queries in thrift server may read wrong SQL configs
- Resolved
- is related to
-
SPARK-32126 Scope Session.active in IncrementalExecution
- Resolved
- relates to
-
SPARK-38328 SQLConf.get flaky causes NON-default spark session settings being lost
- Open
- links to