Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-6675][SQL]Hive setConf issue #5457

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions sql/core/src/main/scala/org/apache/spark/sql/SQLConf.scala
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,15 @@ private[sql] class SQLConf extends Serializable {
/** ********************** SQLConf functionality methods ************ */

/** Set Spark SQL configuration properties. */
def setConf(props: Properties): Unit = settings.synchronized {
props.foreach { case (k, v) => settings.put(k, v) }
def setConf(props: Properties, overwrite: Boolean = true): Unit = settings.synchronized {
if (overwrite) {
props.foreach { case (k, v) => settings.put(k, v) }
} else {
props
.filter(p => !settings.containsKey(p._1))
.foreach { case (k, v) => settings.put(k, v) }
}

}

/** Set the given Spark SQL configuration property. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class SQLContext(@transient val sparkContext: SparkContext)
*
* @group config
*/
def setConf(props: Properties): Unit = conf.setConf(props)
def setConf(props: Properties, overwrite: Boolean = true): Unit = conf.setConf(props, overwrite)

/**
* Set the given Spark SQL configuration property.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class HiveContext(sc: SparkContext) extends SQLContext(sc) {
}

protected[hive] lazy val hiveconf: HiveConf = {
setConf(sessionState.getConf.getAllProperties)
setConf(sessionState.getConf.getAllProperties, false)
sessionState.getConf
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.spark.sql.hive

import org.apache.spark.sql.hive.test.TestHive
import org.scalatest.FunSuite

class HiveContextInitSuite extends FunSuite {
test("SPARK-6675 Hive setConf") {
val hc = new HiveContext(TestHive.sparkContext)
hc.setConf("hive.metastore.warehouse.dir", "/home/spark/hive/warehouse_test")
hc.setConf("spark.sql.shuffle.partitions", "10")
assert(hc.getAllConfs.get("hive.metastore.warehouse.dir")
.toList.contains("/home/spark/hive/warehouse_test"))
assert(hc.getAllConfs.get("spark.sql.shuffle.partitions").toList.contains("10"))
}
}