diff --git a/sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLSessionManager.scala b/sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLSessionManager.scala index ef9187df4f4a9..f4d0e89125cd9 100644 --- a/sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLSessionManager.scala +++ b/sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLSessionManager.scala @@ -118,18 +118,22 @@ private[hive] class SparkSQLSessionManager(hiveServer: HiveServer2, sqlContext: } handleToSession.put(session.getSessionHandle, session) - val sparkSession = sparkSessionManager.getOrCreteSparkSession( - session, - sessionUGI, - withImpersonation) + val sqlContext = if(withImpersonation) { + sparkSessionManager.getOrCreteSparkSession( + session, + sessionUGI, + withImpersonation).sqlContext + } else { + SparkSQLEnv.sqlContext.newSession() + } val sessionHandle = session.getSessionHandle HiveThriftServer2.listener.onSessionCreated( session.getIpAddress, sessionHandle.getSessionId.toString, session.getUsername) - sparkSession.sqlContext.setConf(HiveUtils.FAKE_HIVE_VERSION.key, HiveUtils.builtinHiveVersion) + sqlContext.setConf(HiveUtils.FAKE_HIVE_VERSION.key, HiveUtils.builtinHiveVersion) if (sessionConf != null && sessionConf.containsKey("use:database")) { - sparkSession.sql(s"use ${sessionConf.get("use:database")}") + sqlContext.sql(s"use ${sessionConf.get("use:database")}") } - sparkSqlOperationManager.sessionToContexts.put(sessionHandle, sparkSession.sqlContext) + sparkSqlOperationManager.sessionToContexts.put(sessionHandle, sqlContext) sessionHandle } diff --git a/sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/HiveThriftServer2Suites.scala b/sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/HiveThriftServer2Suites.scala index dd18add53fde8..eed3587b76356 100644 --- a/sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/HiveThriftServer2Suites.scala +++ b/sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/HiveThriftServer2Suites.scala @@ -910,6 +910,7 @@ abstract class HiveThriftServer2Test extends SparkFunSuite with BeforeAndAfterAl s"""$startScript | --master local + | --hiveconf ${ConfVars.HIVE_SERVER2_ENABLE_DOAS}=false | --hiveconf ${ConfVars.METASTORECONNECTURLKEY}=$metastoreJdbcUri | --hiveconf ${ConfVars.METASTOREWAREHOUSE}=$warehousePath | --hiveconf ${ConfVars.HIVE_SERVER2_THRIFT_BIND_HOST}=localhost