Skip to content

Commit 50762fa

Browse files
AngersZhuuuusandeep-katta
authored andcommitted
spark-28954 Use SessionResourceLoader to cover HIVEAUXJARS conf jars
1 parent 9800736 commit 50762fa

File tree

3 files changed

+10
-31
lines changed

3 files changed

+10
-31
lines changed

sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLCLIDriver.scala

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,7 @@ private[hive] object SparkSQLCLIDriver extends Logging {
138138
// Clean up after we exit
139139
ShutdownHookManager.addShutdownHook { () => SparkSQLEnv.stop() }
140140

141-
val remoteMode = isRemoteMode(sessionState)
142-
// "-h" option has been passed, so connect to Hive thrift server.
143-
if (!remoteMode) {
144-
// Hadoop-20 and above - we need to augment classpath using hiveconf
145-
// components.
146-
// See also: code in ExecDriver.java
147-
var loader = conf.getClassLoader
148-
val auxJars = HiveConf.getVar(conf, HiveConf.ConfVars.HIVEAUXJARS)
149-
if (StringUtils.isNotBlank(auxJars)) {
150-
loader = ThriftserverShimUtils.addToClassPath(loader, StringUtils.split(auxJars, ","))
151-
}
152-
conf.setClassLoader(loader)
153-
Thread.currentThread().setContextClassLoader(loader)
154-
} else {
141+
if (isRemoteMode(sessionState)) {
155142
// Hive 1.2 + not supported in CLI
156143
throw new RuntimeException("Remote operations not supported")
157144
}
@@ -169,6 +156,15 @@ private[hive] object SparkSQLCLIDriver extends Logging {
169156
val cli = new SparkSQLCLIDriver
170157
cli.setHiveVariables(oproc.getHiveVariables)
171158

159+
// In SparkSQL CLI, we may want to use jars augmented by hiveconf
160+
// hive.aux.jars.path, here we add jars augmented by hiveconf to
161+
// Spark's SessionResourceLoader to obtain these jars.
162+
val auxJars = HiveConf.getVar(conf, HiveConf.ConfVars.HIVEAUXJARS)
163+
if (StringUtils.isNotBlank(auxJars)) {
164+
val resourceLoader = SparkSQLEnv.sqlContext.sessionState.resourceLoader
165+
StringUtils.split(auxJars, ",").foreach(resourceLoader.addJar(_))
166+
}
167+
172168
// TODO work around for set the log output to console, because the HiveContext
173169
// will set the output into an invalid buffer.
174170
sessionState.in = System.in

sql/hive-thriftserver/v1.2.1/src/main/scala/org/apache/spark/sql/hive/thriftserver/ThriftserverShimUtils.scala

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.apache.spark.sql.hive.thriftserver
1919

2020
import org.apache.commons.logging.LogFactory
21-
import org.apache.hadoop.hive.ql.exec.Utilities
2221
import org.apache.hadoop.hive.ql.session.SessionState
2322
import org.apache.hive.service.cli.{RowSet, RowSetFactory, TableSchema, Type}
2423
import org.apache.hive.service.cli.thrift.TProtocolVersion._
@@ -51,12 +50,6 @@ private[thriftserver] object ThriftserverShimUtils {
5150

5251
private[thriftserver] def toJavaSQLType(s: String): Int = Type.getType(s).toJavaSQLType
5352

54-
private[thriftserver] def addToClassPath(
55-
loader: ClassLoader,
56-
auxJars: Array[String]): ClassLoader = {
57-
Utilities.addToClassPath(loader, auxJars)
58-
}
59-
6053
private[thriftserver] val testedProtocolVersions = Seq(
6154
HIVE_CLI_SERVICE_PROTOCOL_V1,
6255
HIVE_CLI_SERVICE_PROTOCOL_V2,

sql/hive-thriftserver/v2.3.5/src/main/scala/org/apache/spark/sql/hive/thriftserver/ThriftserverShimUtils.scala

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ package org.apache.spark.sql.hive.thriftserver
1919

2020
import java.security.AccessController
2121

22-
import scala.collection.JavaConverters._
23-
24-
import org.apache.hadoop.hive.ql.exec.AddToClassPathAction
2522
import org.apache.hadoop.hive.ql.session.SessionState
2623
import org.apache.hadoop.hive.serde2.thrift.Type
2724
import org.apache.hive.service.cli.{RowSet, RowSetFactory, TableSchema}
@@ -56,13 +53,6 @@ private[thriftserver] object ThriftserverShimUtils {
5653

5754
private[thriftserver] def toJavaSQLType(s: String): Int = Type.getType(s).toJavaSQLType
5855

59-
private[thriftserver] def addToClassPath(
60-
loader: ClassLoader,
61-
auxJars: Array[String]): ClassLoader = {
62-
val addAction = new AddToClassPathAction(loader, auxJars.toList.asJava)
63-
AccessController.doPrivileged(addAction)
64-
}
65-
6656
private[thriftserver] val testedProtocolVersions = Seq(
6757
HIVE_CLI_SERVICE_PROTOCOL_V1,
6858
HIVE_CLI_SERVICE_PROTOCOL_V2,

0 commit comments

Comments
 (0)