yaooqinn commented on a change in pull request #27969: 
[SPARK-31170][SQL][test-hive1.2] Spark SQL Cli should respect hive-site.xml and 
spark.sql.warehouse.dir
URL: https://github.com/apache/spark/pull/27969#discussion_r397849414
 
 

 ##########
 File path: 
sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLCLIDriver.scala
 ##########
 @@ -85,43 +86,52 @@ private[hive] object SparkSQLCLIDriver extends Logging {
       System.exit(1)
     }
 
-    val sparkConf = new SparkConf(loadDefaults = true)
-    val hadoopConf = SparkHadoopUtil.get.newConfiguration(sparkConf)
-    val extraConfigs = HiveUtils.formatTimeVarsForHiveClient(hadoopConf)
-
-    val cliConf = HiveClientImpl.newHiveConf(sparkConf, hadoopConf, 
extraConfigs)
+    val dummyHiveConf = new HiveConf(classOf[SessionState])
+    // a dummy CliSessionState to parse hive command line options and other 
hive parameters,
+    // e.g. database.
+    val dummySessionState = new CliSessionState(dummyHiveConf)
 
-    val sessionState = new CliSessionState(cliConf)
-
-    sessionState.in = System.in
+    dummySessionState.in = System.in
     try {
-      sessionState.out = new PrintStream(System.out, true, UTF_8.name())
-      sessionState.info = new PrintStream(System.err, true, UTF_8.name())
-      sessionState.err = new PrintStream(System.err, true, UTF_8.name())
+      dummySessionState.out = new PrintStream(System.out, true, UTF_8.name())
+      dummySessionState.info = new PrintStream(System.err, true, UTF_8.name())
+      dummySessionState.err = new PrintStream(System.err, true, UTF_8.name())
     } catch {
-      case e: UnsupportedEncodingException => System.exit(3)
+      case _: UnsupportedEncodingException => System.exit(3)
     }
-
-    if (!oproc.process_stage2(sessionState)) {
+    if (!oproc.process_stage2(dummySessionState)) {
       System.exit(2)
     }
 
-    // Set all properties specified via command line.
+    // If the same property is configured by spark.hadoop.xxx, we will 
override it and
+    // obey settings from command-line properties
+    val cmdProperties = dummySessionState.cmdProperties.entrySet().asScala.map 
{ e =>
+      (e.getKey.toString, e.getValue.toString)
+    }.toMap.filterKeys { key =>
+      // We do not propagate metastore options to the execution copy of hive.
+      key != "javax.jdo.option.ConnectionURL"
+    }
+
+    // For hadoop and hive settings, the priority order is:
+    // --hiveconf xxx(cmdProperties) > spark.hive.xxx > spark.hadoop.xxx > xxx 
from hive-site.xml
+    sys.props ++= cmdProperties.map {case (k, v) => SPARK_HADOOP_PROP_PREFIX + 
k -> v}
 
 Review comment:
   It will be load by sparkConf then take affect

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to