Skip to content

Commit cfe472a

Browse files
JoshRosenrxin
authored andcommitted
[SPARK-14786] Remove hive-cli dependency from hive subproject
The `hive` subproject currently depends on `hive-cli` in order to perform a check to see whether a `SessionState` is an instance of `org.apache.hadoop.hive.cli.CliSessionState` (see #9589). The introduction of this `hive-cli` dependency has caused problems for users whose Hive metastore JAR classpaths don't include the `hive-cli` classes (such as in #11495). This patch removes this dependency on `hive-cli` and replaces the `isInstanceOf` check by reflection. I added a Maven Enforcer rule to ban `hive-cli` from the `hive` subproject in order to make sure that this dependency is not accidentally reintroduced. /cc rxin yhuai adrian-wang preecet Author: Josh Rosen <joshrosen@databricks.com> Closes #12551 from JoshRosen/remove-hive-cli-dep-from-hive-subproject.
1 parent 8045814 commit cfe472a

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

sql/hive/pom.xml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@
7373
<version>${protobuf.version}</version>
7474
</dependency>
7575
-->
76-
<dependency>
77-
<groupId>${hive.group}</groupId>
78-
<artifactId>hive-cli</artifactId>
79-
</dependency>
8076
<!--
8177
<dependency>
8278
<groupId>${hive.group}</groupId>
@@ -225,6 +221,27 @@
225221
<argLine>-da -Xmx3g -XX:MaxPermSize=${MaxPermGen} -XX:ReservedCodeCacheSize=512m</argLine>
226222
</configuration>
227223
</plugin>
224+
<plugin>
225+
<groupId>org.apache.maven.plugins</groupId>
226+
<artifactId>maven-enforcer-plugin</artifactId>
227+
<executions>
228+
<execution>
229+
<id>enforce-versions</id>
230+
<goals>
231+
<goal>enforce</goal>
232+
</goals>
233+
<configuration>
234+
<rules>
235+
<bannedDependencies>
236+
<excludes combine.children="append">
237+
<exclude>*:hive-cli</exclude>
238+
</excludes>
239+
</bannedDependencies>
240+
</rules>
241+
</configuration>
242+
</execution>
243+
</executions>
244+
</plugin>
228245
</plugins>
229246
</build>
230247
</project>

sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import scala.language.reflectiveCalls
2424

2525
import org.apache.hadoop.conf.Configuration
2626
import org.apache.hadoop.fs.Path
27-
import org.apache.hadoop.hive.cli.CliSessionState
2827
import org.apache.hadoop.hive.conf.HiveConf
2928
import org.apache.hadoop.hive.metastore.{PartitionDropOptions, TableType => HiveTableType}
3029
import org.apache.hadoop.hive.metastore.api.{Database => HiveDatabase, FieldSchema, Function => HiveFunction, FunctionType, PrincipalType, ResourceType, ResourceUri}
@@ -110,10 +109,20 @@ private[hive] class HiveClientImpl(
110109
}
111110
}
112111

112+
def isCliSessionState(state: SessionState): Boolean = {
113+
var temp: Class[_] = if (state != null) state.getClass else null
114+
var found = false
115+
while (temp != null && !found) {
116+
found = temp.getName == "org.apache.hadoop.hive.cli.CliSessionState"
117+
temp = temp.getSuperclass
118+
}
119+
found
120+
}
121+
113122
val ret = try {
114123
// originState will be created if not exists, will never be null
115124
val originalState = SessionState.get()
116-
if (originalState.isInstanceOf[CliSessionState]) {
125+
if (isCliSessionState(originalState)) {
117126
// In `SparkSQLCLIDriver`, we have already started a `CliSessionState`,
118127
// which contains information like configurations from command line. Later
119128
// we call `SparkSQLEnv.init()` there, which would run into this part again.

sql/hive/src/main/scala/org/apache/spark/sql/hive/client/IsolatedClientLoader.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private[hive] object IsolatedClientLoader extends Logging {
103103
hadoopVersion: String,
104104
ivyPath: Option[String]): Seq[URL] = {
105105
val hiveArtifacts = version.extraDeps ++
106-
Seq("hive-metastore", "hive-exec", "hive-common", "hive-serde", "hive-cli")
106+
Seq("hive-metastore", "hive-exec", "hive-common", "hive-serde")
107107
.map(a => s"org.apache.hive:$a:${version.fullVersion}") ++
108108
Seq("com.google.guava:guava:14.0.1",
109109
s"org.apache.hadoop:hadoop-client:$hadoopVersion")

0 commit comments

Comments
 (0)