Skip to content

Commit a2f4add

Browse files
committed
getConf will return the default value if a config is not set
1 parent 037b1db commit a2f4add

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

sql/core/src/main/scala/org/apache/spark/sql/SQLConf.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,12 @@ private[sql] class SQLConf extends Serializable with CatalystConf {
527527

528528
/** Return the value of Spark SQL configuration property for the given key. */
529529
def getConfString(key: String): String = {
530-
Option(settings.get(key)).getOrElse(throw new NoSuchElementException(key))
530+
Option(settings.get(key)).
531+
orElse {
532+
// Try to use the default value
533+
Option(sqlConfEntries.get(key)).map(_.defaultValueString)
534+
}.
535+
getOrElse(throw new NoSuchElementException(key))
531536
}
532537

533538
/**

sql/core/src/main/scala/org/apache/spark/sql/execution/commands.scala

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.apache.spark.sql.execution
1919

20+
import java.util.NoSuchElementException
21+
2022
import org.apache.spark.Logging
2123
import org.apache.spark.annotation.DeveloperApi
2224
import org.apache.spark.rdd.RDD
@@ -94,8 +96,9 @@ case class SetCommand(
9496
s"Property ${SQLConf.Deprecated.MAPRED_REDUCE_TASKS} is deprecated, " +
9597
s"automatically converted to ${SQLConf.SHUFFLE_PARTITIONS.key} instead.")
9698
if (value.toInt < 1) {
97-
val msg = s"Setting negative ${SQLConf.Deprecated.MAPRED_REDUCE_TASKS} for automatically " +
98-
"determining the number of reducers is not supported."
99+
val msg =
100+
s"Setting negative ${SQLConf.Deprecated.MAPRED_REDUCE_TASKS} for automatically " +
101+
"determining the number of reducers is not supported."
99102
throw new IllegalArgumentException(msg)
100103
} else {
101104
sqlContext.setConf(SQLConf.SHUFFLE_PARTITIONS.key, value)
@@ -147,7 +150,13 @@ case class SetCommand(
147150
// Queries a single property.
148151
case Some((key, None)) =>
149152
val runFunc = (sqlContext: SQLContext) => {
150-
Seq(Row(key, sqlContext.getConf(key, "<undefined>")))
153+
val value =
154+
try {
155+
sqlContext.getConf(key)
156+
} catch {
157+
case _: NoSuchElementException => "<undefined>"
158+
}
159+
Seq(Row(key, value))
151160
}
152161
(keyValueOutput, runFunc)
153162
}

0 commit comments

Comments
 (0)