cloud-fan 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_r397847925
########## 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} + + val sparkConf = new SparkConf(loadDefaults = true) + val hadoopConf = SparkHadoopUtil.newConfiguration(sparkConf) + val extraConfigs = HiveUtils.formatTimeVarsForHiveClient(hadoopConf) + + SharedState.loadHiveConfFile(sparkConf, hadoopConf) + + val cliConf = HiveClientImpl.newHiveConf(sparkConf, hadoopConf, extraConfigs) + + val sessionState = new CliSessionState(cliConf) + val conf: HiveConf = sessionState.getConf // Hive 2.0.0 onwards HiveConf.getClassLoader returns the UDFClassLoader (created by Hive). // Because of this spark cannot find the jars as class loader got changed // Hive changed the class loader because of HIVE-11878, so it is required to use old // classLoader as sparks loaded all the jars in this classLoader conf.setClassLoader(Thread.currentThread().getContextClassLoader) - sessionState.cmdProperties.entrySet().asScala.foreach { item => - val key = item.getKey.toString - val value = item.getValue.toString - // We do not propagate metastore options to the execution copy of hive. - if (key != "javax.jdo.option.ConnectionURL") { - conf.set(key, value) - sessionState.getOverriddenConfigurations.put(key, value) Review comment: This is not called anymore in the new code. ---------------------------------------------------------------- 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