Skip to content

Commit bbf0ac4

Browse files
respect the --hiveconf in the SparkSQLCliDriver commandline
1 parent c409e23 commit bbf0ac4

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ private[hive] object SparkSQLCLIDriver extends Logging {
156156
// Execute -i init files (always in silent mode)
157157
cli.processInitFiles(sessionState)
158158

159+
// Respect the configurations from the command line and .hiverc for backward-compatible
160+
SparkSQLEnv.applyOverridedConf(sessionState)
161+
159162
if (sessionState.execString != null) {
160163
System.exit(cli.processLine(sessionState.execString))
161164
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package org.apache.spark.sql.hive.thriftserver
1919

2020
import java.io.PrintStream
2121

22-
import scala.collection.JavaConverters._
22+
import org.apache.hadoop.hive.ql.session.SessionState
2323

2424
import org.apache.spark.{SparkConf, SparkContext}
2525
import org.apache.spark.internal.Logging
@@ -66,6 +66,14 @@ private[hive] object SparkSQLEnv extends Logging {
6666
}
6767
}
6868

69+
def applyOverridedConf(ss: SessionState): Unit = {
70+
val it = ss.getOverriddenConfigurations.entrySet().iterator()
71+
while (it.hasNext) {
72+
val kv = it.next()
73+
SparkSQLEnv.sqlContext.setConf(kv.getKey, kv.getValue)
74+
}
75+
}
76+
6977
/** Cleans up and shuts down the Spark SQL environments. */
7078
def stop() {
7179
logDebug("Shutting down Spark SQL Environment")

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class CliSuite extends SparkFunSuite with BeforeAndAfterAll with Logging {
9191
| --hiveconf ${ConfVars.METASTORECONNECTURLKEY}=$jdbcUrl
9292
| --hiveconf ${ConfVars.METASTOREWAREHOUSE}=$warehousePath
9393
| --hiveconf ${ConfVars.SCRATCHDIR}=$scratchDirPath
94+
| --hiveconf conf1=conftest
95+
| --hiveconf conf2=1
9496
""".stripMargin.split("\\s+").toSeq ++ extraArgs
9597
}
9698

@@ -272,4 +274,13 @@ class CliSuite extends SparkFunSuite with BeforeAndAfterAll with Logging {
272274
s"LIST FILE $dataFilePath;" -> "small_kv.txt"
273275
)
274276
}
277+
278+
test("apply hiveconf from cli command") {
279+
runCliWithin(2.minute)(
280+
s"SET conf1;" -> "conftest",
281+
s"SET conf2;" -> "1",
282+
// bypassed by SparkSQLCLIDriver
283+
s"SET ${ConfVars.METASTORECONNECTURLKEY};" -> "undefined"
284+
)
285+
}
275286
}

0 commit comments

Comments
 (0)