Skip to content

Commit 20f6cf7

Browse files
committed
solve compatability issue
1 parent f7912a9 commit 20f6cf7

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveContext.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ class HiveContext(sc: SparkContext) extends SQLContext(sc) {
293293

294294
proc match {
295295
case driver: Driver =>
296-
val results = new JArrayList[String]
296+
val results = HiveShim.createDriverResultsArray
297297
val response: CommandProcessorResponse = driver.run(cmd)
298298
// Throw an exception if there is an error in query processing.
299299
if (response.getResponseCode != 0) {
@@ -303,7 +303,12 @@ class HiveContext(sc: SparkContext) extends SQLContext(sc) {
303303
driver.setMaxRows(maxRows)
304304
driver.getResults(results)
305305
driver.close()
306-
results
306+
results.map { r =>
307+
r match {
308+
case s: String => s
309+
case o => o.toString
310+
}
311+
}
307312
case _ =>
308313
sessionState.out.println(tokens(0) + " " + cmd_1)
309314
Seq(proc.run(cmd_1).getResponseCode.toString)

sql/hive/v0.12.0/src/main/scala/org/apache/spark/sql/hive/Shim.scala

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

2020
import java.net.URI
21+
import java.util.{ArrayList => JArrayList}
2122
import java.util.Properties
2223
import org.apache.hadoop.conf.Configuration
2324
import org.apache.hadoop.fs.Path
@@ -49,14 +50,16 @@ private[hive] object HiveShim {
4950
new TableDesc(serdeClass, inputFormatClass, outputFormatClass, properties)
5051
}
5152

53+
def createDriverResultsArray = new JArrayList[String]
54+
5255
def getStatsSetupConstTotalSize = StatsSetupConst.TOTAL_SIZE
5356

54-
def createDefaultDBIfNeeded(context: HiveContext) ={ }
57+
def createDefaultDBIfNeeded(context: HiveContext) = { }
5558

5659
/** The string used to denote an empty comments field in the schema. */
5760
def getEmptyCommentsFieldValue = "None"
5861

59-
def getCommandProcessor(cmd: Array[String], conf: HiveConf) = {
62+
def getCommandProcessor(cmd: Array[String], conf: HiveConf) = {
6063
CommandProcessorFactory.get(cmd(0), conf)
6164
}
6265

sql/hive/v0.13.1/src/main/scala/org/apache/spark/sql/hive/Shim.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.apache.spark.sql.hive
1919

20+
import java.util.{ArrayList => JArrayList}
2021
import java.util.Properties
2122
import org.apache.hadoop.conf.Configuration
2223
import org.apache.hadoop.fs.Path
@@ -53,17 +54,19 @@ private[hive] object HiveShim {
5354
new TableDesc(inputFormatClass, outputFormatClass, properties)
5455
}
5556

57+
def createDriverResultsArray = new JArrayList[Object]
58+
5659
def getStatsSetupConstTotalSize = StatsSetupConst.TOTAL_SIZE
5760

58-
def createDefaultDBIfNeeded(context: HiveContext) ={
61+
def createDefaultDBIfNeeded(context: HiveContext) = {
5962
context.runSqlHive("CREATE DATABASE default")
6063
context.runSqlHive("USE default")
6164
}
6265

6366
/* The string used to denote an empty comments field in the schema. */
6467
def getEmptyCommentsFieldValue = ""
6568

66-
def getCommandProcessor(cmd: Array[String], conf: HiveConf) = {
69+
def getCommandProcessor(cmd: Array[String], conf: HiveConf) = {
6770
CommandProcessorFactory.get(cmd, conf)
6871
}
6972

0 commit comments

Comments
 (0)