Skip to content

Commit f7534b3

Browse files
cloud-fangatorsmile
authored andcommitted
[SPARK-22487][SQL][FOLLOWUP] still keep spark.sql.hive.version
## What changes were proposed in this pull request? a followup of #19712 , adds back the `spark.sql.hive.version`, so that if users try to read this config, they can still get a default value instead of null. ## How was this patch tested? N/A Author: Wenchen Fan <[email protected]> Closes #19719 from cloud-fan/minor.
1 parent 176ae4d commit f7534b3

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ private[hive] object SparkSQLEnv extends Logging {
5555
metadataHive.setOut(new PrintStream(System.out, true, "UTF-8"))
5656
metadataHive.setInfo(new PrintStream(System.err, true, "UTF-8"))
5757
metadataHive.setError(new PrintStream(System.err, true, "UTF-8"))
58+
sparkSession.conf.set(HiveUtils.FAKE_HIVE_VERSION.key, HiveUtils.builtinHiveVersion)
5859
}
5960
}
6061

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ private[hive] class SparkSQLSessionManager(hiveServer: HiveServer2, sqlContext:
7777
} else {
7878
sqlContext.newSession()
7979
}
80+
ctx.setConf(HiveUtils.FAKE_HIVE_VERSION.key, HiveUtils.builtinHiveVersion)
8081
if (sessionConf != null && sessionConf.containsKey("use:database")) {
8182
ctx.sql(s"use ${sessionConf.get("use:database")}")
8283
}

sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/HiveThriftServer2Suites.scala

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ class HiveThriftBinaryServerSuite extends HiveThriftJdbcTest {
155155

156156
test("Checks Hive version") {
157157
withJdbcStatement() { statement =>
158-
val resultSet = statement.executeQuery("SET spark.sql.hive.metastore.version")
158+
val resultSet = statement.executeQuery("SET spark.sql.hive.version")
159159
resultSet.next()
160-
assert(resultSet.getString(1) === "spark.sql.hive.metastore.version")
160+
assert(resultSet.getString(1) === "spark.sql.hive.version")
161161
assert(resultSet.getString(2) === HiveUtils.builtinHiveVersion)
162162
}
163163
}
@@ -521,7 +521,20 @@ class HiveThriftBinaryServerSuite extends HiveThriftJdbcTest {
521521
conf += resultSet.getString(1) -> resultSet.getString(2)
522522
}
523523

524-
assert(conf.get("spark.sql.hive.metastore.version") === Some("1.2.1"))
524+
assert(conf.get("spark.sql.hive.version") === Some("1.2.1"))
525+
}
526+
}
527+
528+
test("Checks Hive version via SET") {
529+
withJdbcStatement() { statement =>
530+
val resultSet = statement.executeQuery("SET")
531+
532+
val conf = mutable.Map.empty[String, String]
533+
while (resultSet.next()) {
534+
conf += resultSet.getString(1) -> resultSet.getString(2)
535+
}
536+
537+
assert(conf.get("spark.sql.hive.version") === Some("1.2.1"))
525538
}
526539
}
527540

@@ -708,9 +721,9 @@ class HiveThriftHttpServerSuite extends HiveThriftJdbcTest {
708721

709722
test("Checks Hive version") {
710723
withJdbcStatement() { statement =>
711-
val resultSet = statement.executeQuery("SET spark.sql.hive.metastore.version")
724+
val resultSet = statement.executeQuery("SET spark.sql.hive.version")
712725
resultSet.next()
713-
assert(resultSet.getString(1) === "spark.sql.hive.metastore.version")
726+
assert(resultSet.getString(1) === "spark.sql.hive.version")
714727
assert(resultSet.getString(2) === HiveUtils.builtinHiveVersion)
715728
}
716729
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ private[spark] object HiveUtils extends Logging {
6666
.stringConf
6767
.createWithDefault(builtinHiveVersion)
6868

69+
// A fake config which is only here for backward compatibility reasons. This config has no effect
70+
// to Spark, just for reporting the builtin Hive version of Spark to existing applications that
71+
// already rely on this config.
72+
val FAKE_HIVE_VERSION = buildConf("spark.sql.hive.version")
73+
.doc(s"deprecated, please use ${HIVE_METASTORE_VERSION.key} to get the Hive version in Spark.")
74+
.stringConf
75+
.createWithDefault(builtinHiveVersion)
76+
6977
val HIVE_METASTORE_JARS = buildConf("spark.sql.hive.metastore.jars")
7078
.doc(s"""
7179
| Location of the jars that should be used to instantiate the HiveMetastoreClient.

0 commit comments

Comments
 (0)